The 1.2.2 release adds a few minor features and a significant change.
The where block now allows you to specify conditions using traditional ruby syntax.
Select[:column1].from[:table1, :table2].where doThis change creates very nice looking code in the where block, but I'm not entirely sure it's a step in the right direction. While it looks great in the above example it also allows you to use variables, which can be confusing.
table1.column1 >= 1
table1.column2 <= 20
table1.column3 = table2.column1
table1.column4 = 'foo'
some_val = 1In the above example column1 and some_val look very similar, but create very different output in the generated sql string. The alternative is to use the existing equal syntax.
column1 = some_val
end.to_sql #=> "select column1 from table1 where column1 = 1
Select[:column1].from[:table1].where doIn the previous example it is very clear that column1 is a column and some_val is a variable. The problem with this solution is that it begins to fall down when you consider <=, >=, etc. To support conditions with these operators we would have needed to implement the following (arguably ugly) syntax.
equal :column1, some_val
Select[:column1].from[:table1].where doWhen faced with this decision we opted for the example that simply allowed ruby syntax.
less_than_equal :column1, some_val
The not_null method was added to the options available in where conditions.
Select[:column1].from[:table1].where doThe is_not_in method was added to String, Numeric, and Symbol.
end.to_sql #=> "select column1 from table1 where column2 is not null"
Select[:column1].from[:table1].where doTable and column aliasing was also added in this release.
end.to_sql #=> "select column1 from table1 where column1 not in (select column1 from table2)"
Select[:column1 => :total].from[:table1 => :results].to_sql #=> "select column1 as total from table1 as results"sqldsl 1.2.2 is available via a gem install.
> gem install sqldsl