Drizzle Castor is a type-safe CRUD library and Data Access Object (DAO) abstraction built on top of Drizzle ORM. It eliminates the repetitive boilerplate of writing raw Drizzle queries by providing a JSON-based querying syntax, an extensible middleware pipeline, unified Role-Based Access Control (RBAC), and multi-dialect execution strategies — all with full TypeScript inference from your existing Drizzle schema.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/fajarnugraha37/drizzle-castor/llms.txt
Use this file to discover all available pages before exploring further.
Key features
JSON-based querying
Filter, sort, and project relational data using intuitive JSON payloads. The AST translator compiles them into safe, optimised SQL at runtime.
Unified RBAC engine
Built-in middleware-driven Role-Based Access Control. Enforce action-level and field-level security with declarative static maps or asynchronous policy callbacks.
Middleware pipeline
Adopts the Koa-style onion model for absolute control flow (
await next()) on every repository request. Compose custom plugins with ease.Event-driven telemetry
Integrated event bus powered by
mitt. Emits structured, non-blocking events for execution performance, security audits, and data mutations.Hybrid logging
Quarkus-style pattern-based logging powered by
pino. Supports context injection (traceId, parameters) and nested object traversal in log patterns.Dialect agnostic
Supports PostgreSQL, MySQL, and SQLite. Handles dialect-specific logic such as
RETURNING clauses versus temporary tables for atomic mutations.Native soft deletes
Declarative soft-delete capabilities that implicitly apply safety filters to every query and join — no manual
WHERE deleted_flag = 0 required.Safe pagination
Leverages Common Table Expressions (CTEs) to prevent Cartesian fan-out when paginating one-to-many or many-to-many relationships.
Architecture overview
Drizzle Castor implements a middleware-driven repository pattern that functions as an Abstract Syntax Tree (AST) transpiler. Every call to a repository method travels through a layered pipeline before reaching Drizzle ORM and your database.Technology stack
| Concern | Library |
|---|---|
| Language | TypeScript 5+ |
| Runtime | Bun 1.0+ or Node.js |
| ORM | Drizzle ORM 0.30+ |
| Logging | Pino |
| Event bus | Mitt |
| Validation / typing | Zod |
| Testing | Bun Test, Node Test Runner, Testcontainers |
Next steps
Quickstart
Install Drizzle Castor and run your first type-safe query in under five minutes.
Installation
Full installation options including npm, JSR, and peer dependency requirements.
Schema builder
Learn how to configure tables, relations, and soft deletes with createSchemaBuilder.
Repositories
Explore every repository method and understand the hydrated return format.
Access control
Understand profiles, policies, and field-level data trimming.
Middleware pipeline
Compose Koa-style middlewares and subscribe to telemetry events.