drizzle-team / drizzle-team/drizzle-orm
[FEATURE]: AsyncLocalStorage for transactions
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Describe want to want
The idea is to use [AsyncLocalStorage](https://nodejs.org/api/async_context.html) for automatically detecting transaction context, without using transaction object. Example how it should look like:
```typescript
await db.transaction(async () => {
await db.insert(users).values(newUser);
await db.transaction(async () => {
await db.update(users).set({ name: 'Mr. Dan' }).where(eq(users.name, 'Dan'));
await db.delete(users).where(eq(users.name, 'Dan'));
});
});
```
It can make the library easier to use, especially in case if database call is buried in call chain:
Instead of using this:
```typescript
async createUser(dto, transaction?: ...) {
await (transaction || db).insert(users).values(newUser);
}
```
User can write just this:
```typescript
async createUser(dto) {
await db.insert(users).values(newUser); // automatically detect that current request is in transaction
}
```
Contributor guide
Assessment
This issue has not been assessed yet.