Forward args correctly when using withReplica feature (#1536)
Fix selectDistinctOn not working with multiple columns (#1466)
New Features/Helpers
Detailed JSDoc for all query builders in all dialects
You can now access more information, hints, documentation links, etc. while developing and using JSDoc right in your IDE. Previously, we had them only for filter expressions, but now you can see them for all parts of the Drizzle query builder
New helpers for aggregate functions in SQL
Remember, aggregation functions are often used with the GROUP BY clause of the SELECT statement. So if you are selecting using aggregating functions and other columns in one query,
be sure to use the .groupBy clause
Here is a list of functions and equivalent using sql template:
For cases where it’s impossible to perform type checks for specific scenarios, or where it’s possible but error messages would be challenging to understand, we’ve decided to create an ESLint package with recommended rules. This package aims to assist developers in handling crucial scenarios during development. For more information you can check docs.
Install
npm
yarn
pnpm
bun
You can install those packages for typescript support in your IDE
npm
yarn
pnpm
bun
Usage
Create a .eslintrc.yml file, add drizzle to the plugins, and specify the rules you want to use. You can find a list of all existing rules below
All config
This plugin exports an all config that makes use of all rules (except for deprecated ones).
At the moment, all is equivalent to recommended
Rules
enforce-delete-with-where: Enforce using delete with the.where() clause in the .delete() statement. Most of the time, you don’t need to delete all rows in the table and require some kind of WHERE statements.
Error Message:
Optionally, you can define a drizzleObjectName in the plugin options that accept a string or string[]. This is useful when you have objects or classes with a delete method that’s not from Drizzle. Such a delete method will trigger the ESLint rule. To avoid that, you can define the name of the Drizzle object that you use in your codebase (like db) so that the rule would only trigger if the delete method comes from this object:
Example, config 1:
Example, config 2:
enforce-update-with-where: Enforce using update with the.where() clause in the .update() statement. Most of the time, you don’t need to update all rows in the table and require some kind of WHERE statements.
Error Message:
Optionally, you can define a drizzleObjectName in the plugin options that accept a string or string[]. This is useful when you have objects or classes with a delete method that’s not from Drizzle. Such as update method will trigger the ESLint rule. To avoid that, you can define the name of the Drizzle object that you use in your codebase (like db) so that the rule would only trigger if the delete method comes from this object: