Skip to content
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

How to create dynamic WHERE clause #14

Open
PepijnK opened this issue Oct 10, 2017 · 1 comment
Open

How to create dynamic WHERE clause #14

PepijnK opened this issue Oct 10, 2017 · 1 comment

Comments

@PepijnK
Copy link

PepijnK commented Oct 10, 2017

Hi,

Is there support for dynamic where clauses? I could not find any documentation about how to do that. In my case I need to add AND'd conditions with nested OR conditions conditionally, to get something like:
WHERE x=? AND (foo>=? OR bar> ?) AND (bar> ?)

I've tried to create an []sq.Sqlizer and add the OR-expressions in there, then feed that to SelectBuilder.Where() but it fails with the message

converting Exec argument # 1's type: unsupported type []sqrl.Sqlizer, a slice

Ideally there is some kind of ConditionBuilder for this I guess.

@nuqz
Copy link

nuqz commented Oct 26, 2017

@PepijnK Hi, take a look at Or type and it's conj type. According to example you can try something like:

statement.
  Where(sq.Eq{"x": xval}).
  Where(sq.Or{
    sq.GtOrEq{"foo": fooval},
    sq.Gt{"bar": barval1},
  }).
  Where(sq.Gt{"bar": barval2})

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

No branches or pull requests

2 participants