-
-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE]: Allow to pass empty values to inArray #1295
Comments
I believe such a change would lead to an easier developer experience. That being said, similar changes to other aspects of the API have been closed by the team with no action. See #1078 |
I would expect |
I'm not part of the team. I'm just trying to help cleanup the issues. There are two options that have been discussed:
function isTuple<T extends any[]>(array: T): T is [T, ...T[]] {
return array.length > 0;
} And handle the case accordingly in userland.
The down side of the first is that the user has to deal with it (like they are right now, just now the types help them figure it out they need to do it), and handle the case when the array is empty, like this for example: ...
.where(isTuple(myArray) ? inArray(column, myArray) : sql`false`)
... The down side of the second one is that it introduces hidden behavior, we just don't know down the line what other issues it will start. |
I think it's reasonable for a user to assume the following functionality:
In JS: |
Adding a +1 for this; throwing an error when passed an empty array is not useful nor expected, nor does it raise a typescript error which especially sucks. |
I've been using inArray extensively in my recent project and handling this behavior is my single biggest pain point with drizzle. Throwing an error because the array is empty is not expected at all, and I've spent a fair amount of time fixing production code just because of this "feature". I honestly don't see why (as a benefit to the developer) the empty array is not handled internally by drizzle and that it is expected that this should be handled externally outside drizzle instead. |
This could be a solution: https://moderndash.io/docs/arrayminlength |
Hello guys ! Do not hesitate to add your thumb-ups ;) |
Describe what you want
Passing empty array to
inArray
throws:I think it would be more ergonomic to allow empty array as it would avoid additional checks outside of query builder.
Also, throwing an error causes unexpected runtime error if the array changes dynamically.
That's actually what have happened to me with following code:
The text was updated successfully, but these errors were encountered: