What is Criteria?
Criteria is a type-safe query builder that provides a fluent API for constructing database-agnostic queries. It handles filtering, ordering, pagination, and search in a way that’s completely decoupled from your persistence layer.Why Use Criteria?
Type-Safe
Field paths, operators, and values are all validated by TypeScript at compile
time
ORM Agnostic
Works with Prisma, Drizzle, TypeORM, or any persistence layer
Serializable
Convert to/from JSON for API transport or caching
Fluent API
Chain methods naturally for readable, maintainable queries
Basic Usage
Creating a Criteria
Adding Filters
Ordering Results
Pagination
Search
Type Safety
Criteria leverages TypeScript to provide compile-time validation:Field Paths
Only valid field paths from your type are allowed:Operators Per Type
Operators are validated based on the field type:Value Types
Values are validated to match the field type:Serialization
To JSON
From Object
From Query Params
Perfect for REST APIs:Cloning
Create independent copies for variations:Checking State
Getting Components
Integration with Repository
Next Steps
Filters & Operators
Complete guide to all filter operators and their usage
Ordering & Pagination
Learn about sorting, pagination, and search
Query Params & Adapters
API integration, field adapters, and quantifiers
PaginatedResult
Working with paginated query results