Skip to content

Capabilities

💎 FeatureWhat it gives you
Schema-only modeGenerate SurrealQL with generateFullSchemaQl() without touching the database—perfect for migrations & CI.
Embedded testingRun SurrealDB fully in-process via @surrealdb/node engines (mem://) for ultra-fast unit tests.
Parameterized queries (vars)Prevent injection; supported in select, count, query, etc.
Type-safe fetch projectionAutomatic hydration of related records (Field.record) with full TypeScript types.
Circular dependency thunkUse Field.record(() => OtherTable) to avoid import cycles while keeping types.
Advanced data typesFull, type-safe support for bytes, duration, uuid, decimal, and specific geometry types.
Custom Surreal typesDefine `Field.custom<‘left'

FeatureSurrealDB Syntax Exampleunreal-orm SupportNotes
Basic Table DefinitionDEFINE TABLE user;Supportedclass User extends Table.normal({ name: 'user', ... })
IF NOT EXISTSDEFINE TABLE user IF NOT EXISTS;SupportedTable.normal({ ..., method: 'IF NOT EXISTS' })
OVERWRITEDEFINE TABLE user OVERWRITE;SupportedTable.normal({ ..., method: 'OVERWRITE' })
SCHEMAFULLDEFINE TABLE user SCHEMAFULL;SupportedTable.normal({ ..., schemafull: true }) is the standard.
SCHEMALESSDEFINE TABLE user SCHEMALESS;SupportedTable.normal({ ..., schemafull: false })
TYPE NORMALDEFINE TABLE user TYPE NORMAL;SupportedThis is the default for Table.normal.
TYPE ANYDEFINE TABLE user TYPE ANY;SupportedNot directly supported, use schemafull: false.
TYPE RELATION IN ... OUT ...DEFINE TABLE likes TYPE RELATION IN user OUT post;SupportedUse Table.relation({ fields: { in: Field.record(...), out: 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;SupportedIndex.define(() => User, { fields: ['email'], unique: true })
SEARCH ANALYZER (Full-Text Search)DEFINE INDEX ... SEARCH ANALYZER ... BM25 HIGHLIGHTS;SupportedUse the analyzer option in Index.define. Other keywords like BM25 are not exposed.
Vector Index (MTREE, HNSW)DEFINE INDEX ... MTREE DIMENSION ...;Not Supported
COMMENT @stringDEFINE INDEX user_email ON user ... COMMENT '...';SupportedUse the comment option in Index.define.
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';
class User extends Table.normal({
name: 'user',
schemafull: true,
fields: {
name: Field.string({ assert: '$value.length > 2' }),
age: Field.number({ assert: '$value >= 0', default: 0 }),
isActive: Field.bool({ default: true }),
createdAt: Field.datetime({ default: () => new Date() }),
profile: Field.object({
bio: Field.string(),
website: Field.option(Field.string()),
}),
tags: Field.array(Field.string(), { max: 10 }),
posts: Field.array(Field.record(() => Post)),
nickname: Field.option(Field.string()),
// Advanced Types
balance: Field.decimal(),
apiKey: Field.uuid(),
lastLogin: Field.duration(),
avatar: Field.bytes(),
location: Field.geometry('point'),
side: Field.custom<'left' | 'right'>('"left" | "right"'),
},
}) {}
// Define indexes separately
const UserNameIndex = Index.define(() => User, {
name: 'user_name_idx',
fields: ['name'],
unique: true,
});