Skip to content
🚀 This documentation is for unreal-orm 1.0.0 alpha which requires SurrealDB 2.0 alpha SDK. For the stable version, see npm.

SelectQueryOptions

Defined in: define/table/types/query.ts:56

Defines the options available for a SELECT query.

// Type-safe field selection
const posts = await Post.select({
select: {
title: true,
author: { name: true, email: true },
},
});
// Type: { title: string; author: { name: string; email: string } }[]
// With custom computed field
const 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 SurrealQL
const posts = await Post.select({
select: surql`title, count(<-comment) AS commentCount`,
});

TTable

The data shape of the table being queried.

TFields extends Record<string, FieldDefinition<unknown>> = Record<string, FieldDefinition<unknown>>

The field definitions of the table (for type-safe select).

optional explain: boolean

Defined in: define/table/types/query.ts:136

If true, returns the query plan instead of the results.


optional fetch: string[]

Defined in: define/table/types/query.ts:128

An array of fields to fetch (expand related records).


optional from: 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.


optional groupBy: string[]

Defined in: define/table/types/query.ts:120

An array of fields to group the results by.


optional limit: number

Defined in: define/table/types/query.ts:124

The maximum number of records to return.


optional omit: 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)
// 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

optional only: boolean

Defined in: define/table/types/query.ts:112

If true, returns only the first record from the result set.


optional orderBy: OrderByClause[]

Defined in: define/table/types/query.ts:122

An array of OrderByClause objects to sort the results.


optional parallel: boolean

Defined in: define/table/types/query.ts:132

If true, runs the query in parallel with other queries.


optional select: 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.


optional split: string[]

Defined in: define/table/types/query.ts:118

An array of fields to split the results by.


optional start: number

Defined in: define/table/types/query.ts:126

The starting record number.


optional tempfiles: boolean

Defined in: define/table/types/query.ts:134

If true, enables temporary file usage for the query.


optional timeout: string

Defined in: define/table/types/query.ts:130

The timeout for the query, specified in a duration string (e.g. “1m”).


optional value: 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.

const names = await User.select({ value: 'name' });
// → SELECT VALUE name FROM user
// Type: string[]

optional where: 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.


optional with: { indexes: string[]; } | { noIndex: true; }

Defined in: define/table/types/query.ts:114

The WITH clause for the query, specifying index usage.