Table
const
Table:object
Defined in: define.ts:289
Type declaration
Section titled “Type declaration”normal()
Section titled “normal()”
readonly
normal<TFields
>(options
):ModelStatic
<ModelInstance
<InferTableDataFromFields
<TFields
>>,TFields
>
Define a normal (non-relation) SurrealDB table model.
Type Parameters
Section titled “Type Parameters”TFields
Section titled “TFields”TFields
extends Record
<string
, FieldDefinition
<unknown
>>
The shape of the table’s fields.
Parameters
Section titled “Parameters”options
Section titled “options”NormalTableOptions
<TFields
>
Table options including name, fields, indexes, permissions, etc.
Returns
Section titled “Returns”ModelStatic
<ModelInstance
<InferTableDataFromFields
<TFields
>>, TFields
>
A model class with static CRUD/query methods and instance typing.
Example
Section titled “Example”class User extends Table.normal({ name: 'user', fields: { name: Field.string(), age: Field.number() }, schemafull: true,}) {}
relation()
Section titled “relation()”
readonly
relation<TIn
,TOut
,TOther
>(options
):ModelStatic
<ModelInstance
<InferTableDataFromFields
<RelationTableFields
<TIn
,TOut
,TOther
>>>,RelationTableFields
<TIn
,TOut
,TOther
>>
Define a relation table model (edge table) for SurrealDB. Enforces presence of ‘in’ and ‘out’ fields for relation endpoints.
Type Parameters
Section titled “Type Parameters”TIn
extends FieldDefinition
<unknown
>
FieldDefinition for the ‘in’ endpoint (source node).
TOut
extends FieldDefinition
<unknown
>
FieldDefinition for the ‘out’ endpoint (target node).
TOther
Section titled “TOther”TOther
extends Record
<string
, FieldDefinition
<unknown
>> = Record
<string
, never
>
Additional fields for the relation (optional).
Parameters
Section titled “Parameters”options
Section titled “options”RelationTableOptions
<TIn
, TOut
, TOther
>
Relation table options including name, fields (must include ‘in’ and ‘out’), etc.
Returns
Section titled “Returns”ModelStatic
<ModelInstance
<InferTableDataFromFields
<RelationTableFields
<TIn
, TOut
, TOther
>>>, RelationTableFields
<TIn
, TOut
, TOther
>>
A model class for the relation table with static CRUD/query methods and instance typing.
Example
Section titled “Example”const Authored = Table.relation({ name: 'authored', fields: { in: Field.record(() => User), out: Field.record(() => Post), since: Field.datetime(), },});