Prepared statement returns undefined

I have the following server action:

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")


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")


I get undefined.

Why is that? What is wrong with the statement using .findFirst() instead of .select() ??
Was this page helpful?