Drizzle ORM Query Builder Only Returning One Row

Aren't these two queries the same?
const [data] = await db.execute(sql`SELECT * FROM products`);
const [data] = await db.execute(sql`SELECT * FROM products`);
const [data] = await db.select().from(products);
const [data] = await db.select().from(products);
I'm trying to fetch all rows from the products table. Raw SQL query execution works fine and returns all rows:
db.execute(sqlSELECT * FROM products)
db.execute(sqlSELECT * FROM products)
But using the standalone query builder, only one row is returned:
db.select().from(products)
db.select().from(products)
Do I miss something here? I'm using MySQL with Next.js
2 Replies
rphlmr ⚡
rphlmr ⚡5mo ago
The first query is good. The second is good too but when doing [data] with the builder api you are destructing the array of results to grab the first result.
const data = await db.select().from(products)
const data = await db.select().from(products)
othman
othmanOP5mo ago
Thank you @Raphaël M (@rphlmr) ⚡
Want results from more Discord servers?
Add your server