Table
constTable:object
Defined in: define/table/index.ts:41
A factory object for creating table model definitions.
Type Declaration
Section titled “Type Declaration”normal()
Section titled “normal()”
readonlynormal<TFields>(options):ModelStatic<ModelInstance<InferShapeFromFields<TFields>>,TFields,TableDefineOptions<TFields>>
Defines a standard (NORMAL) table model.
Returns a base class that should be extended to create your final model.
Type Parameters
Section titled “Type Parameters”TFields
Section titled “TFields”TFields extends Record<string, FieldDefinition<unknown>>
Parameters
Section titled “Parameters”options
Section titled “options”NormalTableOptions<TFields>
Configuration for the normal table.
Returns
Section titled “Returns”ModelStatic<ModelInstance<InferShapeFromFields<TFields>>, TFields, TableDefineOptions<TFields>>
A base model class to be extended.
Example
Section titled “Example”import Table, { Field } from 'unreal-orm';
class User extends Table.normal({ name: 'user', schemafull: true, fields: { name: Field.string(), email: Field.string({ assert: surql`$value CONTAINS "@"` }), createdAt: Field.datetime({ default: surql`time::now()` }), },}) { // Custom methods are defined directly in the class body getDisplayName() { return `${this.name} <${this.email}>`; }}relation()
Section titled “relation()”
readonlyrelation<TIn,TOut,TOther>(options):ModelStatic<ModelInstance<InferShapeFromFields<RelationTableFields<TIn,TOut,TOther>>>,RelationTableFields<TIn,TOut,TOther>,TableDefineOptions<RelationTableFields<TIn,TOut,TOther>>>
Defines a relation (RELATION) table model, also known as an edge.
Returns a base class that should be extended.
Type Parameters
Section titled “Type Parameters”TIn extends FieldDefinition<unknown>
TOut extends FieldDefinition<unknown>
TOther
Section titled “TOther”TOther extends Record<string, FieldDefinition<unknown>> = Record<string, never>
Parameters
Section titled “Parameters”options
Section titled “options”RelationTableOptions<TIn, TOut, TOther>
Configuration for the relation table.
Returns
Section titled “Returns”ModelStatic<ModelInstance<InferShapeFromFields<RelationTableFields<TIn, TOut, TOther>>>, RelationTableFields<TIn, TOut, TOther>, TableDefineOptions<RelationTableFields<TIn, TOut, TOther>>>
A base model class to be extended.
Example
Section titled “Example”import Table, { Field } from 'unreal-orm';
// Assumes User and Post models are already defined.class Likes extends Table.relation({ name: 'likes', schemafull: true, fields: { in: Field.record(() => User), out: Field.record(() => Post), timestamp: Field.datetime({ default: surql`new datetime()` }), },}) {}view()
Section titled “view()”
readonlyview<TResult>(options):ModelStatic<ViewInstance,Record<string,never>,TableDefineOptions<Record<string,never>>>
Defines a pre-computed table view (DEFINE TABLE ... AS SELECT ...).
Returns a base class that should be extended.
Type Parameters
Section titled “Type Parameters”TResult
Section titled “TResult”TResult extends Record<string, unknown> = Record<string, unknown>
Parameters
Section titled “Parameters”options
Section titled “options”ViewTableOptions
Configuration for the view table.
Returns
Section titled “Returns”ModelStatic<ViewInstance, Record<string, never>, TableDefineOptions<Record<string, never>>>
A base model class to be extended.
Example
Section titled “Example”import { Table } from 'unreal-orm';import { surql } from 'surrealdb';
type AdultUser = { name: string; age: number };
class AdultUsers extends Table.view<AdultUser>({ name: 'adult_users', as: surql`SELECT name, age FROM user WHERE age >= 18`,}) {}