I'm using the Prisma Client (TypeScript). I want t...
# orm-help
d
I'm using the Prisma Client (TypeScript). I want to add ~500 records to my database -- is there not an option to insert many items into the database? Do I have to iterate instead?
h
Yes, you will need to iterate. Create a promise of all operations and do
Promise.all
on them. That way it would be send it batches to the Prisma server
d
Thanks for the quick reply! 🙂
a
Just note that there may be a difference between iterate+insertOne() vs insertMany(). With iterate+insertOne(), you may encounter an error halfway. When that happens, you end up with a "partial success" at that point. Some rows are inserted. Some are not. With insertMany(), it depends on the database. With MySQL/PostgreSQL/SQLite, all rows get inserted, or all rows do not get inserted. With Mongo, you can get partial success, pre-4.0. From 4.0 onward, you can use multi-document transactions to get the same behaviour as MySQL. Not too familiar with how Prisma does stuff under the hood but those are some points to consider.
I'm not even sure if Prisma has a
.createMany()
method but it doesn't look like it
Nested objects seem to allow insertMany() but I'm not sure if it's transactional
d
Yeah it seems to be missing that function right now, maybe the v2 gets it :^) I already encountered an error halfway, kinda meh, just redoing it for now in that case