Conditional batch on Neon Batch API?

Hi, it's possible to do something like:
const deleteImages = true // can be true or false

await db.batch([
db.update(users).set({ ... }).where(...),
deleteImages ? db.delete(userImages).where(...) : false
])
const deleteImages = true // can be true or false

await db.batch([
db.update(users).set({ ... }).where(...),
deleteImages ? db.delete(userImages).where(...) : false
])
1 Reply
Angelelz
Angelelz3w ago
If instead of false, you pass undefined, I don't see why it would have a problem But even safer, you could do this:
const deleteImages = true // can be true or false
const queryList = [db.update(users).set({ ... }).where(...)]
if (deleteImages) {
queryList.push(db.delete(userImages).where(...))
}

await db.batch(queryList)
const deleteImages = true // can be true or false
const queryList = [db.update(users).set({ ... }).where(...)]
if (deleteImages) {
queryList.push(db.delete(userImages).where(...))
}

await db.batch(queryList)
Want results from more Discord servers?
Add your server