How to dynamically generate select queries?

I use this generator for Go (https://github.com/Masterminds/squirrel) and I have to create an SQL where parser.

Suppose I have user’s inputs like these:

  • Bar.Alpha = 7
  • Foo.Bar.X = ‘hello’
  • Foo.Bar.Beta > 21 AND Alpha.Bar != ‘hello’
  • Alice.IsActive AND Bob.LastHash = ‘ab5534b’
  • Alice.Name ~ ‘A.’ OR Bob.LastName !~ 'Bill.
  • Field1 = “foo” AND Field2 != 7 OR Field3 > 11.7

There might be lots of AND / OR in user’s queries. How to dynamically generate them? Thanks.

1 Like

By “dynamically generate them,” do you mean that given Foo.Bar.X = 'hello', you need to generate the SQL WHERE clause for that constraint? Do you also need to generate the JOINs?