How to delete multiple db entries at once?

I have a list of IDs of items I wish to delete, but I cannot figure out a way to delete them. I would prefer not to use hard-coded SQL as that's why I chose to use Drizzle over other alternatives. Here is what I have and what I found, but does not appear to work. I could not find any IN function built into Drizzle. Any help would be much appreciated.
// tagTable: my defined DB table schema
// tagsToRemove: a list of Tags
class Tag {
tagId: number
}

await db.delete(tagTable).where(sql`${tagTable.tagId} IN (${sql.join(tagsToRemove.map(x => x.tagId))})`);
// tagTable: my defined DB table schema
// tagsToRemove: a list of Tags
class Tag {
tagId: number
}

await db.delete(tagTable).where(sql`${tagTable.tagId} IN (${sql.join(tagsToRemove.map(x => x.tagId))})`);
1 Reply
Luxaritas
Luxaritas3w ago
inArray is the function you’re looking for!
Want results from more Discord servers?
Add your server