drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.56k stars 646 forks source link

[FEATURE]: Cancel empty queries #2765

Closed jakeleventhal closed 2 months ago

jakeleventhal commented 3 months ago

Describe what you want

Some drizzle statements, like inArray(someTable.id, []), will evaluate to the following SQL:

DELETE FROM sometable WHERE false

It is possible to have complex layering of query conditions, but this feature is to propose canceling queries entirely and just resolving the promise for calls that will result in no data, updates, etc.

The goal would be to recursively check all conditions in a WHERE clause and determine if the entire result can be simplified to false. If so, never make an attempt to reach the db. This would just speed up some API calls and remove the need to contact the DB in many cases

L-Mario564 commented 2 months ago

Checking for these kind of conditions adds overhead to the ORM and even if no rows are affected, some developers may still want to execute them because of triggers or for logging purposes. This won't be worked on as the developer should be responsible for running or not running said queries.