Path: | lib/sequel/extensions/query_literals.rb |
Last Update: | Fri Jul 13 14:52:09 +0000 2012 |
The query_literals extension changes Sequel‘s default behavior of the select, order and group methods so that if the first argument is a regular string, it is treated as a literal string, with the rest of the arguments (if any) treated as placeholder values. This allows you to write code such as:
DB[:table].select('a, b, ?', 2).group('a, b').order('c')
The default Sequel behavior would literalize that as:
SELECT 'a, b, ?', 2 FROM table GROUP BY 'a, b' ORDER BY 'c'
Using this extension changes the literalization to:
SELECT a, b, 2, FROM table GROUP BY a, b ORDER BY c
This extension makes select, group, and order methods operate like filter methods, which support the same interface.
There are very few places where Sequel‘s default behavior is desirable in this area, but for backwards compatibility, the defaults won‘t be changed until the next major release.
Loading this extension does nothing by default except make the Sequel::QueryLiterals module available. You can extend specific datasets with this module:
ds = DB[:table] ds.extend(Sequel::QueryLiterals)
Order you can extend all of a database‘s datasets with it, which is probably the desired behavior if you are using this extension:
DB.extend_datasets(Sequel::QueryLiterals)