How to use the Batch API?
Hi,
I am using Turso and have an array of people I need to insert into my database. I've tried via
db.insert(people).values(peopleArray)
but get an error about too many variables or something so then I looked into the batch API, but this doesnt work either:
But I can do something like this which works for a single entry?
So why can't I do something similar with an array?Solution:Jump to solution
You could have a helper like this:
```ts
function isTuple<T extends any[]>(array: T): T is [T, ...T[]] {
return array.length > 0;
}...
3 Replies
db.batch
accepts a tuple with at least 1 item. The shape is [T, ...T[]]
Typescript is complaining because it can't statically verify that there's at least one item in that arraySolution
You could have a helper like this:
With that you can please the compiler
Hiya, thanks for the reply but that still doesnt work:
Further down:
Error: Source provides no match for required element at position 0 in target
Ah nvm, sorry it does work, needed to do this:
Thanks again for your help