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

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

The constructor signature for the model class.

InferShapeFromFields<TFields>

TInstance

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

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

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

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

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

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

Gets the table name for this model.

string


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

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

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

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

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

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

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

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

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

ModelStatic<TInstance, TFields, TOptions>

SelectQueryOptions<InferShapeFromFields<TFields>, TFields> & object

Promise<unknown[]>

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

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

Selects records with OMIT clause (implicit db).

ModelStatic<TInstance, TFields, TOptions>

SelectQueryOptions<InferShapeFromFields<TFields>, TFields> & object

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

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

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

Selects with type-safe field selection object (implicit db). Returns inferred type based on selected fields.

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

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

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

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

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

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<InferOmitResult<TFields, TOmit>[]>

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

Selects records with type-safe OMIT clause (explicit db). Returns all fields except the omitted ones with proper type inference.

TOmit extends OmitSelect<TFields>

ModelStatic<TInstance, TFields, TOptions>

SurrealLike

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

Promise<InferOmitResult<TFields, TOmit>[]>

const users = await User.select(db, { omit: { password: true } });
// Type: Omit<User, 'password'>[]

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

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

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>[]>

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

Selects with type-safe field selection object (explicit db). Returns inferred type based on selected fields.

TSelect extends FieldSelect<TFields>

ModelStatic<TInstance, TFields, TOptions>

SurrealLike

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

Promise<InferSelectResult<TFields, TSelect>[]>

// Object select with nested fields - type is inferred!
const posts = await Post.select(db, {
select: { title: true, author: { name: true } }
});
// Type: { title: string; author: { name: string } }[]
// With computed field
const posts = await Post.select(db, {
select: { title: true, commentCount: typed<number>(surql`count(<-comment)`) }
});
// Type: { title: string; commentCount: number }[]

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

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

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

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

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

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

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

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