Smarter way to update while creating
In prisma, I can do something like this:
is there a smarter way to do this in drizzle? currently im doing this:
this is extremely slow to do the promise.all here. it would be much more efficient to just do this upon creation of the
blogs
if i could just do a create many and name one trip to the db. at the very least i'd like to be able to do 2 trips (one for the creation of all the new blogs and one for the user updates)3 Replies
bump
depends on the db engine you are using
I believe prisma also does this the stupid way, it also makes one db query per updated, so I'm not sure there's a huge performance difference here
but if you're using postgres you can use an upsert on users, as long as you are 100% sure that every user id you are referencing currently exists
note that your sql has to use the column casing you use at the database level, so if you have underscore db columns and camelcase drizzle prop names, you'll have to use
excluded.blog_id
instead
you have to think about this from a sql engine standpoint rather than a drizzle standpoint. prisma is not doing anything smart here, one await
call in prisma is translating into n
database calls@francis ended up doing something like this: