drizzle-team / drizzle-team/drizzle-orm
[FEATURE]: Relax batch type to accept BatchItem<'sqlite'>[] in DrizzleD1Database
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Feature hasn't been suggested before.
- [x] I have verified this feature I'm about to request hasn't been suggested before.
### Describe the enhancement you want to request
The current `batch` method in `DrizzleD1Database` has the following signature:
```ts
async batch, T extends Readonly<[U, ...U[]]>>(
batch: T,
): Promise>
```
While this enforces a non-empty array, it makes it cumbersome to use in practice. For example, consider a helper function like:
```ts
function insertData(data: TData): BatchItem<'sqlite'>[] {
// ...
}
```
To use this with `batch`, we must cast the result:
```ts
await db.batch(insertData(data) as [BatchItem<'sqlite'>, ...BatchItem<'sqlite'>[]]);
```
This cast is verbose and error-prone, especially when you're already returning a typed array.
### Suggested Change
Relax the type constraint on `batch` to accept any readonly array of `BatchItem<'sqlite'>`:
```ts
async batch, T extends readonly U[]>(
batch: T,
): Promise>
```
A simple runtime check can return early for an empty array.
If this change is acceptable, I’d be happy to open a PR to implement it.
Contributor guide
Research direction
Start at the DrizzleD1Database.batch signature described in the issue and inspect its surrounding implementation. Verify the empty-array behavior and relevant batch tests, then confirm that readonly BatchItem<'sqlite'>[] is accepted without a cast while existing batch response typing remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend, database
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100