K
Kysely10mo 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 User10mo ago
Message Not Public
Sign In & Join Server To View
koskimas
koskimas10mo 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.10mo ago
thanks!!