Method: Sequel::SQL::Builders#lit
- Defined in:
- lib/sequel/sql.rb
#lit(s, *args) ⇒ Object
Converts a string into a Sequel::LiteralString
, in order to override string literalization, e.g.:
DB[:items].where(abc: 'def').sql #=>
"SELECT * FROM items WHERE (abc = 'def')"
DB[:items].where(abc: Sequel.lit('def')).sql #=>
"SELECT * FROM items WHERE (abc = def)"
You can also provide arguments, to create a Sequel::SQL::PlaceholderLiteralString
:
DB[:items].select{|o| o.count(Sequel.lit('DISTINCT ?', :a))}.sql #=>
"SELECT count(DISTINCT a) FROM items"
600 601 602 603 604 605 606 607 608 609 610 |
# File 'lib/sequel/sql.rb', line 600 def lit(s, *args) if args.empty? if s.is_a?(LiteralString) s else LiteralString.new(s) end else SQL::PlaceholderLiteralString.new(s, args) end end |