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.
Type Parameters
Section titled “Type Parameters”TInstance
Section titled “TInstance”TInstance extends ModelInstance<InferShapeFromFields<TFields>>
The type of a model instance.
TFields
Section titled “TFields”TFields extends Record<string, FieldDefinition<unknown>>
The field definitions for the model.
TOptions
Section titled “TOptions”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.
Parameters
Section titled “Parameters”InferShapeFromFields<TFields>
Returns
Section titled “Returns”TInstance
Methods
Section titled “Methods”create()
Section titled “create()”Call Signature
Section titled “Call Signature”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.
Type Parameters
Section titled “Type Parameters”T extends ModelStatic<TInstance, TFields, TOptions>
Parameters
Section titled “Parameters”T
CreateData<TFields>
The data to create the record with.
Returns
Section titled “Returns”Promise<InstanceType<T>>
A promise that resolves to the created model instance.
Example
Section titled “Example”const user = await User.create({ name: 'John', email: 'john@example.com' });Call Signature
Section titled “Call Signature”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).
Type Parameters
Section titled “Type Parameters”T extends ModelStatic<TInstance, TFields, TOptions>
Parameters
Section titled “Parameters”T
A SurrealDB connection or transaction object.
CreateData<TFields>
The data to create the record with.
Returns
Section titled “Returns”Promise<InstanceType<T>>
A promise that resolves to the created model instance.
Example
Section titled “Example”const user = await User.create(db, { name: 'John', email: 'john@example.com' });delete()
Section titled “delete()”Call Signature
Section titled “Call Signature”delete<
T>(this,id):Promise<void>
Defined in: define/table/types/model.ts:557
Deletes a record from the database (implicit db).
Type Parameters
Section titled “Type Parameters”T extends ModelStatic<TInstance, TFields, TOptions>
Parameters
Section titled “Parameters”T
RecordId
The record ID to delete.
Returns
Section titled “Returns”Promise<void>
A promise that resolves when the record is deleted.
Example
Section titled “Example”await User.delete('user:123');Call Signature
Section titled “Call Signature”delete<
T>(this,db,id):Promise<void>
Defined in: define/table/types/model.ts:576
Deletes a record from the database (explicit db).
Type Parameters
Section titled “Type Parameters”T extends ModelStatic<TInstance, TFields, TOptions>
Parameters
Section titled “Parameters”T
A SurrealDB connection or transaction object.
RecordId
The record ID to delete.
Returns
Section titled “Returns”Promise<void>
A promise that resolves when the record is deleted.
Example
Section titled “Example”await User.delete(db, 'user:123');getTableName()
Section titled “getTableName()”getTableName():
string
Defined in: define/table/types/model.ts:252
Gets the table name for this model.
Returns
Section titled “Returns”string
select()
Section titled “select()”Call Signature
Section titled “Call Signature”select(
this):Promise<TInstance[]>
Defined in: define/table/types/model.ts:297
Selects all full model instances from the table (implicit db).
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
Returns
Section titled “Returns”Promise<TInstance[]>
A promise that resolves to an array of all model instances.
Example
Section titled “Example”const allUsers = await User.select();Call Signature
Section titled “Call Signature”select<
QueryOptions>(this,options):Promise<Record<string,unknown>[]>
Defined in: define/table/types/model.ts:302
Selects records with GROUP BY aggregation (implicit db).
Type Parameters
Section titled “Type Parameters”QueryOptions
Section titled “QueryOptions”QueryOptions extends SelectQueryOptions<InferShapeFromFields<TFields>>
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
options
Section titled “options”QueryOptions & object
Returns
Section titled “Returns”Promise<Record<string, unknown>[]>
Call Signature
Section titled “Call Signature”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).
Type Parameters
Section titled “Type Parameters”QueryOptions
Section titled “QueryOptions”QueryOptions extends SelectQueryOptions<InferShapeFromFields<TFields>>
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
options
Section titled “options”QueryOptions & object
Returns
Section titled “Returns”Promise<Partial<InferShapeFromFields<TFields>> | undefined>
Call Signature
Section titled “Call Signature”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).
Type Parameters
Section titled “Type Parameters”QueryOptions
Section titled “QueryOptions”QueryOptions extends SelectQueryOptions<InferShapeFromFields<TFields>>
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
options
Section titled “options”QueryOptions & object
Returns
Section titled “Returns”Promise<Partial<InferShapeFromFields<TFields>>[]>
Call Signature
Section titled “Call Signature”select<
QueryOptions>(this,options):Promise<TInstance|undefined>
Defined in: define/table/types/model.ts:332
Selects a single full model instance (implicit db).
Type Parameters
Section titled “Type Parameters”QueryOptions
Section titled “QueryOptions”QueryOptions extends SelectQueryOptions<InferShapeFromFields<TFields>>
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
options
Section titled “options”QueryOptions & object
Returns
Section titled “Returns”Promise<TInstance | undefined>
Call Signature
Section titled “Call Signature”select<
QueryOptions>(this,options):Promise<TInstance[]>
Defined in: define/table/types/model.ts:342
Selects multiple full model instances with options (implicit db).
Type Parameters
Section titled “Type Parameters”QueryOptions
Section titled “QueryOptions”QueryOptions extends SelectQueryOptions<InferShapeFromFields<TFields>>
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
options
Section titled “options”QueryOptions & object
Returns
Section titled “Returns”Promise<TInstance[]>
Call Signature
Section titled “Call Signature”select(
this,db):Promise<TInstance[]>
Defined in: define/table/types/model.ts:362
Selects all full model instances from the table (explicit db).
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
A SurrealDB connection or transaction object.
Returns
Section titled “Returns”Promise<TInstance[]>
A promise that resolves to an array of all model instances.
Example
Section titled “Example”const allUsers = await User.select(db);Call Signature
Section titled “Call Signature”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).
Type Parameters
Section titled “Type Parameters”QueryOptions
Section titled “QueryOptions”QueryOptions extends SelectQueryOptions<InferShapeFromFields<TFields>>
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
A SurrealDB connection or transaction object.
options
Section titled “options”QueryOptions & object
Query options including groupBy clause.
Returns
Section titled “Returns”Promise<Record<string, unknown>[]>
A promise that resolves to aggregated results.
Example
Section titled “Example”const results = await User.select(db, { groupBy: ['role'], select: ['role', 'COUNT() as count'] });Call Signature
Section titled “Call Signature”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).
Type Parameters
Section titled “Type Parameters”QueryOptions
Section titled “QueryOptions”QueryOptions extends SelectQueryOptions<InferShapeFromFields<TFields>>
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
A SurrealDB connection or transaction object.
options
Section titled “options”QueryOptions & object
Query options including select fields and only: true.
Returns
Section titled “Returns”Promise<Partial<InferShapeFromFields<TFields>> | undefined>
A promise that resolves to the projected record or undefined.
Example
Section titled “Example”const user = await User.select(db, { from: 'user:123', select: ['name', 'email'], only: true });Call Signature
Section titled “Call Signature”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).
Type Parameters
Section titled “Type Parameters”QueryOptions
Section titled “QueryOptions”QueryOptions extends SelectQueryOptions<InferShapeFromFields<TFields>>
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
A SurrealDB connection or transaction object.
options
Section titled “options”QueryOptions & object
Query options including select fields.
Returns
Section titled “Returns”Promise<Partial<InferShapeFromFields<TFields>>[]>
A promise that resolves to an array of projected records.
Example
Section titled “Example”const users = await User.select(db, { select: ['name', 'email'] });Call Signature
Section titled “Call Signature”select<
QueryOptions>(this,db,options):Promise<TInstance|undefined>
Defined in: define/table/types/model.ts:431
Selects a single full model instance (explicit db).
Type Parameters
Section titled “Type Parameters”QueryOptions
Section titled “QueryOptions”QueryOptions extends SelectQueryOptions<InferShapeFromFields<TFields>>
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
A SurrealDB connection or transaction object.
options
Section titled “options”QueryOptions & object
Query options with only: true.
Returns
Section titled “Returns”Promise<TInstance | undefined>
A promise that resolves to the model instance or undefined.
Example
Section titled “Example”const user = await User.select(db, { from: 'user:123', only: true });Call Signature
Section titled “Call Signature”select<
QueryOptions>(this,db,options):Promise<TInstance[]>
Defined in: define/table/types/model.ts:449
Selects multiple full model instances with options (explicit db).
Type Parameters
Section titled “Type Parameters”QueryOptions
Section titled “QueryOptions”QueryOptions extends SelectQueryOptions<InferShapeFromFields<TFields>>
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
A SurrealDB connection or transaction object.
options
Section titled “options”QueryOptions & object
Query options (no field projection).
Returns
Section titled “Returns”Promise<TInstance[]>
A promise that resolves to an array of model instances.
Example
Section titled “Example”const users = await User.select(db, { limit: 10 });update()
Section titled “update()”Call Signature
Section titled “Call Signature”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).
Type Parameters
Section titled “Type Parameters”T extends ModelStatic<TInstance, TFields, TOptions>
Parameters
Section titled “Parameters”T
RecordId
The record ID to update.
options
Section titled “options”Update options including data and mode.
Partial<InferShapeFromFields<TFields>>
"content" | "merge" | "replace"
Returns
Section titled “Returns”Promise<InstanceType<T>>
A promise that resolves to the updated model instance.
Call Signature
Section titled “Call Signature”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).
Type Parameters
Section titled “Type Parameters”T extends ModelStatic<TInstance, TFields, TOptions>
Parameters
Section titled “Parameters”T
RecordId
The record ID to update.
options
Section titled “options”Update options including patch operations and mode.
"patch"
Returns
Section titled “Returns”Promise<InstanceType<T>>
A promise that resolves to the updated model instance.
Call Signature
Section titled “Call Signature”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).
Type Parameters
Section titled “Type Parameters”T extends ModelStatic<TInstance, TFields, TOptions>
Parameters
Section titled “Parameters”T
A SurrealDB connection or transaction object.
RecordId
The record ID to update.
options
Section titled “options”Update options including data and mode.
Partial<InferShapeFromFields<TFields>>
"content" | "merge" | "replace"
Returns
Section titled “Returns”Promise<InstanceType<T>>
A promise that resolves to the updated model instance.
Example
Section titled “Example”// Full content replacementconst user = await User.update(db, 'user:123', { data: { name: 'Jane', email: 'jane@example.com' }, mode: 'content'});
// Partial mergeconst user = await User.update(db, 'user:123', { data: { name: 'Jane' }, mode: 'merge'});Call Signature
Section titled “Call Signature”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).
Type Parameters
Section titled “Type Parameters”T extends ModelStatic<TInstance, TFields, TOptions>
Parameters
Section titled “Parameters”T
A SurrealDB connection or transaction object.
RecordId
The record ID to update.
options
Section titled “options”Update options including patch operations and mode.
"patch"
Returns
Section titled “Returns”Promise<InstanceType<T>>
A promise that resolves to the updated model instance.
Example
Section titled “Example”const user = await User.update(db, 'user:123', { data: [{ op: 'replace', path: '/name', value: 'Jane' }], mode: 'patch'});