-
Notifications
You must be signed in to change notification settings - Fork 3
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
Queries with empty arrays are broken #7
Comments
const b = await a.all`SELECT * FROM (VALUES (1), (2)) WHERE column1 NOT IN (${-1})`; accordingly, your second query is invalid SQL syntax because you are not passing a value. |
|
actually ... never mind, I indeed added the ability to spread lists ... but still, your SQL looks invalid, apologies for the confusion ... how would you write that statement in raw SQL? |
SELECT * FROM (VALUES (1), (2)) WHERE column1 NOT IN (-1) SELECT * FROM (VALUES (1), (2)) WHERE column1 NOT IN () I have tested all of these SQL statements by directly typing the expected values into SQLite and it works fine; it is only when using your library that empty arrays fail. |
https://www.sqlite.org/lang_expr.html#booleanexpr
Given that is an SQLite-specific library I did expect empty arrays to work, and it'd be nice to have this feature. But given the |
I think I want that to work in here too ... why not filing a PR? 😄 |
I've opened one in your |
sure and ... thanks! I'll do the update dance right after that gets merged |
Thanks! |
The array interpolation feature usually works great, but when given an empty array, it fails.
correctly returns
[ { column1: 1 }, { column1: 2 } ]
buteither produces an error or returns nothing.
This is because your dependency
static-params
doesn't return a value for empty arrays when converting JS format strings to SQL parameters. Your code in utils.js assumes that the amount of statement fragments is alwaysv+1
, wherev
is the amount of substituted values. But since the SQL statement is still split at an empty array but no value is provided, this assumption is incorrect.A possible solution would be to specifically account for empty arrays by returning a value of
''
, as I have done in my project that bundlessqlite-tag-spawned
. I'm unsure if this would break other things that rely onstatic-params
though.The text was updated successfully, but these errors were encountered: