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.
✨ Features
Section titled “✨ Features”Reference Fields (Experimental)
Section titled “Reference Fields (Experimental)”- Added
referenceoption toRecordFieldOptions: You can now mark a record link as aREFERENCE. - Support for
ON DELETEactions: 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" } });Table Views
Section titled “Table Views”- Added
Table.view()method: Define pre-computed table views usingDEFINE TABLE ... AS SELECT .... - Support for
ASclause: 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",}) {}🛠️ Internals
Section titled “🛠️ Internals”DDL Generation
Section titled “DDL Generation”- Updated DDL generators:
generateFieldsDdl: AddsREFERENCEandON DELETEclauses.generateTableDdl: AddsTYPE VIEW(handled as normal tables withASclause) and theASquery string.
Testing
Section titled “Testing”- Enabled experimental capabilities: Updated test database setup to allow experimental features for testing
REFERENCEfields.