Getting Started
Database Drivers
Schema Integrations
Seed Generators
Utilities and Testing
The following files were used as context for generating this wiki page:
The eslint-plugin-drizzle package is a specialized linting utility designed to enforce safety patterns within Drizzle ORM query construction. Its primary purpose is to prevent common, high-risk development mistakes, specifically those involving destructive database operations that lack necessary filtering criteria.
At its architectural core, the plugin functions as a structural validator of the Drizzle fluent API surface. By inspecting the Abstract Syntax Tree (AST) of Drizzle queries, it identifies instances where delete() or update() methods are invoked without a subsequent .where() clause. Executing these operations on entire tables is a frequent source of data loss or corruption, and this plugin serves as a compile-time (or development-time) guard to catch these patterns before they reach a production environment.
The plugin provides curated configuration presets that teams can adopt to ensure a baseline level of query safety. By integrating these rules into standard ESLint workflows, it ensures that developers follow the prescribed, safer patterns—such as chaining the .where() clause to every destructive statement—without requiring manual review for every query implementation.
The plugin centers on two exported rule modules: the default export from enforce-delete-with-where.ts and the default export from enforce-update-with-where.ts. These rules operate by monitoring the structure of MemberExpression nodes within the AST.
For deletions, the rule verifies that the .delete() method call is associated with a structure that includes a .where() clause. If the call chain is incomplete, it reports an error indicating that all rows in a table are at risk of deletion. The update rule follows a similar logic, specifically focusing on the .set() method following an .update() call, ensuring that the final chain logically includes a .where() operation.
Sources: eslint-plugin-drizzle/src/enforce-delete-with-where.ts:11-53, eslint-plugin-drizzle/src/enforce-update-with-where.ts:10-58
The plugin exposes configurations through an index.ts file that aggregates rules and settings, allowing for modular adoption:
Sources: eslint-plugin-drizzle/src/index.ts:9-14, eslint-plugin-drizzle/src/configs/all.ts:1-14, eslint-plugin-drizzle/src/configs/recommended.ts:1-14
The plugin utilizes the @typescript-eslint/utils RuleCreator to hook into the MemberExpression visitor. The implementation tracks the sequence of property names across the AST traversal to validate the presence of the required filtering methods.
Sources: eslint-plugin-drizzle/src/enforce-delete-with-where.ts:36-50
Note
The rules rely on internal state tracking during the AST traversal process to determine if a .where() method has been successfully called within the current query chain.
To integrate the plugin, ensure it is configured in your ESLint settings and use the recommended plugin exports.
// .eslintrc.yaml
plugins:
- drizzle
rules:
'drizzle/enforce-delete-with-where': 'error'
'drizzle/enforce-update-with-where': 'error'
// Your code usage
// This will trigger an error:
db.delete(users);
// This is correct:
db.delete(users).where(eq(users.id, 1));Sources: eslint-plugin-drizzle/src/index.ts:9-12, drizzle-orm/src/sqlite-core/query-builders/delete.ts:160-191
The design prioritizes preventing data-destructive API calls through static analysis.
Sources: eslint-plugin-drizzle/src/enforce-delete-with-where.ts:9-53
Important
The plugin identifies the Drizzle object based on the naming configuration provided in options. If you use custom object names for your Drizzle database instance, ensure they are registered in the rule options to trigger accurate detection.