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.
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:259
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:280
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:295
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:692
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:711
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:268
Gets the table name for this model.
Returns
Section titled “Returns”string
insert()
Section titled “insert()”Call Signature
Section titled “Call Signature”insert<
T>(this,options):Promise<InstanceType<T>>
Defined in: define/table/types/model.ts:316
Inserts a single record using INSERT statement (implicit db).
Type Parameters
Section titled “Type Parameters”T extends ModelStatic<TInstance, TFields, TOptions>
Parameters
Section titled “Parameters”T
options
Section titled “options”InsertQueryOptions<InferShapeFromFields<TFields>, Partial<InferShapeFromFields<TFields>>>
Insert options including data to insert.
Returns
Section titled “Returns”Promise<InstanceType<T>>
A promise that resolves to the inserted model instance.
Example
Section titled “Example”const user = await User.insert({ data: { name: 'John', email: 'john@example.com' },});Call Signature
Section titled “Call Signature”insert<
T>(this,options):Promise<InstanceType<T>[]>
Defined in: define/table/types/model.ts:338
Bulk inserts multiple records using INSERT statement (implicit db).
Type Parameters
Section titled “Type Parameters”T extends ModelStatic<TInstance, TFields, TOptions>
Parameters
Section titled “Parameters”T
options
Section titled “options”InsertQueryOptions<InferShapeFromFields<TFields>, Partial<InferShapeFromFields<TFields>>[]>
Insert options including array of data to insert.
Returns
Section titled “Returns”Promise<InstanceType<T>[]>
A promise that resolves to an array of inserted model instances.
Example
Section titled “Example”const users = await User.insert({ data: [ { name: 'John', email: 'john@example.com' }, { name: 'Jane', email: 'jane@example.com' }, ],});Call Signature
Section titled “Call Signature”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).
Type Parameters
Section titled “Type Parameters”T extends ModelStatic<TInstance, TFields, TOptions>
Parameters
Section titled “Parameters”T
A SurrealDB connection or transaction object.
options
Section titled “options”InsertQueryOptions<InferShapeFromFields<TFields>, Partial<InferShapeFromFields<TFields>>>
Insert options including data to insert.
Returns
Section titled “Returns”Promise<InstanceType<T>>
A promise that resolves to the inserted model instance.
Example
Section titled “Example”const user = await User.insert(db, { data: { name: 'John', email: 'john@example.com' },});Call Signature
Section titled “Call Signature”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).
Type Parameters
Section titled “Type Parameters”T extends ModelStatic<TInstance, TFields, TOptions>
Parameters
Section titled “Parameters”T
A SurrealDB connection or transaction object.
options
Section titled “options”InsertQueryOptions<InferShapeFromFields<TFields>, Partial<InferShapeFromFields<TFields>>[]>
Insert options including array of data to insert.
Returns
Section titled “Returns”Promise<InstanceType<T>[]>
A promise that resolves to an array of inserted model instances.
Example
Section titled “Example”const users = await User.insert(db, { data: [ { name: 'John', email: 'john@example.com' }, { name: 'Jane', email: 'jane@example.com' }, ],});select()
Section titled “select()”Call Signature
Section titled “Call Signature”select(
this):Promise<TInstance[]>
Defined in: define/table/types/model.ts:407
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(
this,options):Promise<Record<string,unknown>[]>
Defined in: define/table/types/model.ts:412
Selects records with GROUP BY aggregation (implicit db).
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
options
Section titled “options”SelectQueryOptions<InferShapeFromFields<TFields>, TFields> & object
Returns
Section titled “Returns”Promise<Record<string, unknown>[]>
Call Signature
Section titled “Call Signature”select(
this,options):Promise<unknown[]>
Defined in: define/table/types/model.ts:422
Selects records with VALUE clause - returns array of values (implicit db).
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
options
Section titled “options”SelectQueryOptions<InferShapeFromFields<TFields>, TFields> & object
Returns
Section titled “Returns”Promise<unknown[]>
Call Signature
Section titled “Call Signature”select(
this,options):Promise<Partial<InferShapeFromFields<TFields>>[]>
Defined in: define/table/types/model.ts:432
Selects records with OMIT clause (implicit db).
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
options
Section titled “options”SelectQueryOptions<InferShapeFromFields<TFields>, TFields> & object
Returns
Section titled “Returns”Promise<Partial<InferShapeFromFields<TFields>>[]>
Call Signature
Section titled “Call Signature”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.
Type Parameters
Section titled “Type Parameters”TSelect
Section titled “TSelect”TSelect extends FieldSelect<TFields>
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
options
Section titled “options”Omit<SelectQueryOptions<InferShapeFromFields<TFields>, TFields>, "select"> & object
Returns
Section titled “Returns”Promise<InferSelectResult<TFields, TSelect>[]>
Call Signature
Section titled “Call Signature”select(
this,options):Promise<TInstance|undefined>
Defined in: define/table/types/model.ts:456
Selects a single full model instance (implicit db).
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
options
Section titled “options”SelectQueryOptions<InferShapeFromFields<TFields>, TFields> & object
Returns
Section titled “Returns”Promise<TInstance | undefined>
Call Signature
Section titled “Call Signature”select(
this,options):Promise<TInstance[]>
Defined in: define/table/types/model.ts:466
Selects multiple full model instances with options (implicit db).
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
options
Section titled “options”SelectQueryOptions<InferShapeFromFields<TFields>, TFields>
Returns
Section titled “Returns”Promise<TInstance[]>
Call Signature
Section titled “Call Signature”select(
this,db):Promise<TInstance[]>
Defined in: define/table/types/model.ts:484
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(
this,db,options):Promise<Record<string,unknown>[]>
Defined in: define/table/types/model.ts:492
Selects records with GROUP BY aggregation (explicit db).
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
options
Section titled “options”SelectQueryOptions<InferShapeFromFields<TFields>, TFields> & object
Returns
Section titled “Returns”Promise<Record<string, unknown>[]>
Call Signature
Section titled “Call Signature”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).
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
options
Section titled “options”SelectQueryOptions<InferShapeFromFields<TFields>, TFields> & object
Returns
Section titled “Returns”Promise<unknown[]>
Call Signature
Section titled “Call Signature”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.
Type Parameters
Section titled “Type Parameters”TOmit extends OmitSelect<TFields>
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
options
Section titled “options”Omit<SelectQueryOptions<InferShapeFromFields<TFields>, TFields>, "omit"> & object
Returns
Section titled “Returns”Promise<InferOmitResult<TFields, TOmit>[]>
Example
Section titled “Example”const users = await User.select(db, { omit: { password: true } });// Type: Omit<User, 'password'>[]Call Signature
Section titled “Call Signature”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.
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
options
Section titled “options”SelectQueryOptions<InferShapeFromFields<TFields>, TFields> & object
Returns
Section titled “Returns”Promise<Partial<InferShapeFromFields<TFields>>[]>
Call Signature
Section titled “Call Signature”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.
Type Parameters
Section titled “Type Parameters”TSelect
Section titled “TSelect”TSelect extends FieldSelect<TFields>
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
options
Section titled “options”Omit<SelectQueryOptions<InferShapeFromFields<TFields>, TFields>, "select"> & object
Returns
Section titled “Returns”Promise<InferSelectResult<TFields, TSelect>[]>
Example
Section titled “Example”// 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 fieldconst posts = await Post.select(db, { select: { title: true, commentCount: typed<number>(surql`count(<-comment)`) }});// Type: { title: string; commentCount: number }[]Call Signature
Section titled “Call Signature”select(
this,db,options):Promise<TInstance|undefined>
Defined in: define/table/types/model.ts:575
Selects a single full model instance (explicit db).
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
options
Section titled “options”SelectQueryOptions<InferShapeFromFields<TFields>, TFields> & object
Returns
Section titled “Returns”Promise<TInstance | undefined>
Call Signature
Section titled “Call Signature”select(
this,db,options):Promise<TInstance[]>
Defined in: define/table/types/model.ts:586
Selects multiple full model instances with options (explicit db).
Parameters
Section titled “Parameters”ModelStatic<TInstance, TFields, TOptions>
options
Section titled “options”SelectQueryOptions<InferShapeFromFields<TFields>, TFields>
Returns
Section titled “Returns”Promise<TInstance[]>
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:602
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:617
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:648
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:672
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'});