Skip to content
🚀 This documentation is for unreal-orm 1.0.0 alpha which requires SurrealDB 2.0 alpha SDK. For the stable version, see npm.

Table

const Table: object

Defined in: define/table/index.ts:41

A factory object for creating table model definitions.

readonly normal<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.

TFields extends Record<string, FieldDefinition<unknown>>

NormalTableOptions<TFields>

Configuration for the normal table.

ModelStatic<ModelInstance<InferShapeFromFields<TFields>>, TFields, TableDefineOptions<TFields>>

A base model class to be extended.

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}>`;
}
}

readonly relation<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.

TIn extends FieldDefinition<unknown>

TOut extends FieldDefinition<unknown>

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

RelationTableOptions<TIn, TOut, TOther>

Configuration for the relation table.

ModelStatic<ModelInstance<InferShapeFromFields<RelationTableFields<TIn, TOut, TOther>>>, RelationTableFields<TIn, TOut, TOther>, TableDefineOptions<RelationTableFields<TIn, TOut, TOther>>>

A base model class to be extended.

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()` }),
},
}) {}

readonly view<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.

TResult extends Record<string, unknown> = Record<string, unknown>

ViewTableOptions

Configuration for the view table.

ModelStatic<ViewInstance, Record<string, never>, TableDefineOptions<Record<string, never>>>

A base model class to be extended.

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`,
}) {}