Closed rev4324 closed 5 hours ago
I suspect this is a bug in Bun. Can you file an issue in https://github.com/oven-sh/bun?
I don't think this is a bug in Bun, since the problem is caused by joined table column names overriding the original table column names. JS objects can't have the same key twice so the behavior is the same in bun:sqlite and better-sqlite3 when used directly, without Drizzle - the columns are overridden. Drizzle seems to mitigate this behavior in better-sqlite3 driver, but it doesn't do that in bun:sqlite one.
Can confirm it's not just Bun; I'm running into the same error with drizzle-orm/d1
.
Edit:
Seems to be part of this file.
this.logger.logQuery(this.query.sql, params);
- const row = this.stmt.values(...params)[0];
+ const row = stmt.raw().get(...params) as unknown[];
.raw() Causes the prepared statement to return rows as arrays instead of objects. This is primarily used as a performance optimization when retrieving a very high number of rows. Column names can be recovered by using the .columns() method.
Not sure if this is it, but it sounds like what's being described.
@rev4324 Hi there, is this still an issue? I cloned your reproduction repo and it seems both drivers now return the same values.
Seems like the issue was fixed. @L-Mario564 is right, it's working now. I checked on Bun 1.1.26 and the results are exactly the same between bun:sqlite and better-sqlite3. The issue was likely due to Bun's sqlite driver itself though, since when I use Bun 1.1.8 (the version I did use when creating this issue), the issue is still there. It must have been fixed sometime between 1.1.8 and 1.1.26. Note: I used the same, old drizzle version with both Bun versions since I installed the deps with a frozen lockfile.
What version of
drizzle-orm
are you using?0.30.10
What version of
drizzle-kit
are you using?No response
Describe the Bug
The same query yields different results using
bun:sqlite
compared tobetter-sqlite3
on Node. Thebun:sqlite
result is wrong - it has mismatched values and keys. The query uses two left joins.Reproduction: https://github.com/rev4324/drizzle-repro
Expected behavior
Both drivers should yield the same results.
Environment & setup
I'm using macOS 14.4.1 (23E224) ARM64.