SelectQueryOptions
Defined in: define/table/types/query.ts:32
Defines the options available for a SELECT query.
Example
Section titled “Example”// Find all active users, order by name, and fetch their postsconst activeUsers = await User.find({ where: surql`isActive = true`, orderBy: [{ field: 'name', order: 'ASC' }], fetch: ['posts'], limit: 50});Type Parameters
Section titled “Type Parameters”TTable
Section titled “TTable”TTable
The data shape of the table being queried.
Properties
Section titled “Properties”explain?
Section titled “explain?”
optionalexplain:boolean
Defined in: define/table/types/query.ts:62
If true, returns the query plan instead of the results.
fetch?
Section titled “fetch?”
optionalfetch:string[]
Defined in: define/table/types/query.ts:54
An array of fields to fetch (expand related records).
optionalfrom:BoundQuery<unknown[]> |Expr|Table<string> |RecordId<string>
Defined in: define/table/types/query.ts:36
The table or record ID to select from. Defaults to the model’s table. Supports Table, RecordId, BoundQuery, or raw Expr for advanced use cases.
groupBy?
Section titled “groupBy?”
optionalgroupBy: (string| keyofTTable)[]
Defined in: define/table/types/query.ts:46
An array of fields to group the results by.
limit?
Section titled “limit?”
optionallimit:number
Defined in: define/table/types/query.ts:50
The maximum number of records to return.
optionalonly:boolean
Defined in: define/table/types/query.ts:38
If true, returns only the first record from the result set.
orderBy?
Section titled “orderBy?”
optionalorderBy:OrderByClause[]
Defined in: define/table/types/query.ts:48
An array of OrderByClause objects to sort the results.
parallel?
Section titled “parallel?”
optionalparallel:boolean
Defined in: define/table/types/query.ts:58
If true, runs the query in parallel with other queries.
select?
Section titled “select?”
optionalselect: (string| keyofTTable)[]
Defined in: define/table/types/query.ts:34
An array of fields to select. If omitted, all fields (*) are selected.
split?
Section titled “split?”
optionalsplit: (string| keyofTTable)[]
Defined in: define/table/types/query.ts:44
An array of fields to split the results by.
start?
Section titled “start?”
optionalstart:number
Defined in: define/table/types/query.ts:52
The starting record number.
tempfiles?
Section titled “tempfiles?”
optionaltempfiles:boolean
Defined in: define/table/types/query.ts:60
If true, enables temporary file usage for the query.
timeout?
Section titled “timeout?”
optionaltimeout:string
Defined in: define/table/types/query.ts:56
The timeout for the query, specified in a duration string (e.g. “1m”).
where?
Section titled “where?”
optionalwhere:BoundQuery<unknown[]> |Expr
Defined in: define/table/types/query.ts:42
The WHERE clause for the query. Use surql templates or SurrealDB expressions for type-safe parameter binding.
optionalwith: {indexes:string[]; } | {noIndex:true; }
Defined in: define/table/types/query.ts:40
The WITH clause for the query, specifying index usage.