QueryOptions interface allows you to configure how queries are processed, including field selection, filtering, joins, sorting, and pagination.
Interface Definition
Properties
Array of field names that are allowed to be selected, filtered, or sorted by the client.Only these fields can be used in query parameters like
?fields=name,email or ?filter=name||$eq||John.Array of field names that should be excluded from queries.These fields cannot be queried by clients and will not appear in responses.
Array of field names that should always be included in the response, even if not requested.These fields will always be selected regardless of the
?fields= query parameter.Server-side filter that is always applied to queries.Can be:
QueryFilter[]: Array of filter conditionsSCondition: A condition object from@nestjsx/crud-requestQueryFilterFunction: A function that returns a condition
Default sorting to apply when no sort is specified in the query.
Default number of records to return per page.Clients can override this with
?limit= query parameter, up to maxLimit.Maximum number of records that can be requested per page.If a client requests more than this, it will be capped to
maxLimit.Cache duration in milliseconds, or
false to disable caching.If Returns responses in format:
true, responses are always paginated even when no limit is specified.{ data: [...], count: 10, total: 100, page: 1, pageCount: 10 }If Requires your entity to have a
true, enables soft delete functionality.deletedAt column. Soft-deleted records are excluded from queries by default.JoinOptions
TheJoinOptions interface configures relation joins:
SQL alias for the joined relation.
Fields from the joined relation that clients can query.
If
true, this relation is always loaded without requiring ?join=relationName in the query.Fields from the joined relation that should never be exposed.
Fields from the joined relation that are always selected.
If set to The relation can still be used for filtering but won’t be included in responses.
false, prevents selecting fields from this relation.If Only returns records that have this relation.
true, uses INNER JOIN instead of LEFT JOIN.Usage Examples
Basic Query Configuration
Join Relations
Server-Side Filtering
Dynamic Filtering with Function
Soft Delete Support
Default Sorting and Caching
Notes
The
allow and exclude options work together. If both are specified, exclude takes precedence. It’s generally better to use one or the other for clarity.