QueryOptions interface allows you to configure how queries are processed, including field selection, filtering, joins, sorting, and pagination.
Interface Definition
Properties
QueryFields
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.QueryFields
Array of field names that should be excluded from queries.These fields cannot be queried by clients and will not appear in responses.
QueryFields
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.QueryFilterOption
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
JoinOptions
QuerySort[]
Default sorting to apply when no sort is specified in the query.
number
Default number of records to return per page.Clients can override this with
?limit= query parameter, up to maxLimit.number
Maximum number of records that can be requested per page.If a client requests more than this, it will be capped to
maxLimit.number | false
Cache duration in milliseconds, or
false to disable caching.boolean
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 }boolean
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:
string
SQL alias for the joined relation.
QueryFields
Fields from the joined relation that clients can query.
boolean
If
true, this relation is always loaded without requiring ?join=relationName in the query.QueryFields
Fields from the joined relation that should never be exposed.
QueryFields
Fields from the joined relation that are always selected.
false
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.boolean
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.