SelectQueryOptions
Defined in: define/table/types/query.ts:56
Defines the options available for a SELECT query.
Example
Section titled “Example”// Type-safe field selectionconst posts = await Post.select({ select: { title: true, author: { name: true, email: true }, },});// Type: { title: string; author: { name: string; email: string } }[]
// With custom computed fieldconst posts = await Post.select({ select: { title: true, commentCount: typed<number>(surql`count(<-comment)`), },});
// String array (pass-through)const posts = await Post.select({ select: ['title', 'author.name'],});
// Raw SurrealQLconst posts = await Post.select({ select: surql`title, count(<-comment) AS commentCount`,});Type Parameters
Section titled “Type Parameters”TTable
Section titled “TTable”TTable
The data shape of the table being queried.
TFields
Section titled “TFields”TFields extends Record<string, FieldDefinition<unknown>> = Record<string, FieldDefinition<unknown>>
The field definitions of the table (for type-safe select).
Properties
Section titled “Properties”explain?
Section titled “explain?”
optionalexplain:boolean
Defined in: define/table/types/query.ts:136
If true, returns the query plan instead of the results.
fetch?
Section titled “fetch?”
optionalfetch:string[]
Defined in: define/table/types/query.ts:128
An array of fields to fetch (expand related records).
optionalfrom:BoundQuery<unknown[]> |Expr|Table<string> |RecordId<string>
Defined in: define/table/types/query.ts:110
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[]
Defined in: define/table/types/query.ts:120
An array of fields to group the results by.
limit?
Section titled “limit?”
optionallimit:number
Defined in: define/table/types/query.ts:124
The maximum number of records to return.
optionalomit:string[] |OmitSelect<TFields>
Defined in: define/table/types/query.ts:93
Fields to omit from the result (native OMIT clause).
Cannot be used together with select.
Supports two formats:
- Object: Type-safe
{ field: true }format with inferred return type - String array: Pass-through field names (less type-safe)
Example
Section titled “Example”// Type-safe omit (recommended)const users = await User.select({ omit: { password: true } });// → SELECT * OMIT password FROM user// Type: Omit<User, 'password'>[]
// String array (less type-safe)const users = await User.select({ omit: ['password'] });// → SELECT * OMIT password FROM user
optionalonly:boolean
Defined in: define/table/types/query.ts:112
If true, returns only the first record from the result set.
orderBy?
Section titled “orderBy?”
optionalorderBy:OrderByClause[]
Defined in: define/table/types/query.ts:122
An array of OrderByClause objects to sort the results.
parallel?
Section titled “parallel?”
optionalparallel:boolean
Defined in: define/table/types/query.ts:132
If true, runs the query in parallel with other queries.
select?
Section titled “select?”
optionalselect:SelectOption<TFields>
Defined in: define/table/types/query.ts:71
Fields to select. Supports multiple formats:
- Object: Type-safe field selection with nested support
- String array: Pass-through field names
- BoundQuery/Expr: Raw SurrealQL
If omitted, all fields (*) are selected.
split?
Section titled “split?”
optionalsplit:string[]
Defined in: define/table/types/query.ts:118
An array of fields to split the results by.
start?
Section titled “start?”
optionalstart:number
Defined in: define/table/types/query.ts:126
The starting record number.
tempfiles?
Section titled “tempfiles?”
optionaltempfiles:boolean
Defined in: define/table/types/query.ts:134
If true, enables temporary file usage for the query.
timeout?
Section titled “timeout?”
optionaltimeout:string
Defined in: define/table/types/query.ts:130
The timeout for the query, specified in a duration string (e.g. “1m”).
value?
Section titled “value?”
optionalvalue:string
Defined in: define/table/types/query.ts:107
Select a single field’s values (native SELECT VALUE).
Returns an array of values instead of objects.
Cannot be used together with select.
Example
Section titled “Example”const names = await User.select({ value: 'name' });// → SELECT VALUE name FROM user// Type: string[]where?
Section titled “where?”
optionalwhere:BoundQuery<unknown[]> |Expr
Defined in: define/table/types/query.ts:116
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:114
The WITH clause for the query, specifying index usage.