Configurable audit logging for Drizzle ORM (v0.1.12). Provides automatic CRUD audit interception, custom action logging, scoped tracking with duration, and field-level transforms (redact, mask, hash, omit). Supports PostgreSQL, SQLite, and MySQL with pluggable storage (same DB, external DB, webhook, MongoDB). Integrates with frameworks (Hono, Elysia, Express, etc.) and workers (BullMQ, Temporal). Features AsyncLocalStorage context propagation, transaction awareness, and skip-on-noop. Zero-config start, progressive enhancement, and strict TypeScript. Active development with weekly releases.
npm install drizzle-auditNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Wrap a PostgreSQL Drizzle instance with audit logging using drizzleTableStorage, enabling automatic CRUD audit and custom actions.
Add .returning() to all DML operations you want audited. For MySQL (no RETURNING), use db.$audit.action() manually.
Use manual audit entries via db.$audit.action() after each DML operation. See examples/express-mysql-sqlite for a pattern.
Use withAuditContext(context) helper or framework middlewares to set context per request/worker.
Always include `auditTable: auditLog` in the config passed to withDrizzleAudit.
If per-statement auditing is required inside transactions, use manual db.$audit.action() calls instead of relying on automatic interception.
Ensure drizzle-orm >= 0.33.0 is installed: npm install drizzle-orm@latest
Wrap your drizzle instance: const db = withDrizzleAudit(rawDb, config);
Add `auditTable: myAuditTable` to the config object.
Use ESM imports (import) and ensure your bundler supports Node.js subpath exports, or use a full path like './node_modules/drizzle-audit/storage/drizzle.js'.