You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Zen is the missing link between SQL and typed data. By writing tables with Zod schema, you get idempotent migration helpers, typed CRUD, normalized object references, and many features other database clients cannot provide.
116
116
117
117
### What Zen is not:
118
-
-**Zen is not a query builder** — Rather than fluent query building `.where().orderBy().limit()` chains, you write SQL directly: `` db.all(Posts)`WHERE published = ${true} ORDER BY created_at DESC LIMIT 20` ``
119
-
-**Zen is not an ORM** — Tables are not classes, they are Zod-powered singletons which provide schema-aware SQL-fragment helpers. These tables can be passed to CRUD helpers to validate writes, generate DDL, and normalize joined data into an object graph.
118
+
-**Zen is not a query builder** — Rather than building SQL with fluent chains `.where().orderBy().limit()`, you write it directly with templates: `` db.all(Posts)`WHERE published = ${true} ORDER BY created_at DESC LIMIT 20` `` Helper functions help you write the tedious parts of SQL without hiding it or limiting your queries.
119
+
-**Zen is not an ORM** — Tables are not classes. They are Zod-powered singletons which provide schema-aware utilities. These tables can be used to validate writes, generate DDL, and deduplicate joined data.
120
120
-**Zen is not a startup** — Zen is an open-source library, not a venture-backed SaaS. There will never be a managed “ZenDB” instance or a “Zen Studio.” The library is a thin wrapper around Zod and JavaScript SQL drivers, with a focus on runtime abstractions rather than complicated tooling.
121
121
122
122
### Safety
@@ -127,9 +127,6 @@ Zen is the missing link between SQL and typed data. By writing tables with Zod s
127
127
-**No destructive helpers** — No `dropColumn()`, `dropTable()`, `renameColumn()`
128
128
-**No automatic migrations** — Schema changes are explicit in upgrade events
129
129
130
-
Migrations are **additive and idempotent** by design. Use `ensureColumn()`, `ensureIndex()`, `copyColumn()` for safe schema evolution. Breaking changes require multi-step migrations. Rollbacks are new forward migrations.
131
-
132
-
133
130
## Table Definitions
134
131
135
132
```typescript
@@ -491,6 +488,29 @@ await db.exec`CREATE INDEX idx_posts_author ON ${Posts}(${Posts.cols.authorId})`
491
488
const count =awaitdb.val<number>`SELECT COUNT(*) FROM ${Posts}`;
492
489
```
493
490
491
+
## CRUD Helpers
492
+
```typescript
493
+
// Insert with Zod validation (uses RETURNING to get actual row)
**RETURNING support:**`insert()` and `update()` use `RETURNING *` on SQLite and PostgreSQL to return the actual row from the database, including DB-computed defaults and triggers. MySQL falls back to a separate SELECT.
512
+
513
+
494
514
## Fragment Helpers
495
515
496
516
Type-safe SQL fragments as methods on Table objects:
**RETURNING support:**`insert()` and `update()` use `RETURNING *` on SQLite and PostgreSQL to return the actual row from the database, including DB-computed defaults and triggers. MySQL falls back to a separate SELECT.
0 commit comments