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.

v1.0.0-alpha.2

This alpha release introduces support for SurrealDB’s experimental REFERENCE fields and pre-computed table views, along with DDL generation updates.

  • Added reference option to RecordFieldOptions: You can now mark a record link as a REFERENCE.
  • Support for ON DELETE actions: Configure behavior when the referenced record is deleted (IGNORE, UNSET, CASCADE, REJECT).
import { Field } from "unreal-orm";
const Comment = Field.record(
() => User,
{
// Simple reference
reference: true,
// Or with specific options
reference: {
onDelete: "CASCADE"
}
}
);
  • Added Table.view() method: Define pre-computed table views using DEFINE TABLE ... AS SELECT ....
  • Support for AS clause: Views are defined by a query that is executed to populate the table.
import { Table } from "unreal-orm";
import { surql } from "surrealdb";
class AdultUsers extends Table.view({
name: "adult_users",
as: surql`SELECT * FROM user WHERE age >= 18`,
}) {}

You can also provide a TypeScript type to Table.view to infer the shape of the view:

type AdultUser = { name: string; age: number };
class AdultUsers extends Table.view<AdultUser>({
name: "adult_users",
as: "SELECT name, age FROM user WHERE age >= 18",
}) {}
  • Updated DDL generators:
    • generateFieldsDdl: Adds REFERENCE and ON DELETE clauses.
    • generateTableDdl: Adds TYPE VIEW (handled as normal tables with AS clause) and the AS query string.
  • Enabled experimental capabilities: Updated test database setup to allow experimental features for testing REFERENCE fields.