Read Operations
Read operations in Routier provide powerful querying capabilities with a fluent, chainable API. The framework supports filtering, sorting, pagination, and aggregation operations.
Quick Navigation
Overview
Routier’s read operations feature:
- Fluent query API - Chain multiple operations together
- Type-safe queries - Full TypeScript support
- Efficient filtering - Database-level query optimization
- Flexible sorting - Multiple sort criteria support
- Built-in aggregation - Count, sum, min, max operations
- Pagination support - Skip and take operations
Comprehensive Query Documentation
For detailed information about read operations, including:
- Basic querying with
toArrayAsync(),firstAsync(),countAsync() - Filtering with
where()clauses and parameterized queries - Sorting with
orderBy()andorderByDescending() - Field selection with
map()andselect() - Pagination with
skip()andtake() - Aggregation operations like
sum(),min(),max(),distinct() - Computed properties and performance optimization
- Terminal methods and query execution
Please refer to the comprehensive Queries documentation which covers all aspects of querying in Routier with detailed examples and best practices.
Key Concepts
Query Execution
All queries must end with a terminal method to execute:
toArrayAsync()- return all resultsfirstAsync()- first item, throws if nonefirstOrUndefinedAsync()- first item or undefinedsomeAsync()- any matchcountAsync()- count of itemssumAsync(),minAsync(),maxAsync()- aggregationstoGroupAsync(selector)- group items by key
Query Chaining
Queries are lazy and chainable - nothing executes until you call a terminal method:
// This query chain doesn't execute until toArrayAsync() is called
const results = await dataStore.products
.where((p) => p.price > 100)
.sort((p) => p.name)
.skip(10)
.take(5)
.toArrayAsync();
Performance Considerations
- Apply database-backed filters first, then computed/unmapped filters
- Use appropriate terminal methods for your use case
- Consider pagination for large datasets
Next Steps
- Data Manipulation - Learn about proxy-based updates and array/object manipulation
- Queries Documentation - Comprehensive querying guide with examples
- Create Operations - Learn how to add new entities
- Update Operations - Learn how to modify existing entities
- Delete Operations - Learn how to remove entities
- Bulk Operations - Learn how to handle multiple entities efficiently