better-drizzle
A type-safe repository layer for Drizzle ORM.
Most Drizzle projects end up writing the same wrapper layer, one function per table, one per join, one per pagination pattern. better-drizzle ships that layer already typed and tested. Install it alongside Drizzle:
bun add better-drizzle drizzle-ormWrap your Drizzle client once. Every table gets findMany, findFirst, create, update, upsert, paginate, cursor, exists, and count, all with full type inference from your schema, no codegen required:
const posts = await client.posts.findMany({
where: { published: true, author: { is: { active: true } } },
include: { author: true },
orderBy: [{ id: 'desc' }],
take: 20,
});Relation writes work in the same call as data updates: connect, disconnect, and set map directly to the relation in your schema:
const user = await client.users.create({ data: { id: 123, name: 'better' } });
await client.users.update({
data: { name: 'better-drizzle', posts: { connect: { id: 456 } } },
where: { id: 123 },
});Pagination is built in, with typed metadata for both offset and cursor strategies:
const { data, meta } = await client.posts.paginate({
where: { published: true },
page: 1,
perPage: 25,
});
// meta → { total, page, perPage, lastPage }Context#
Drizzle gives you type safety and SQL you can read. What it does not give you is the layer every team writes anyway: repository functions per table, pagination, relation loading, the hook someone forgets to call. That layer gets rewritten in every project, slightly differently each time, and it is where the bugs live.
Approach#
better-drizzle wraps the client you already have and gives every table reads, writes, relation loading, pagination, hooks and plugins: with types inferred straight from your schema, so nothing is declared twice and nothing drifts. The raw Drizzle client stays one property away, which means the library never becomes the reason you cannot write the query you need.
Engineering decisions#
- Types are inferred from the schema instead of declared next to it, a column rename breaks the build, not production.
- The escape hatch is a first-class feature: the underlying client is always exposed, so no query is ever unreachable.
- Hooks and plugins carry the extensions, which keeps the core API small enough to learn in one sitting.
- Benchmarks live in the repository, because a wrapper that costs performance is a wrapper nobody keeps.
Outcome#
The repetitive query glue disappears from the codebase without giving up type safety or control. The project has 395 stars on GitHub and is used by teams that wanted Drizzle without writing the same repository layer for the fifth time.