What's the best way to bulk insert with a many-to-many relationship (posts & categories) in prisma?
What's the best way to bulk insert with a many-to-many relationship (posts & categories) in prisma?
9 Replies
I have a large amount of posts I need to seed into the database, but there doesn't seem to be a way to do that with a many-to-many relationship like categories
how slow is it to do them in a loop?
(and what is this for? testing I guess?)
very slow, there are about 30k articles posts to push
not for testing, im transferring over data from to from a legacy site
ok, if 30k and it's a one-time job, I might just say do it the slow way. If it runs a long time it runs a long time.
But also since this is a one-time job, consider maybe dropping out of prisma and using SQL if you think that will let you get done faster
do u have a many to many set up in ur prisma schema already
or no
If you have the schema and etc all done, then just use a createMany, which is a single SQL statement and faster than doing many creates
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Prisma
Transactions and batch queries (Reference)
This page explains the transactions API of Prisma Client.
\so you're basically just doing putting the foreign key in manually?