Breaking Changes:
Table and column aliasing is now done with an 'as' method instead of using hashes. This change was necessary since column order is important and hashes are unordered.
irb> Select[:column1.as(:book), 1.as(:total), 'foo'.as(:constant)].to_sqlEquality in the where clause has been changed from a single equals to double equals. I personally preferred the single equals; however, it broke in scenarios where columns were not prefixed by table names. The previous solution did not work because ruby assigned a local variable instead of raising a method_missing and allowing the ReceiveAny class to handle the assignment.
=> "select column1 as book, 1 as total, 'foo' as constant"
irb> Select.all.from[:table1.as(:aliased_table_name)].to_sql
=> "select * from table1 aliased_table_name"
The new syntax is the same, except it uses == instead of =.
Select[:column1].from[:table1].where doNew Feature:
column1 == 99
end.to_sql
=> "select column1 from table1 where column1 = 99"
Inner Joins are now also supported
Select.all.from[:t1.as(:a)].inner_join[:t2.as(:b)].on doBug Fix:
a.id == b.id
end.inner_join[:t3.as(:c)].on do
b.id2 == c.id
end.to_sql
=> "select * from t1 a inner join t2 b on a.id = b.id inner join t3 c on b.id2 = c.id"
Or conditions are surrounded by parenthesis.
Select[:column1].from[:table1].where do
column1.equal 0
end.or do
column1 > 100
end.to_sql
=> "select column1 from table1 where column1 = 0 or (column1 > 100)"
Hello,
ReplyDeleteFinally I got time to use sqldsl! I found it really interesting and fits in my project.
I have read the source code and I'm developing the ".and" method and support for "like" in WHERE clauses.
If you want I can send you the code or add it to rubyforge svn.
Thanks,
Sergio Espeja.