Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
better-drizzle

better-drizzle

> 数据库
Free

ORM, but better

305 stars0 likes4 views
WebsiteGitHub

About

ORM, but better

Drizzle ORM, but better

bash
npm install better-drizzle drizzle-orm
  • point 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.

typescript
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.

…
typescript
const { count } = await client.users.delete({
	where: eq(users.id, 123),
});
typescript
const users = client.repository('users');
typescript
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:

typescript
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:

typescript
const client = better(db, {
	schema,
	locks: {
		transactionsOnly: true,
	},
});
…
typescript
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.

typescript
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' },
});
  • Canonical skill format: SKILL.md plus task-specific files in references/
  • Multi-agent support: AGENTS.md for repo context, CLAUDE.md and GEMINI.md as thin adapters, and the skill pack as the canonical workflow layer
  • Scope: querying, writes, transactions, plugins, performance-sensitive changes, and review-time checks for API correctness
  • Security posture: zero scripts, zero network, no secret-reading instructions, and explicit prompt-injection resistance guidance

See the website AI page for installation notes, supported agent surfaces, and the security model: https://better-drizzle.com/docs/ai

Issues· 5 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

betterdatabasedrizzle

No comments yet. Be the first to share.

> Details

PublishedSep 9, 2026
UpdatedSep 18, 2026
Category数据库
PricingFree

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库