Table
const
Table:object
Defined in: define/table/index.ts:39
A factory object for creating table model definitions.
Type declaration
Section titled “Type declaration”normal()
Section titled “normal()”
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.
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: '$value CONTAINS "@"' }), createdAt: Field.datetime({ default: () => new Date() }), },}) { // Custom methods are defined directly in the class body getDisplayName() { return `${this.name} <${this.email}>`; }}
relation()
Section titled “relation()”
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.
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: () => new Date() }), },}) {}