Issue querying with relations in bun+sqlite
👋 repro + context here - https://github.com/sammccord/drizzle-relations-repro
It seems like the query goes through fine, but the row comes back as json and not a list of values, so trying to access the fields by index won't work.
Not sure if it's a bun or drizzle issue, but since the query works fine it could be a simple parsing fix but I'm not 100% the best way to go about fixing it myself.
GitHub
GitHub - sammccord/drizzle-relations-repro
Contribute to sammccord/drizzle-relations-repro development by creating an account on GitHub.
9 Replies
I've ran into this same issue, @sammccord were you ever able to resolve this?
Nope
i was able to get it to work by adding this:
on line 262 of
node_modules/drizzle-orm/relations.js
but i am unsure if this breaks something or not
Maybe someone from the drizzle team could take a look at this?
I feel like this is an issue to be resolved at the bun-sqlite driver level, since there could be other behaviors that depend on the row being an arrayThis looks good to me, I’ve moved to a different orm but would definitely be nice to get this looked at
which orm are you using now, out of curiosity?
Prisma, I’d rather use drizzle but I’m firmly in bun and this is is the only thing holding me back
hey @alexblokh, are you aware of this issue/discrepancy in behavior between the better-sqlite3 and bun:sqlite driver?
I did some more debugging, it seems like the
better-sqlite3
driver calls
which returns an array of values ([ '0.9687278431702451', '[["0.07639715656862389","0.9687278431702451"]]']
in this example)
after this block
inside PreparedQuery.get
where the get would return a mapped value.
Meanwhile, the bun driver seemingly always calls the api to get a mapped value ( const row = this.stmt.get(...params);
) and works with that value for the rest of the PreparedQuery.get
function, including in parts where an array is expectedoh, it seems there is a PR for this already: https://github.com/drizzle-team/drizzle-orm/pull/1276
GitHub
Fix bun sqlite returning when using get by dardanbujupaj · Pull Req...
Fix returning with bun sqlite when using get.
Bun sqlite get returns an object, which is not handled well by the result mapper. By using values (but only the first index) we receive the needed arra...
opened last year
I also found this PR: https://github.com/drizzle-team/drizzle-orm/pull/1885 that seems to already be merged
but forcing drizzle-orm to the latest version (which has this code change) doesn't seem to work
🤔