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.

ModelStatic

ModelStatic<TInstance, TFields, TOptions> = TInstance

Defined in: define/table/types/model.ts:237

Represents the static side of a model class (the class itself). This includes the constructor, static properties like _tableName and _fields, and static methods like create and the overloaded select.

TInstance extends ModelInstance<InferShapeFromFields<TFields>>

The type of a model instance.

TFields extends Record<string, FieldDefinition<unknown>>

The field definitions for the model.

TOptions extends TableDefineOptions<TFields>

The table definition options.

new ModelStatic(data): TInstance

Defined in: define/table/types/model.ts:243

The constructor signature for the model class.

InferShapeFromFields<TFields>

TInstance

create<T>(this, data): Promise<InstanceType<T>>

Defined in: define/table/types/model.ts:264

Creates a new record in the database (implicit db). Uses the globally configured database connection.

T extends ModelStatic<TInstance, TFields, TOptions>

T

CreateData<TFields>

The data to create the record with.

Promise<InstanceType<T>>

A promise that resolves to the created model instance.

const user = await User.create({ name: 'John', email: 'john@example.com' });

create<T>(this, db, data): Promise<InstanceType<T>>

Defined in: define/table/types/model.ts:279

Creates a new record in the database (explicit db).

T extends ModelStatic<TInstance, TFields, TOptions>

T

SurrealLike

A SurrealDB connection or transaction object.

CreateData<TFields>

The data to create the record with.

Promise<InstanceType<T>>

A promise that resolves to the created model instance.

const user = await User.create(db, { name: 'John', email: 'john@example.com' });

delete<T>(this, id): Promise<void>

Defined in: define/table/types/model.ts:557

Deletes a record from the database (implicit db).

T extends ModelStatic<TInstance, TFields, TOptions>

T

RecordId

The record ID to delete.

Promise<void>

A promise that resolves when the record is deleted.

await User.delete('user:123');

delete<T>(this, db, id): Promise<void>

Defined in: define/table/types/model.ts:576

Deletes a record from the database (explicit db).

T extends ModelStatic<TInstance, TFields, TOptions>

T

SurrealLike

A SurrealDB connection or transaction object.

RecordId

The record ID to delete.

Promise<void>

A promise that resolves when the record is deleted.

await User.delete(db, 'user:123');

getTableName(): string

Defined in: define/table/types/model.ts:252

Gets the table name for this model.

string


select(this): Promise<TInstance[]>

Defined in: define/table/types/model.ts:297

Selects all full model instances from the table (implicit db).

ModelStatic<TInstance, TFields, TOptions>

Promise<TInstance[]>

A promise that resolves to an array of all model instances.

const allUsers = await User.select();

select<QueryOptions>(this, options): Promise<Record<string, unknown>[]>

Defined in: define/table/types/model.ts:302

Selects records with GROUP BY aggregation (implicit db).

QueryOptions extends SelectQueryOptions<InferShapeFromFields<TFields>>

ModelStatic<TInstance, TFields, TOptions>

QueryOptions & object

Promise<Record<string, unknown>[]>

select<QueryOptions>(this, options): Promise<Partial<InferShapeFromFields<TFields>> | undefined>

Defined in: define/table/types/model.ts:312

Selects a single record with specific field projection (implicit db).

QueryOptions extends SelectQueryOptions<InferShapeFromFields<TFields>>

ModelStatic<TInstance, TFields, TOptions>

QueryOptions & object

Promise<Partial<InferShapeFromFields<TFields>> | undefined>

select<QueryOptions>(this, options): Promise<Partial<InferShapeFromFields<TFields>>[]>

Defined in: define/table/types/model.ts:322

Selects multiple records with specific field projection (implicit db).

QueryOptions extends SelectQueryOptions<InferShapeFromFields<TFields>>

ModelStatic<TInstance, TFields, TOptions>

QueryOptions & object

Promise<Partial<InferShapeFromFields<TFields>>[]>

select<QueryOptions>(this, options): Promise<TInstance | undefined>

Defined in: define/table/types/model.ts:332

Selects a single full model instance (implicit db).

QueryOptions extends SelectQueryOptions<InferShapeFromFields<TFields>>

ModelStatic<TInstance, TFields, TOptions>

QueryOptions & object

Promise<TInstance | undefined>

select<QueryOptions>(this, options): Promise<TInstance[]>

Defined in: define/table/types/model.ts:342

Selects multiple full model instances with options (implicit db).

QueryOptions extends SelectQueryOptions<InferShapeFromFields<TFields>>

ModelStatic<TInstance, TFields, TOptions>

QueryOptions & object

Promise<TInstance[]>

select(this, db): Promise<TInstance[]>

Defined in: define/table/types/model.ts:362

Selects all full model instances from the table (explicit db).

ModelStatic<TInstance, TFields, TOptions>

SurrealLike

A SurrealDB connection or transaction object.

Promise<TInstance[]>

A promise that resolves to an array of all model instances.

const allUsers = await User.select(db);

select<QueryOptions>(this, db, options): Promise<Record<string, unknown>[]>

Defined in: define/table/types/model.ts:377

Selects records with GROUP BY aggregation (explicit db).

QueryOptions extends SelectQueryOptions<InferShapeFromFields<TFields>>

ModelStatic<TInstance, TFields, TOptions>

SurrealLike

A SurrealDB connection or transaction object.

QueryOptions & object

Query options including groupBy clause.

Promise<Record<string, unknown>[]>

A promise that resolves to aggregated results.

const results = await User.select(db, { groupBy: ['role'], select: ['role', 'COUNT() as count'] });

select<QueryOptions>(this, db, options): Promise<Partial<InferShapeFromFields<TFields>> | undefined>

Defined in: define/table/types/model.ts:395

Selects a single record with specific field projection (explicit db).

QueryOptions extends SelectQueryOptions<InferShapeFromFields<TFields>>

ModelStatic<TInstance, TFields, TOptions>

SurrealLike

A SurrealDB connection or transaction object.

QueryOptions & object

Query options including select fields and only: true.

Promise<Partial<InferShapeFromFields<TFields>> | undefined>

A promise that resolves to the projected record or undefined.

const user = await User.select(db, { from: 'user:123', select: ['name', 'email'], only: true });

select<QueryOptions>(this, db, options): Promise<Partial<InferShapeFromFields<TFields>>[]>

Defined in: define/table/types/model.ts:413

Selects multiple records with specific field projection (explicit db).

QueryOptions extends SelectQueryOptions<InferShapeFromFields<TFields>>

ModelStatic<TInstance, TFields, TOptions>

SurrealLike

A SurrealDB connection or transaction object.

QueryOptions & object

Query options including select fields.

Promise<Partial<InferShapeFromFields<TFields>>[]>

A promise that resolves to an array of projected records.

const users = await User.select(db, { select: ['name', 'email'] });

select<QueryOptions>(this, db, options): Promise<TInstance | undefined>

Defined in: define/table/types/model.ts:431

Selects a single full model instance (explicit db).

QueryOptions extends SelectQueryOptions<InferShapeFromFields<TFields>>

ModelStatic<TInstance, TFields, TOptions>

SurrealLike

A SurrealDB connection or transaction object.

QueryOptions & object

Query options with only: true.

Promise<TInstance | undefined>

A promise that resolves to the model instance or undefined.

const user = await User.select(db, { from: 'user:123', only: true });

select<QueryOptions>(this, db, options): Promise<TInstance[]>

Defined in: define/table/types/model.ts:449

Selects multiple full model instances with options (explicit db).

QueryOptions extends SelectQueryOptions<InferShapeFromFields<TFields>>

ModelStatic<TInstance, TFields, TOptions>

SurrealLike

A SurrealDB connection or transaction object.

QueryOptions & object

Query options (no field projection).

Promise<TInstance[]>

A promise that resolves to an array of model instances.

const users = await User.select(db, { limit: 10 });

update<T>(this, id, options): Promise<InstanceType<T>>

Defined in: define/table/types/model.ts:467

Updates a record using content, merge, or replace mode (implicit db).

T extends ModelStatic<TInstance, TFields, TOptions>

T

RecordId

The record ID to update.

Update options including data and mode.

Partial<InferShapeFromFields<TFields>>

"content" | "merge" | "replace"

Promise<InstanceType<T>>

A promise that resolves to the updated model instance.

update<T>(this, id, options): Promise<InstanceType<T>>

Defined in: define/table/types/model.ts:482

Updates a record using JSON Patch operations (implicit db).

T extends ModelStatic<TInstance, TFields, TOptions>

T

RecordId

The record ID to update.

Update options including patch operations and mode.

JsonPatchOperation[]

"patch"

Promise<InstanceType<T>>

A promise that resolves to the updated model instance.

update<T>(this, db, id, options): Promise<InstanceType<T>>

Defined in: define/table/types/model.ts:513

Updates a record using content, merge, or replace mode (explicit db).

T extends ModelStatic<TInstance, TFields, TOptions>

T

SurrealLike

A SurrealDB connection or transaction object.

RecordId

The record ID to update.

Update options including data and mode.

Partial<InferShapeFromFields<TFields>>

"content" | "merge" | "replace"

Promise<InstanceType<T>>

A promise that resolves to the updated model instance.

// Full content replacement
const user = await User.update(db, 'user:123', {
data: { name: 'Jane', email: 'jane@example.com' },
mode: 'content'
});
// Partial merge
const user = await User.update(db, 'user:123', {
data: { name: 'Jane' },
mode: 'merge'
});

update<T>(this, db, id, options): Promise<InstanceType<T>>

Defined in: define/table/types/model.ts:537

Updates a record using JSON Patch operations (explicit db).

T extends ModelStatic<TInstance, TFields, TOptions>

T

SurrealLike

A SurrealDB connection or transaction object.

RecordId

The record ID to update.

Update options including patch operations and mode.

JsonPatchOperation[]

"patch"

Promise<InstanceType<T>>

A promise that resolves to the updated model instance.

const user = await User.update(db, 'user:123', {
data: [{ op: 'replace', path: '/name', value: 'Jane' }],
mode: 'patch'
});