!CHAPTER Details on FoxxRepository A repository is a gateway to the database. It gets data from the database, updates it or saves new data. It uses the given model when it returns a model and expects instances of the model for methods like save. In your repository file, export the repository as *repository*. ```javascript var Foxx = require("org/arangodb/foxx"); var TodosRepository = Foxx.Repository.extend({ }); exports.repository = TodosRepository; ``` !SUBSECTION Initialize @startDocuBlock JSF_foxx_repository_initializer !SECTION Defining custom queries You can define custom query methods using Foxx.createQuery and Foxx.Repository.extend. For more details see the chapter on Foxx Queries. *Examples* ```javascript var Foxx = require("org/arangodb/foxx"); var TodosRepository = Foxx.Repository.extend({ getPendingItems: Foxx.createQuery( 'FOR todo IN my_todos FILTER todo.completed == false RETURN todo' ) }); ``` !SECTION Attributes of a Repository !SUBSECTION Collection @startDocuBlock JSF_foxx_repository_collection !SUBSECTION ModelPrototype @startDocuBlock JSF_foxx_repository_modelPrototype !SUBSECTION Prefix @startDocuBlock JSF_foxx_repository_prefix !SECTION Defining indexes Repository can take care of ensuring the existence of collection indexes for you. If you define indexes for a repository, instances of the repository will have access to additional index-specific methods like *range* or *fulltext* (see below). The syntax for defining indexes is the same used in [*collection.ensureIndex*](../IndexHandling/README.md). @EXAMPLES ```js var Foxx = require('org/arangodb/foxx'); var FulltextRepository = Foxx.Repository.extend({ indexes: [ { type: 'fulltext', fields: ['text'], minLength: 3 } ] }); ``` !SECTION Methods of a Repository !SUBSECTION Adding entries to the repository @startDocuBlock JSF_foxx_repository_save !SUBSECTION Finding entries in the repository @startDocuBlock JSF_foxx_repository_byId @startDocuBlock JSF_foxx_repository_byExample @startDocuBlock JSF_foxx_repository_firstExample @startDocuBlock JSF_foxx_repository_all !SUBSECTION Removing entries from the repository @startDocuBlock JSF_foxx_repository_remove @startDocuBlock JSF_foxx_repository_removeById @startDocuBlock JSF_foxx_repository_removeByExample !SUBSECTION Replacing entries in the repository @startDocuBlock JSF_foxx_repository_replace @startDocuBlock JSF_foxx_repository_replaceById @startDocuBlock JSF_foxx_repository_replaceByExample !SUBSECTION Updating entries in the repository @startDocuBlock JSF_foxx_repository_updateById @startDocuBlock JSF_foxx_repository_updateByExample !SUBSECTION Counting entries in the repository @startDocuBlock JSF_foxx_repository_count !SUBSECTION Index-specific repository methods @startDocuBlock JSF_foxx_repository_range @startDocuBlock JSF_foxx_repository_near @startDocuBlock JSF_foxx_repository_within @startDocuBlock JSF_foxx_repository_fulltext