Skip to content
🚀 This documentation is for unreal-orm 1.0.0 alpha which requires SurrealDB 2.0 SDK. For use with version 1.x, see here.

ModelStatic

ModelStatic<TInstance, TFields, TOptions> = TInstance

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

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

The constructor signature for the model class.

InferShapeFromFields<TFields>

TInstance

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

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

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:304

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:765

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:784

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:277

Gets the table name for this model.

string


insert<T>(this, options): Promise<InstanceType<T>>

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

Inserts a single record using INSERT statement (implicit db).

T extends ModelStatic<TInstance, TFields, TOptions>

T

InsertQueryOptions<InferShapeFromFields<TFields>, Partial<InferShapeFromFields<TFields>>>

Insert options including data to insert.

Promise<InstanceType<T>>

A promise that resolves to the inserted model instance.

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

insert<T>(this, options): Promise<InstanceType<T>[]>

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

Bulk inserts multiple records using INSERT statement (implicit db).

T extends ModelStatic<TInstance, TFields, TOptions>

T

InsertQueryOptions<InferShapeFromFields<TFields>, Partial<InferShapeFromFields<TFields>>[]>

Insert options including array of data to insert.

Promise<InstanceType<T>[]>

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

const users = await User.insert({
data: [
{ name: 'John', email: 'john@example.com' },
{ name: 'Jane', email: 'jane@example.com' },
],
});

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

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

Inserts a single record using INSERT statement (explicit db).

T extends ModelStatic<TInstance, TFields, TOptions>

T

SurrealLike

A SurrealDB connection or transaction object.

InsertQueryOptions<InferShapeFromFields<TFields>, Partial<InferShapeFromFields<TFields>>>

Insert options including data to insert.

Promise<InstanceType<T>>

A promise that resolves to the inserted model instance.

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

insert<T>(this, db, options): Promise<InstanceType<T>[]>

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

Bulk inserts multiple records using INSERT statement (explicit db).

T extends ModelStatic<TInstance, TFields, TOptions>

T

SurrealLike

A SurrealDB connection or transaction object.

InsertQueryOptions<InferShapeFromFields<TFields>, Partial<InferShapeFromFields<TFields>>[]>

Insert options including array of data to insert.

Promise<InstanceType<T>[]>

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

const users = await User.insert(db, {
data: [
{ name: 'John', email: 'john@example.com' },
{ name: 'Jane', email: 'jane@example.com' },
],
});

select(this): Promise<TInstance[]>

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

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(this, options): Promise<Record<string, unknown>[]>

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

Selects records with GROUP BY aggregation (implicit db).

ModelStatic<TInstance, TFields, TOptions>

SelectQueryOptions<InferShapeFromFields<TFields>, TFields> & object

Promise<Record<string, unknown>[]>

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

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

Selects records with VALUE clause - returns array of values (implicit db).

ModelStatic<TInstance, TFields, TOptions>

SelectQueryOptions<InferShapeFromFields<TFields>, TFields> & object

Promise<unknown[]>

select<TOmit>(this, options): Promise<{ [K in string | number | symbol]: { [K in string | number | symbol as K extends keyof TOmit ? TOmit[K] extends true ? never : K : K]: InferFieldType<TFields[K]> }[K] } | undefined>

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

Selects and omits fields from a single record (implicit db).

TOmit extends OmitSelect<TFields>

ModelStatic<TInstance, TFields, TOptions>

Omit<SelectQueryOptions<InferShapeFromFields<TFields>, TFields>, "omit"> & object

Promise<{ [K in string | number | symbol]: { [K in string | number | symbol as K extends keyof TOmit ? TOmit[K] extends true ? never : K : K]: InferFieldType<TFields[K]> }[K] } | undefined>

select<TOmit>(this, options): Promise<{ [K in string | number | symbol]: { [K in string | number | symbol as K extends keyof TOmit ? TOmit[K] extends true ? never : K : K]: InferFieldType<TFields[K]> }[K] }[]>

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

TOmit extends OmitSelect<TFields>

ModelStatic<TInstance, TFields, TOptions>

Omit<SelectQueryOptions<InferShapeFromFields<TFields>, TFields>, "omit"> & object

Promise<{ [K in string | number | symbol]: { [K in string | number | symbol as K extends keyof TOmit ? TOmit[K] extends true ? never : K : K]: InferFieldType<TFields[K]> }[K] }[]>

select<TSelect>(this, options): Promise<InferSelectResult<TFields, TSelect> | undefined>

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

Selects specified fields from a single record (implicit db).

TSelect extends FieldSelect<TFields>

ModelStatic<TInstance, TFields, TOptions>

Omit<SelectQueryOptions<InferShapeFromFields<TFields>, TFields>, "select"> & object

Promise<InferSelectResult<TFields, TSelect> | undefined>

select<TSelect>(this, options): Promise<InferSelectResult<TFields, TSelect>[]>

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

TSelect extends FieldSelect<TFields>

ModelStatic<TInstance, TFields, TOptions>

Omit<SelectQueryOptions<InferShapeFromFields<TFields>, TFields>, "select"> & object

Promise<InferSelectResult<TFields, TSelect>[]>

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

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

Selects a single full model instance (implicit db).

ModelStatic<TInstance, TFields, TOptions>

SelectQueryOptions<InferShapeFromFields<TFields>, TFields> & object

Promise<TInstance | undefined>

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

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

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

ModelStatic<TInstance, TFields, TOptions>

SelectQueryOptions<InferShapeFromFields<TFields>, TFields>

Promise<TInstance[]>

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

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

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(this, db, options): Promise<Record<string, unknown>[]>

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

Selects records with GROUP BY aggregation (explicit db).

ModelStatic<TInstance, TFields, TOptions>

SurrealLike

SelectQueryOptions<InferShapeFromFields<TFields>, TFields> & object

Promise<Record<string, unknown>[]>

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

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

Selects records with VALUE clause - returns array of values (explicit db).

ModelStatic<TInstance, TFields, TOptions>

SurrealLike

SelectQueryOptions<InferShapeFromFields<TFields>, TFields> & object

Promise<unknown[]>

select<TOmit>(this, db, options): Promise<{ [K in string | number | symbol]: { [K in string | number | symbol as K extends keyof TOmit ? TOmit[K] extends true ? never : K : K]: InferFieldType<TFields[K]> }[K] } | undefined>

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

Selects and omits fields from a single record (explicit db).

TOmit extends OmitSelect<TFields>

ModelStatic<TInstance, TFields, TOptions>

SurrealLike

Omit<SelectQueryOptions<InferShapeFromFields<TFields>, TFields>, "omit"> & object

Promise<{ [K in string | number | symbol]: { [K in string | number | symbol as K extends keyof TOmit ? TOmit[K] extends true ? never : K : K]: InferFieldType<TFields[K]> }[K] } | undefined>

select<TOmit>(this, db, options): Promise<{ [K in string | number | symbol]: { [K in string | number | symbol as K extends keyof TOmit ? TOmit[K] extends true ? never : K : K]: InferFieldType<TFields[K]> }[K] }[]>

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

TOmit extends OmitSelect<TFields>

ModelStatic<TInstance, TFields, TOptions>

SurrealLike

Omit<SelectQueryOptions<InferShapeFromFields<TFields>, TFields>, "omit"> & object

Promise<{ [K in string | number | symbol]: { [K in string | number | symbol as K extends keyof TOmit ? TOmit[K] extends true ? never : K : K]: InferFieldType<TFields[K]> }[K] }[]>

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

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

Selects records with OMIT clause using string array (explicit db). Less type-safe than object format.

ModelStatic<TInstance, TFields, TOptions>

SurrealLike

SelectQueryOptions<InferShapeFromFields<TFields>, TFields> & object

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

select<TSelect>(this, db, options): Promise<InferSelectResult<TFields, TSelect> | undefined>

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

Selects specified fields from a single record (explicit db).

TSelect extends FieldSelect<TFields>

ModelStatic<TInstance, TFields, TOptions>

SurrealLike

Omit<SelectQueryOptions<InferShapeFromFields<TFields>, TFields>, "select"> & object

Promise<InferSelectResult<TFields, TSelect> | undefined>

select<TSelect>(this, db, options): Promise<InferSelectResult<TFields, TSelect>[]>

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

TSelect extends FieldSelect<TFields>

ModelStatic<TInstance, TFields, TOptions>

SurrealLike

Omit<SelectQueryOptions<InferShapeFromFields<TFields>, TFields>, "select"> & object

Promise<InferSelectResult<TFields, TSelect>[]>

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

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

Selects a single full model instance (explicit db).

ModelStatic<TInstance, TFields, TOptions>

SurrealLike

SelectQueryOptions<InferShapeFromFields<TFields>, TFields> & object

Promise<TInstance | undefined>

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

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

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

ModelStatic<TInstance, TFields, TOptions>

SurrealLike

SelectQueryOptions<InferShapeFromFields<TFields>, TFields>

Promise<TInstance[]>


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

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

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:690

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:721

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:745

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'
});