K
Kysely15mo ago
liteyear.

How can I write a query that does multiple insertions at once?

I have an array of Ids that I want to assign to a single id in a "bridging" table for a many to many relationship: ie: singleId: id1 singleId: id2 singleId: id3
3 Replies
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
koskimas
koskimas15mo ago
@liteyear. Which dialect are you using? Most dialects support this:
db.insertInto('table')
.values([
{ singleId: id1, otherId: id },
{ singleId: id2, otherId: id },
{ singleId: id3, otherId: id }
])
.execute()
db.insertInto('table')
.values([
{ singleId: id1, otherId: id },
{ singleId: id2, otherId: id },
{ singleId: id3, otherId: id }
])
.execute()
liteyear.
liteyear.OP15mo ago
thanks!!
Want results from more Discord servers?
Add your server