sqlite http-proxy can't handle undefined values on `.get()` ?
Hi drizzle team! I've been playing with the http-proxy plugin to see how it works, and I hit a funny edge case trying to handle
undefined
values on get()
. The docs show this barebones example to set up an http proxy:
They, I attempted a .get()
request for a value that doesn't exist in the database:
I tested the better-sqlite3
adapter and found email
should return undefined
(which doesn't match the type inference mind you!). But in the SQlite proxy, I get a much funnier result:
It seems it's trying to parse the value even when rows
is an empty array in the adapter. Is there a way to return undefined
for this case as in the better-sqlite adapter? Thanks!12 Replies
Thanks for the feedback! I'll try to reproduce it
Yes, it's possible to do that
Also, what was the issue with 'email doesn't match the type inference'? Can you show the schema object and a query where types are wrongly inferred?
Ah, just commenting that the type signature gaurantees a return value when it could be
undefined
oh, it't a known issue
We actually have a PR for that
didn't have a chance to merge it yet
also saw you GH issue about custom types
It's a known issue that toDriver is not always called on inserts, especially when the value is undefined, for example. However, for your case, we will provide the ability to pass a custom function to a default in a schema
Tracking issue for that
https://github.com/drizzle-team/drizzle-orm/issues/304
will duplicate this message in GH issue
Ah that would be fantastic. The custom type was definitely a workaround after trying a lambda in
default
first!
So you mean .default(() => nanoid())
could be possible in the future?We were thinking
.$default(() => nanoid())
just to separate database defualts and runtime defaults
but yes
we will have it
2 super important things for us, that we are working on
1. Relational Queries performance improvements(almost there)
2. Slow TypeScript Intellisense on a big amount of tables/columns -> https://discord.com/channels/1043890932593987624/1095436601426972822
After that will clean PR's and add such features like defaults, etc.All very helpful, thanks!
So about the
undefined
issue in my http-proxy, is this a case of me holding it wrong? Or are there planned changes here?I think it may be just a bug on sqlite-proxy side. I'll go through tests there and try to spot this issue
I'll have a time to check it tomorrow and will ping you back here
Sounds good. I can just check if
entry?.id
is undefined
as a workaround for nowYeah, sorry for that and thanks for a bug report, it's always very helpful
Also traced the code if it helps! Looks like empty arrays are still mapped against the column names, even when that array is empty. Would explain why the values are present but undefined https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/sqlite-proxy/session.ts#L129-L134
GitHub
drizzle-orm/drizzle-orm/src/sqlite-proxy/session.ts at main · drizz...
TypeScript ORM that feels like writing SQL. Contribute to drizzle-team/drizzle-orm development by creating an account on GitHub.
Thanks!