How to find single record in database using trpc and drizzle?
I am trying to do a simple database lookup finding a user by a custom field discordId.
I have added that id to my drizzle schema and pushed to the database:
and now I am trying to create a trpc route for getting the info:
but I am getting an error:
looking at a similar process with prisma, the database structures are models and not simple 'consts' should the databasse structure type be automatically inferred or so I need to custom define this?
Solution:Jump to solution
I think i figured it out:
```
findUserByDiscordId: publicProcedure
.input(z.object({ discordId: z.string() }))...
5 Replies
Solution
I think i figured it out:
I am still looking for an answer on how to use findfirst with drizzle so it returns a single array rather than an object.
I cannot figure out how to use drizzle, findfirst, and a where clause...
Drizzle ORM - next gen TypeScript ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Here is how to use where with drizzle https://orm.drizzle.team/docs/select#filtering
Drizzle ORM - next gen TypeScript ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
To get a row you can use select or use query
Query is easier and allows you to get a single document directly
Check the first link
The where option works different than prisma. Check de second link