Skip to main content

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.

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.

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.
[ Application Logic ]


[ Repository Interface ] (createOne, searchMany, etc.)


[ Middleware Pipeline ] (Execution Context, RBAC, Custom Plugins)


[ Executor Engine ] (single-executor, batch-executor)
        │ (Uses Query Parser for AST compilation)

[ Drizzle ORM ] -> [ Database Engine ]
Each layer has a single responsibility. The Repository Interface exposes strongly-typed methods that match your schema. The Middleware Pipeline intercepts every request, runs RBAC checks, emits telemetry events, and calls any custom plugins you register. The Executor Engine translates the parsed JSON AST into a concrete Drizzle query and handles dialect-specific differences. This separation means you can add cross-cutting concerns — logging, caching, rate-limiting — without modifying any business logic.

Technology stack

ConcernLibrary
LanguageTypeScript 5+
RuntimeBun 1.0+ or Node.js
ORMDrizzle ORM 0.30+
LoggingPino
Event busMitt
Validation / typingZod
TestingBun 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.

Build docs developers (and LLMs) love