@virohuman1/light-orm
v1.0.0
Published
A lightweight, fully-typed TypeScript ORM for serverless Postgres (Neon, Supabase). Schema definitions, an inferred typed query builder, CRUD, filtering, transactions, migrations and a fluent API — no code generation.
Maintainers
Readme
@virohuman1/light-orm
A lightweight, fully-typed TypeScript ORM for serverless Postgres (Neon, Supabase). No code generation, no heavy runtime — just a clean schema layer, an inferred typed query builder, and a small client on top of the pg driver.
npm install @virohuman1/light-orm pgQuick start
import { defineModel, number, string, boolean, timestamp, createDb } from "@virohuman1/light-orm";
const Todo = defineModel("todos", {
id: number().primaryKey(),
title: string().notNull(),
completed: boolean().notNull().default(false),
createdAt: timestamp().default("now()"),
});
const db = createDb({ connectionString: process.env.DATABASE_URL! }, { todos: Todo });
await db.$migrate(); // create tables if they don't exist
const todo = await db.todos.create({ title: "Finish assignment" });
// ^? { id: number; title: string; completed: boolean; createdAt: string }
await db.todos.findMany({ where: { completed: false } });
await db.todos.update(todo.id, { completed: true });
await db.todos.delete(todo.id);Type safety
Everything is inferred from the schema — invalid fields are compile errors:
db.todos.create({ titel: "typo" }); // ✗ TS error: unknown property 'titel'
db.todos.findMany({ where: { nope: true } }); // ✗ TS error: unknown property 'nope'
const t = await db.todos.create({ title: "x" });
t.completed; // ✓ typed as booleanFeatures
- Typed CRUD:
create/findMany/findFirst/findById/update/delete/count - Rich where operators:
equals,not,in,gt/gte/lt/lte,like,contains - Fluent chaining:
db.todos.query().where({...}).orderBy("id","desc").limit(10).all() - Transactions:
db.$transaction(async (tx) => { ... }) - Migrations:
db.$migrate()(idempotent CREATE TABLE) +light-orm generateCLI - Basic relations:
belongsTo/hasManyviainclude - Runtime validation layer + typed errors (
ValidationError,RecordNotFoundError) - Parameterized queries everywhere — no SQL injection surface
CLI
light-orm generate ./dist/models.js > schema.sqlSee the repository ARCHITECTURE.md for the full design and known limitations.
