Pioter
Pioter
DTDrizzle Team
Created by Pioter on 10/23/2023 in #help
Next 13, Next-Auth with Neon Postgres and Drizzle vs Prisma 5
I am trying to set up Next-Auth with Neon Postgres and Drizzle, but failing miserably. I set up a repo with several branches, including configurations for: 1) Next 13, Next-Auth, Neon Postgres, Prisma 5 2) Next 13, Next-Auth, PlanetScale MySQL, Prisma 5 3) Next 13, Next-Auth, Neon Postgres, Drizzle The first two work perfectly fine, I am able to authenticate and store users in a database, regardless of whether they are signing up with password, magic links, or OAuth providers. However, I am facing weird issues with the Drizzle branch, particularly with getUserByEmailAction and other similar .select() -based queries, which for some weird reason sometimes return undefined. The logic for all three branches is exactly the same and the code is nearly identical. If anyone would like to have a look and see if they are able to fix it, the code is available here: https://github.com/pjborowiecki/SAASY-LAND-Next-13-Starters-With-Authentication-And-Database-Implemented The branch I am referring to is called next-auth-drizzle-neon-postgres Looking forward to some of you trying and pointing out the issue!
27 replies
DTDrizzle Team
Created by Pioter on 10/22/2023 in #help
Performance difference between `.select()` and `.findMany()`
Is there any performance difference between .select() and .findMany() when using in prepared statements? Or any benefit of using one over the other? Which one is preferred in prepared statements?
1 replies
DTDrizzle Team
Created by Pioter on 10/22/2023 in #help
Prepared statement returns undefined
I have the following server action:
export async function getUserByEmailAction(email: string) {
return await psGetUserByEmail.execute({ email })
}
export async function getUserByEmailAction(email: string) {
return await psGetUserByEmail.execute({ email })
}
When I define the prepared statement as
export const psGetUserByEmail = db
.select()
.from(users)
.where(eq(users.email, sql.placeholder("email")))
.prepare("psGetUserByEmail")
export const psGetUserByEmail = db
.select()
.from(users)
.where(eq(users.email, sql.placeholder("email")))
.prepare("psGetUserByEmail")
I get the user back. But when I define the statement as
export const psGetUserByEmail = db.query.users
.findFirst({
where: (users, { eq }) => eq(users.email, sql.placeholder("email")),
})
.prepare("psGetUserByEmail")
export const psGetUserByEmail = db.query.users
.findFirst({
where: (users, { eq }) => eq(users.email, sql.placeholder("email")),
})
.prepare("psGetUserByEmail")
I get undefined. Why is that? What is wrong with the statement using .findFirst() instead of .select() ??
2 replies
DTDrizzle Team
Created by Pioter on 10/22/2023 in #help
Prepared Update statements
Is it possible to use preparad statements for updating data? I was able to use prepared statements with .select(), .findFirst(), or .findMany(), but I am having trouble with .update(). If possible, what would the syntax be? I am trying to update a verificationToken, and I would need two placeholders there. Tried something like this, but It's wrong:
export const psUpdateEmailVerificationToken = db.update(users).set({
emailVerificationToken: sql.placeholder("emailVerificationToken"),
}).where({
(users, {eq}) => eq(users.id, sql.placeholder("id"))
}).prepare("psUpdateEmailVerificationToken")
export const psUpdateEmailVerificationToken = db.update(users).set({
emailVerificationToken: sql.placeholder("emailVerificationToken"),
}).where({
(users, {eq}) => eq(users.id, sql.placeholder("id"))
}).prepare("psUpdateEmailVerificationToken")
Is this even possible? I am using Drizzle with Postrgres at Neon.
7 replies