drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.65k stars 650 forks source link

[BUG]: Select operation returning [] while using ORM but not while using SQL #2671

Open dev-shetty opened 4 months ago

dev-shetty commented 4 months ago

What version of drizzle-orm are you using?

0.32.0

What version of drizzle-kit are you using?

0.23.0

Describe the Bug

I am using Drizzle ORM with Turso SQLite.

I am trying to select the items in a table but I am getting [] (empty array) while using the ORM style fetching. Code and screenshot below

export async function test() {
  const result = await db.select().from(fooTable).all()
  return result
}

Output:

image

But while using SQL I am getting the correct output, code and screenshot below:

export async function test() {
  const result = (await db.run(sql`SELECT * from ${fooTable}`)).rows
  return result
}

Output:

image

Surprisingly, Insert operation works with the ORM fetching, with this code

export async function test() {
  const result = await db.insert(fooTable).values({ bar: "Deveesh Shetty" }).returning()
  return result
}

Expected behavior

This code should also return the rows in the table and not an empty array

export async function test() {
  const result = await db.select().from(fooTable).all()
  return result
}

Environment & setup

Development environment Using Next.js 14.2.5 Package Manager: pnpm 9.5.0

guerty48011 commented 4 months ago

I had a somewhat similar problem and reinstalling drizzle fixed it for me (I actually recloned the whole project from github, since I tried the same code on another computer and it worked fine)

feri-irawan commented 2 months ago

Same issue, using SQLite (Turso) always returns an empty array, even though there is data.

const stickersList = await db.select().from(stickers).all(); // output: []
const stickersList = await db.select().from(stickers); // output: []