cerial
v0.1.0
Published
A Prisma-like ORM for SurrealDB with schema-driven code generation and full TypeScript type safety
Downloads
103
Maintainers
Readme
Cerial
A Prisma-like ORM for SurrealDB with schema-driven code generation and full TypeScript type safety.
Features
- Schema-first design with
.cerialfiles - 15 field types: String, Int, Float, Bool, Date, Email, Uuid, Duration, Decimal, Bytes, Geometry, Number, Any, Record, Relation
- Embedded objects, tuples, literals, and enums
- Full relation support (1:1, 1:N, N:N) with nested create, connect, and disconnect
- Complete CRUD query API with type-safe select and include
- Rich filtering: comparison, string, array, logical, and existence operators
- Transactions in three modes: array, callback, and manual
- Schema inheritance with
extends,abstractmodels, and pick/omit - Auto-generated TypeScript types with dynamic return types
- CLI with generate, init, format commands and watch mode
- Auto-migration generation (DEFINE TABLE/FIELD/INDEX)
- Clean NONE vs null separation (
?for optional,@nullablefor null) - Typed record IDs with automatic FK type inference
Installation
npm install cerial # or: pnpm add cerial / yarn add cerial / bun add cerialQuick Start
1. Define your schema in a .cerial file:
model User {
id Record @id
email Email @unique
name String
age Int?
}2. Generate the client:
npx cerial generate -s ./schemas -o ./db-client3. Query with full type safety:
import { CerialClient } from './db-client';
const client = new CerialClient();
await client.connect({ url: 'http://localhost:8000', namespace: 'main', database: 'main' });
const users = await client.User.findMany({
where: { age: { gte: 18 } },
select: { id: true, name: true, email: true },
});Links
License
Apache 2.0
