drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: Support query cancellation with `AbortSignal`

Open
#1,602 9 comments 118 reactions 1 assignee Claimed by @AndriiSherman View on GitHub
enhancement
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Describe what you want

Currently, there is no simple way to cancel queries with Drizzle. There are cases where query cancellation can be useful to conserve server resources. One ubiquitous case would be a user navigating away from an interface that interacts with a long-running query where the results may no longer be relevant. Another use could be the application defining query execution timeouts.

Note: most databases support cancelling queries ([mysql](https://dev.mysql.com/doc/refman/8.0/en/kill.html), [sqlite](https://www.sqlite.org/c3ref/interrupt.html), [postgres](https://www.postgresql.org/docs/14/libpq-cancel.html))

It seems that [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) is becoming a standard for cancelling async operations. It's implemented in all major runtimes, including Node > 15.

- It's used in [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#aborting_a_fetch)
- It's used in a number of nodejs APIs, e.g. [`child_process`](https://nodejs.org/api/child_process.html)
- It's discussed as a solution to query cancellation problem in other ORMs ([`knex`](https://github.com/knex/knex/issues/707), [`sequelize`](https://github.com/sequelize/sequelize/issues/14247), [`prisma`](https://github.com/prisma/prisma/issues/15594))
- It's supported in a number of other third-party solutions, e.g. Temporal

Drizzle queries could take additional signal param similar to fetch and other APIs.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.