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:
db.batch(peopleArray.map(p => db.insert(people).values(p))

But I can do something like this which works for a single entry?
const person = { id: 1, name: "Tester" }
const ins = db.insert(people).values(person)
db.batch([ins])

So why can't I do something similar with an array?
Solution
You could have a helper like this:
function isTuple<T extends any[]>(array: T): T is [T, ...T[]] {
   return array.length > 0;
}


With that you can please the compiler
Was this page helpful?