Skip to content

Capabilities

FeatureSurrealDB Syntax Exampleunreal-orm SupportNotes
Basic Table DefinitionDEFINE TABLE user;SupportedTable.define({ name: 'user', ... })
IF NOT EXISTSDEFINE TABLE user IF NOT EXISTS;SupportedTable.define({ ..., method: 'IF NOT EXISTS' })
OVERWRITEDEFINE TABLE user OVERWRITE;SupportedTable.define({ ..., method: 'OVERWRITE' })
SCHEMAFULLDEFINE TABLE user SCHEMAFULL;SupportedTable.define({ ..., schemafull: true }) or implicit if fields defined & no other type.
SCHEMALESSDEFINE TABLE user SCHEMALESS;SupportedTable.define({ ..., type: 'schemaless' })
TYPE NORMALDEFINE TABLE user TYPE NORMAL;SupportedTable.define({ ..., type: 'normal' })
TYPE ANYDEFINE TABLE user TYPE ANY;SupportedTable.define({ ..., type: 'any' })
TYPE RELATION IN ... OUT ...DEFINE TABLE likes TYPE RELATION IN user OUT post;⚠️ PartiallyNo direct type: 'relation' option. Define in/out fields as Field.record(). ENFORCED not supported.
ENFORCED (for TYPE RELATION)DEFINE TABLE likes TYPE RELATION ... ENFORCED;Not SupportedTied to full TYPE RELATION syntax.
Table View (AS SELECT ...)DEFINE TABLE user_view AS SELECT ... FROM user;Not Supported
CHANGEFEED @duration [INCLUDE ORIGINAL]DEFINE TABLE user CHANGEFEED 1h;Not Supported
PERMISSIONS (Table-level)DEFINE TABLE user PERMISSIONS FOR select WHERE ...;SupportedTable.define({ ..., permissions: { select: '...' } })
COMMENT @stringDEFINE TABLE user COMMENT 'User accounts';SupportedTable.define({ ..., comment: '...' })
DROP (within DEFINE TABLE)DEFINE TABLE user DROP;Not SupportedREMOVE TABLE is a separate operation, not part of Table.define.
FeatureSurrealDB Syntax Exampleunreal-orm SupportNotes
Basic Field DefinitionDEFINE FIELD email ON user;SupportedVia fields object in Table.define({ fields: { email: Field.string() } }).
IF NOT EXISTS (Field-level)DEFINE FIELD email ON user IF NOT EXISTS;Not SupportedORM regenerates the whole schema.
OVERWRITE (Field-level)DEFINE FIELD email ON user OVERWRITE;Not SupportedORM regenerates the whole schema.
TYPE @type (various types)DEFINE FIELD age ON user TYPE number;⚠️ PartiallySee “Data Type Support” section below for detailed coverage.
FLEXIBLE TYPE @typeDEFINE FIELD meta ON user FLEXIBLE TYPE object;SupportedUse { flexible: true } with Field.object() or Field.custom(). Enables flexible schemas for object/custom fields.
DEFAULT @expressionDEFINE FIELD role ON user TYPE string DEFAULT 'guest';SupportedField.string({ default: 'guest' }). Handles primitives, time::now(), functions.
DEFAULT ALWAYS @expressionDEFINE FIELD updated_at ON user TYPE datetime DEFAULT ALWAYS time::now();Not SupportedOnly standard DEFAULT is supported.
VALUE @expressionDEFINE FIELD created_at ON user VALUE time::now();SupportedField.string({ value: 'time::now()' }) or e.g. Field.string({ value: 'string::lowercase($value)' })
VALUE <future> { @expression }DEFINE FIELD last_accessed ON user VALUE <future> { time::now() };Not SupportedOnly standard VALUE is supported, not VALUE .
ASSERT @expressionDEFINE FIELD email ON user ASSERT string::is::email($value);SupportedField.string({ assert: 'string::is::email($value)' })
READONLYDEFINE FIELD id ON user READONLY;SupportedField.string({ readonly: true })
PERMISSIONS (Field-level)DEFINE FIELD email ON user PERMISSIONS FOR select WHERE...;SupportedField.string({ permissions: { ... } })
COMMENT @stringDEFINE FIELD email ON user COMMENT 'User email';SupportedField.string({ comment: '...' })
REFERENCE (with ON DELETE actions)DEFINE FIELD author ON post TYPE record<user> REFERENCE ON DELETE CASCADE;Not Supported
Define type for id fieldDEFINE FIELD id ON user TYPE string;SupportedTable.define({ fields: { id: Field.custom({ type: 'string' }) } })
Define types for specific array indicesDEFINE FIELD data[0] ON mytable TYPE string;Not SupportedField.array(Field.string()) defines type for all items.
FeatureSurrealDB Syntax Exampleunreal-orm SupportNotes
Basic Index DefinitionDEFINE INDEX user_email ON user COLUMNS email;SupportedTable.define({ indexes: { user_email: { fields: ['email'] } } })
IF NOT EXISTS (Index-level)DEFINE INDEX user_email ON user IF NOT EXISTS ...;Not SupportedORM regenerates the whole schema.
OVERWRITE (Index-level)DEFINE INDEX user_email ON user OVERWRITE ...;Not SupportedORM regenerates the whole schema.
UNIQUE IndexDEFINE INDEX user_email ON user COLUMNS email UNIQUE;SupportedTable.define({ indexes: { user_email: { fields: ['email'], unique: true } } })
SEARCH ANALYZER (Full-Text Search)DEFINE INDEX ... SEARCH ANALYZER ... BM25 HIGHLIGHTS;⚠️ PartiallyBasic index definition is supported. Specific FTS keywords (SEARCH ANALYZER, BM25) require manual setup or are not exposed.
Vector Index (MTREE, HNSW)DEFINE INDEX ... MTREE DIMENSION ...;Not Supported
COMMENT @stringDEFINE INDEX user_email ON user ... COMMENT '...';SupportedTable.define({ indexes: { user_email: { ..., comment: '...' } } })
CONCURRENTLYDEFINE INDEX user_email ON user ... CONCURRENTLY;Not Supported

unreal-orm primarily focuses on schema generation for tables, fields, and indexes. Other DEFINE statements are not yet supported by the ORM.

FeatureSurrealDB Syntax Exampleunreal-orm SupportNotes
DEFINE NAMESPACEDEFINE NAMESPACE test;Not SupportedOperates within a given DB/NS connection.
DEFINE DATABASEDEFINE DATABASE test;Not Supported
DEFINE USERDEFINE USER ...;Not Supported
DEFINE TOKENDEFINE TOKEN ...;Not Supported
DEFINE SCOPEDEFINE SCOPE ...;Not Supported
DEFINE ANALYZERDEFINE ANALYZER ...;Not Supported
DEFINE EVENTDEFINE EVENT ... ON TABLE ...;Not Supported
DEFINE FUNCTIONDEFINE FUNCTION fn::abc() ...;Not Supported
DEFINE PARAMDEFINE PARAM $myparam ...;Not Supported
import { Table, Field } from 'unreal-orm';
const User = Table.define({
name: 'user',
fields: {
name: Field.string({ assert: '$value.length > 2', comment: 'User name' }),
age: Field.number({ assert: '$value >= 0', default: '0' }),
isActive: Field.bool({ default: 'true' }),
createdAt: Field.datetime({ default: 'time::now()' }),
profile: Field.object({
bio: Field.string(),
website: Field.option(Field.string()),
}),
tags: Field.array(Field.string(), { max: 10 }),
posts: Field.array(Field.record((): any => Post), { max: 100 }),
author: Field.record((): any => User),
nickname: Field.option(Field.string()),
customField: Field.custom<number>('duration'),
},
indexes: [
{ name: 'user_name_idx', fields: ['name'], unique: true },
],
``}]},{