Skip to content

Support for encoding parametrized lists #4

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

Closed
wants to merge 1 commit into from

Conversation

edlman
Copy link

@edlman edlman commented Apr 12, 2019

With added support for encoding parametrized lists. E.g.

  List<int> ids = [ ... ]; // init list with values or get it from parameters
  result1 = db.query("select * from table where id in (@ids)", { "ids": ids });
  result2 = db.query("select * from table where id = any (array[@ids]::int[])", { "ids": ids });

When using array[@x] syntax in query it's wise to use array type cast (::int[], ::date[], ...) to avoid problems with null list.

Signed-off-by: Martin Edlman ac@an.y-co.de

Signed-off-by: Martin Edlman <ac@an.y-co.de>
@tomyeh
Copy link
Owner

tomyeh commented May 8, 2020

Sorry, but I think a list can have different meaning. For example, a JSON value. Also, in your example, it will cause a syntax error if the list is empty.

Maybe you can consider to introduce a class for it.

class ListValues {
   String encode();
}

class StringValues implements ListValues {
   StringValues(Iterable<String> this.values, [String this.emptyValue="''"]);
   String encode() => values.isEmpty ? emptyValue: ...;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants