switch function in drizzle

I'm following the "Add Clerk Authentication & Stripe Payments to your NextJS tRPC Application" tutorial. The tutorial uses T3 app + Prisma + Clerk. I've used drizzle for my T3 app and need help converting this switch function written in Prisma-speak to Drizzle-speak.
No description
4 Replies
Neto
Neto5mo ago
switch (eventType) {
case "user.created": {
// https://orm.drizzle.team/learn/guides/count-rows
const [{count = 0}] = await db.select({count: count()}).from(accounts).where(eq(accounts.userId, id))

if(!count){
// https://orm.drizzle.team/docs/insert
await db.insert(accounts).values({userId: id})
}
}

...
}
switch (eventType) {
case "user.created": {
// https://orm.drizzle.team/learn/guides/count-rows
const [{count = 0}] = await db.select({count: count()}).from(accounts).where(eq(accounts.userId, id))

if(!count){
// https://orm.drizzle.team/docs/insert
await db.insert(accounts).values({userId: id})
}
}

...
}
maybe there is an error or two around types and syntaxes, but should be easy to go from there
Bickibird
BickibirdOP5mo ago
@nyx (Rustular DevRel) thank you for replying! Getting a few errors still:
No description
Neto
Neto5mo ago
idk the codebase to point to the specific errors but
import { count, eq } from 'drizzle-orm';
import { count, eq } from 'drizzle-orm';
Bickibird
BickibirdOP5mo ago
Thanks so much
Want results from more Discord servers?
Add your server