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() ??
1 Reply
MAST
MAST13mo ago
You can try to look at the generated SQL to find the issue. turn the logger on in the drizzle config like this:
export const dbDrizzle = drizzle(client, { schema, logger: true });
export const dbDrizzle = drizzle(client, { schema, logger: true });
And check for differences.
Want results from more Discord servers?
Add your server