ORM, but better
Drizzle ORM, but better
npm install better-drizzle drizzle-ormpoint lookups
nested relation reads and writes
pagination payloads
existence checks
count helpers
CRUD return shapes
nested where filters
Less repeated query code for common CRUD flows
Nested relation filters with Drizzle-backed typing
Batched nested include and select with typed payload inference
Atomic connect, disconnect, and set relation writes
Direct and inferred many-to-many relations through simple junction tables
Offset and cursor pagination helpers with typed metadata
Thenable .explain() on read helpers for query-plan inspection
Optional lifecycle hooks for cross-cutting behavior
First-class plugins with setup, transforms, and client/model extensions
Fast paths for simple reads and writes to reduce wrapper overhead
Consistent table delegates: findMany, findFirst, create, update, updateEach, delete, paginate, cursor, count, exists, upsert, upsertMany
Querying your database with Better client
…_count uses correlated SQL subqueries, so relation counts do not add a query per row or a separate count round-trip.
const exists = await client.users.exists({
where: { id: 123 },
});
const count = await client.users.count({
where: {
name: { contains: 'drizzle-orm' },
},
});
const plan = await client.users
.findMany({
where: { active: true },
orderBy: [{ id: 'asc' }],
})
.explain({
analyze: true,
comment: 'users.active.explain',
});.explain() is available on read helpers (findMany, findFirst, findOne, findUnique, count, exists, paginate, cursor). PostgreSQL returns the richest output, while MySQL and SQLite ignore unsupported explain options and return the plan shape their drivers support.
…const { count } = await client.users.delete({
where: eq(users.id, 123),
});const users = client.repository('users');const user = await client.transaction(async (tx) => {
const created = await tx.users.create({
data: {
email: '[email protected]',
id: 123,
name: 'better',
},
});
tx.afterCommit(async () => {
await sendWelcomeEmail(created.email);
});
return created;
});On PostgreSQL and MySQL, read helpers also accept lock for row-level locking:
await client.transaction(async (tx) => {
const jobs = await tx.posts.findMany({
where: { id: { gt: 0 } },
lock: {
mode: 'update',
skipLocked: true,
},
});
return jobs;
});If you want to enforce that locked reads only happen inside transactions, enable it once on the client:
const client = better(db, {
schema,
locks: {
transactionsOnly: true,
},
});…const client = better(drizzle, {
schema,
hooks: {
beforeCreate({ data: user }) {
user.organizationId = randomUUID();
},
},
});meta can still be passed per call, but you can now scope default metadata once on the client with $withContext(...). Scoped values are merged into repository calls, raw SQL hooks, and transaction hooks, and per-call meta overrides matching keys.
type RequestMeta = {
organizationId?: string;
requestId?: string;
userId?: string;
};
const client = better(drizzle, { schema });
const scoped = client.$withContext({
organizationId: 'org_123',
requestId: 'req_123',
});
await scoped.users.create({
data: { name: 'Alice' },
meta: { requestId: 'req_456', userId: 'user_7' },
});SKILL.md plus task-specific files in references/AGENTS.md for repo context, CLAUDE.md and GEMINI.md as thin adapters, and the skill pack as the canonical workflow layerSee the website AI page for installation notes, supported agent surfaces, and the security model: https://better-drizzle.com/docs/ai
No open issues yet, or sync has not completed.