Nullable arrays as parameters in drift file queries #3525
-
I have a query like the following (ignore the absurdity of this example): getCars(:brand AS TEXT OR NULL): SELECT * FROM cars WHERE brand = :brand; Since But is it also possible to do the same with an array expression? So I can pass a getCarsMulti(:brands AS ??? OR NULL): SELECT * FROM cars WHERE :brands IS NOT NULL AND brand IN :brands; (This example is even stranger, but hopefully illustrates the point) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Thanks for the report. The model
I'm actually not sure I understand the point to be honest. What would you expect FWIW, one thing that should work today is: getCarsMulti: SELECT * FROM cars WHERE :brands IS NOT NULL AND $brands; Then you can call this in Dart: getCarsMulti(
brands: (car) => switch (brands) {
null => const Literal(null),
var brands? => car.brand.isIn(brands)
}
) |
Beta Was this translation helpful? Give feedback.
Thanks for the report. The model
drift_dev
uses internally can't represent the concepts of nullable arrays (only arrays with nullable elements), so this is indeed impossible.I'm actually not sure I understand the point to be honest. What would you expect
brand in :brand
to evaluate to if:brand
isnull
, alsoNULL
? Since those checks are most commonly used inWHERE
clauses, isn't that effectively equivalent to just passing an empty list?FWIW, one thing that should work today is:
Then you can call this in Dart: