class String

  1. lib/sequel/extensions/core_extensions.rb

Sequel extends String to add methods to implement the SQL DSL.

Methods

Public Instance

  1. lit
  2. to_sequel_blob

Public Instance methods

lit (*args)

Converts a string into a Sequel::LiteralString, in order to override string literalization, e.g.:

DB[:items].filter(:abc => 'def').sql #=>
  "SELECT * FROM items WHERE (abc = 'def')"

DB[:items].filter(:abc => 'def'.lit).sql #=>
  "SELECT * FROM items WHERE (abc = def)"

You can also provide arguments, to create a Sequel::SQL::PlaceholderLiteralString:

DB[:items].select{|o| o.count('DISTINCT ?'.lit(:a))}.sql #=>
  "SELECT count(DISTINCT a) FROM items"
[show source]
# File lib/sequel/extensions/core_extensions.rb, line 187
def lit(*args)
  args.empty? ? Sequel::LiteralString.new(self) : Sequel::SQL::PlaceholderLiteralString.new(self, args)
end
to_sequel_blob ()

Returns a Sequel::SQL::Blob that holds the same data as this string. Blobs provide proper escaping of binary data.

[show source]
# File lib/sequel/extensions/core_extensions.rb, line 193
def to_sequel_blob
  ::Sequel::SQL::Blob.new(self)
end