Is this the best way to find or create a user in Prisma?
prisma.user.upsert({
where: {
id: user.id,
},
update: {
id: user.id,
},
create: {
id: user.id,
},
})
Yes, you can use upsert to create a record. If the update property is empty, the record will not be updated.
Example:
const upsertUser = await prisma.user.upsert({
where: {
email: '[email protected]',
},
update: {},
create: {
email: '[email protected]',
name: 'Test User',
},
})
We plan to document this better: how upsert can behave as a findOrCreate. The link to the GitHub issue can be found here
For more information regarding upsert, you can read more in the Prisma Client API Reference section.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With