[Beginner] Drizzle select with eq not working

Hi, Im trying drizzle for the first time and seems like theres something wrong with the way I use select with eq
No description
14 Replies
niëmand
niëmandOP12mo ago
This is not returning the existing users
niëmand
niëmandOP12mo ago
But these two seems to work
No description
niëmand
niëmandOP12mo ago
any help is appreciated on what im doing wrong with the first picture
Angelelz
Angelelz12mo ago
Where are you importing eq from?
niëmand
niëmandOP12mo ago
drizzle-orm And it’s not throwing any error It just returns an empty array even though there is records in DB
Angelelz
Angelelz12mo ago
Please do this. Take the first query, the one where you're having issues, remove the await and add the method: toSQL() at the end and then console log what it returns
niëmand
niëmandOP12mo ago
No description
Angelelz
Angelelz12mo ago
That is correct. Are you sure that email exists in the database?
niëmand
niëmandOP12mo ago
yes
const existingUser = await db.execute(sql`select * from ${users} where ${users.email} = ${email}`)
const existingUser = await db.execute(sql`select * from ${users} where ${users.email} = ${email}`)
niëmand
niëmandOP12mo ago
No description
niëmand
niëmandOP12mo ago
The above query returns the existing emails in the DB okay it works now, wierd Anyways thanks man
Angelelz
Angelelz12mo ago
Can you do toSQL() on that one to see? Can you show the database definition I meant the table definition
niëmand
niëmandOP12mo ago
export const users = pgTable("user", {
id: text("id").notNull().primaryKey().default(sql`gen_random_uuid()`),
name: text("name"),
email: text("email").notNull(),
emailVerified: timestamp("emailVerified", { mode: "date" }),
password: text("password"),
image: text("image"),

})
export const users = pgTable("user", {
id: text("id").notNull().primaryKey().default(sql`gen_random_uuid()`),
name: text("name"),
email: text("email").notNull(),
emailVerified: timestamp("emailVerified", { mode: "date" }),
password: text("password"),
image: text("image"),

})
Angelelz
Angelelz12mo ago
I can't find anything wrong with this setup I guess the next step is creating a reproduction repo to investigate This API is well tested, I doubt it's an issue with drizzle
Want results from more Discord servers?
Add your server