drizzle-team / drizzle-team/drizzle-orm
[BUG]: Single-use generic type inferencing for libsql batch response
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### What version of `drizzle-orm` are you using?
0.28.6
### What version of `drizzle-kit` are you using?
0.19.13
### Describe the Bug
When using a batch query which maps data into queries, I have to use typescript kung fu to make sure batch API does not complain.
Example use-case:
```typescript
// ... database intialization
const db: LibSQLDatabase> = drizzle(...);
// ... batch api usage
const queries = transformedDataArray.map(data=>
db.insert(schemas.transformData)
.values(data)
.onConflictDoUpdate({
target: [schemas.transformData.key1, schemas.transformData.key2],
set: { value: data.value }
})
);
type Query = typeof queries[number];
await db.batch(
queries as [Query, ...Query[]] // typescript kung fu required to make it work
);
```
### Expected behavior
I would expect the batch response generic definition to allow using dynamic arrays instead of only Readonly tuples.
I think the issue is with how BatchResponse is defined:
https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/libsql/driver.ts#L34
```TQuery extends Readonly<[U, ...U[]]>``` allows the batch parameter to only be a const tuple. I'm not an expert but a simple solution would be allowing TQuery to either extend a tuple or an array like so: ```TQuery extends Readonly<[U, ...U[]]> | U[]```
Another potential solution would be to allow sending nested array queries, but that would incur runtime costs
### Environment & setup
In my local vscode typescript server
Contributor guide
Assessment
This issue has not been assessed yet.