百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
better-drizzle

better-drizzle

> 数据库
免费

不是 ORM,但更好

305 stars0 点赞4 次浏览
访问官网GitHub

工具介绍

不是 ORM,但更好

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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

betterdatabasedrizzle

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年9月9日
最后更新2026年9月18日
分类数据库
定价免费

> 相关工具

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