Need syntax help

I've been trying out drizzle for a couple hours, and was wondering if there's any way to replicate this action from prisma:
const session = await prisma.session.create({
data: {
userAgent: event.request.headers.get("user-agent"),
user: {
connectOrCreate: {
where: {
email: form.data.email,
},
create: {
email: form.data.email,
},
},
},
},
select: {
id: true,
},
})
const session = await prisma.session.create({
data: {
userAgent: event.request.headers.get("user-agent"),
user: {
connectOrCreate: {
where: {
email: form.data.email,
},
create: {
email: form.data.email,
},
},
},
},
select: {
id: true,
},
})
Is there an equivalent to this way of creating a session that's just as efficient? The main appeal is the "connectOrCreate" functionality.
6 Replies
x03
x03OP10mo ago
Ah, so just combine several queries in one transaction. Appreciate the help 🙏 May I ask what the point of relations are if actions such as this one aren't a thing?
Mykhailo
Mykhailo10mo ago
They were designed for avoiding multiple joins and complex data mapping, but honestly, I don't have right answer, as I am not drizzle developer:)
x03
x03OP10mo ago
So I can just remove the parts that I crossed out, and keep the squared part, and then just use that userId for all my queries / mutations?
No description
x03
x03OP10mo ago
I guess that's now relations work under the hood, but it seems weird to allow relations and have them be near-useless 😭
Mykhailo
Mykhailo10mo ago
yes, you are right! Also, you can read docs about relations and foreign keys https://orm.drizzle.team/docs/rqb#foreign-keys
Drizzle ORM - Query
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Want results from more Discord servers?
Add your server