Skip to content

Table

const Table: object

Defined in: define.ts:289

readonly normal<TFields>(options): ModelStatic<ModelInstance<InferTableDataFromFields<TFields>>, TFields>

Define a normal (non-relation) SurrealDB table model.

TFields extends Record<string, FieldDefinition<unknown>>

The shape of the table’s fields.

NormalTableOptions<TFields>

Table options including name, fields, indexes, permissions, etc.

ModelStatic<ModelInstance<InferTableDataFromFields<TFields>>, TFields>

A model class with static CRUD/query methods and instance typing.

class User extends Table.normal({
name: 'user',
fields: { name: Field.string(), age: Field.number() },
schemafull: true,
}) {}

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.

TIn extends FieldDefinition<unknown>

FieldDefinition for the ‘in’ endpoint (source node).

TOut extends FieldDefinition<unknown>

FieldDefinition for the ‘out’ endpoint (target node).

TOther extends Record<string, FieldDefinition<unknown>> = Record<string, never>

Additional fields for the relation (optional).

RelationTableOptions<TIn, TOut, TOther>

Relation table options including name, fields (must include ‘in’ and ‘out’), etc.

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.

const Authored = Table.relation({
name: 'authored',
fields: {
in: Field.record(() => User),
out: Field.record(() => Post),
since: Field.datetime(),
},
});