Repository Methods
Repository Methods Repositories are the main way to interact with your database tables in Enfyra. Every table you create automatically gets a repository that you can access through $ctx.$repos.tableName . Quick Reference All repository methods return data in this format: { data:
Repository Methods
Repositories are the main way to interact with your database tables in Enfyra. Every table you create automatically gets a repository that you can access through $ctx.$repos.tableName.
Quick Reference
All repository methods return data in this format:
{
data: [...], // Array of records
meta: { // Metadata (when requested)
totalCount: 100,
filterCount: 25
}
}
Available Methods:
- find() - Query records with filtering, sorting, and pagination
- create() - Create new records
- update() - Update existing records by ID
- delete() - Delete records by ID
Accessing Repositories
Repositories are available through the context object ($ctx) in hooks and handlers:
// Access a repository by table name
const productsRepo = $ctx.$repos.products;
const usersRepo = $ctx.$repos.user_definition;
// Access the main table repository (if configured in route)
const mainRepo = $ctx.$repos.main;
Important:
- Repositories are resolved from metadata by table name or alias (see RepoRegistryService). You do not configure a per-route list for basic access.
- $ctx.$repos.main is the current route’s main table (field permissions enforced).
- $ctx.$repos.secure.<name> — same enforcement for another table; $ctx.$repos.<name> — no field-permission enforcement unless you use main / secure.
- All repository methods are async and require await
Documentation
- find() Method - Complete guide to querying records
- create(), update(), delete() Methods - Create, update, and delete operations
- Common Patterns - Best practices and common patterns
Next Steps
- Learn about the Context Object ($ctx) to understand all available properties
- See Query Filtering for advanced filtering patterns
- Check API Lifecycle to understand how repositories fit into the request flow