module Sequel::CoreRefinements

  1. lib/sequel/extensions/core_refinements.rb
  2. lib/sequel/extensions/pg_array.rb
  3. lib/sequel/extensions/pg_array_ops.rb
  4. lib/sequel/extensions/pg_hstore.rb
  5. lib/sequel/extensions/pg_hstore_ops.rb
  6. lib/sequel/extensions/pg_json.rb
  7. lib/sequel/extensions/pg_json_ops.rb
  8. lib/sequel/extensions/pg_range.rb
  9. lib/sequel/extensions/pg_range_ops.rb
  10. lib/sequel/extensions/pg_row.rb
  11. lib/sequel/extensions/pg_row_ops.rb
  12. show all
Parent: Sequel

Included modules

  1. Sequel::SQL::AliasMethods
  2. Sequel::SQL::CastMethods
  3. Sequel::SQL::OrderMethods
  4. Sequel::SQL::BooleanMethods
  5. Sequel::SQL::NumericMethods
  6. Sequel::SQL::QualifyingMethods
  7. Sequel::SQL::StringMethods
  8. Sequel::SQL::SubscriptMethods
  9. Sequel::SQL::ComplexExpressionMethods
  10. Sequel::Postgres::ArrayOpMethods
  11. Sequel::Postgres::HStoreOpMethods
  12. Sequel::Postgres::JSONOpMethods
  13. Sequel::Postgres::RangeOpMethods
  14. Sequel::Postgres::PGRowOp::ExpressionMethods

Public Instance methods

& (ce)

Return a Sequel::SQL::BooleanExpression created from this hash, matching all of the conditions in this hash and the condition specified by the given argument.

{:a=>1} & :b # SQL: a = 1 AND b
{:a=>true} & ~:b # SQL: a IS TRUE AND NOT b
[show source]
# File lib/sequel/extensions/core_refinements.rb, line 98
def &(ce)
  ::Sequel::SQL::BooleanExpression.new(:AND, self, ce)
end
case (*args)

Return a Sequel::SQL::CaseExpression with this array as the conditions and the given default value and expression.

[[{:a=>[2,3]}, 1]].case(0) # SQL: CASE WHEN a IN (2, 3) THEN 1 ELSE 0 END
[[:a, 1], [:b, 2]].case(:d, :c) # SQL: CASE c WHEN a THEN 1 WHEN b THEN 2 ELSE d END
[show source]
# File lib/sequel/extensions/core_refinements.rb, line 29
def case(*args)
  ::Sequel::SQL::CaseExpression.new(self, *args)
end
hstore ()
[show source]
# File lib/sequel/extensions/pg_hstore.rb, line 350
def hstore
  Sequel::Postgres::HStore.new(self)
end
identifier ()

Returns receiver wrapped in an Sequel::SQL::Identifier. Usually used to prevent splitting the symbol.

:a__b # SQL: "a"."b"
:a__b.identifier # SQL: "a__b"
[show source]
# File lib/sequel/extensions/core_refinements.rb, line 205
def identifier
  Sequel::SQL::Identifier.new(self)
end
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_refinements.rb, line 178
def lit(*args)
  args.empty? ? Sequel::LiteralString.new(self) : Sequel::SQL::PlaceholderLiteralString.new(self, args)
end
pg_array (type=nil)
[show source]
# File lib/sequel/extensions/pg_array.rb, line 617
def pg_array(type=nil)
  Sequel::Postgres::PGArray.new(self, type)
end
pg_json ()
[show source]
# File lib/sequel/extensions/pg_json.rb, line 236
def pg_json
  Sequel::Postgres::JSONArray.new(self)
end
pg_range (db_type=nil)
[show source]
# File lib/sequel/extensions/pg_range.rb, line 535
def pg_range(db_type=nil)
  Sequel::Postgres::PGRange.from_range(self, db_type)
end
pg_row ()
[show source]
# File lib/sequel/extensions/pg_row.rb, line 605
def pg_row
  Sequel::Postgres::PGRow::ArrayRow.new(self)
end
sql_expr ()

Return a Sequel::SQL::BooleanExpression created from this array, matching all of the conditions. Rarely do you need to call this explicitly, as Sequel generally assumes that arrays of two element arrays specify this type of condition. One case where it can be necessary to use this is if you are using the object as a value in a filter hash and want to use the = operator instead of the IN operator (which is used by default for arrays of two element arrays).

[[:a, true]].sql_expr # SQL: a IS TRUE
[[:a, 1], [:b, [2, 3]]].sql_expr # SQL: a = 1 AND b IN (2, 3)
[show source]
# File lib/sequel/extensions/core_refinements.rb, line 55
def sql_expr
  Sequel.expr(self)
end
sql_function (*args)

Returns a Sequel::SQL::Function with this as the function name, and the given arguments. This is aliased as Symbol#[] if the RUBY_VERSION is less than 1.9.0. Ruby 1.9 defines Symbol#[], and Sequel doesn’t override methods defined by ruby itself.

:now.sql_function # SQL: now()
:sum.sql_function(:a) # SQL: sum(a)
:concat.sql_function(:a, :b) # SQL: concat(a, b)
[show source]
# File lib/sequel/extensions/core_refinements.rb, line 217
def sql_function(*args)
  Sequel::SQL::Function.new(self, *args)
end
sql_negate ()

Return a Sequel::SQL::BooleanExpression created from this array, matching none of the conditions.

[[:a, true]].sql_negate # SQL: a IS NOT TRUE
[[:a, 1], [:b, [2, 3]]].sql_negate # SQL: a != 1 AND b NOT IN (2, 3)
[show source]
# File lib/sequel/extensions/core_refinements.rb, line 64
def sql_negate
  Sequel.negate(self)
end
sql_or ()

Return a Sequel::SQL::BooleanExpression created from this array, matching any of the conditions.

[[:a, true]].sql_or # SQL: a IS TRUE
[[:a, 1], [:b, [2, 3]]].sql_or # SQL: a = 1 OR b IN (2, 3)
[show source]
# File lib/sequel/extensions/core_refinements.rb, line 73
def sql_or
  Sequel.or(self)
end
sql_string_join (joiner=nil)

Return a Sequel::SQL::StringExpression representing an SQL string made up of the concatenation of this array’s elements. If an argument is passed it is used in between each element of the array in the SQL concatenation.

[:a].sql_string_join # SQL: a
[:a, :b].sql_string_join # SQL: a || b
[:a, 'b'].sql_string_join # SQL: a || 'b'
['a', :b].sql_string_join(' ') # SQL: 'a' || ' ' || b
[show source]
# File lib/sequel/extensions/core_refinements.rb, line 86
def sql_string_join(joiner=nil)
  Sequel.join(self, joiner)
end
sql_value_list ()

Return a Sequel::SQL::ValueList created from this array. Used if this array contains all two element arrays and you want it treated as an SQL value list (IN predicate) instead of as a conditions specifier (similar to a hash). This is not necessary if you are using this array as a value in a filter, but may be necessary if you are using it as a value with placeholder SQL:

DB[:a].filter([:a, :b]=>[[1, 2], [3, 4]]) # SQL: (a, b) IN ((1, 2), (3, 4))
DB[:a].filter('(a, b) IN ?', [[1, 2], [3, 4]]) # SQL: (a, b) IN ((1 = 2) AND (3 = 4))
DB[:a].filter('(a, b) IN ?', [[1, 2], [3, 4]].sql_value_list) # SQL: (a, b) IN ((1, 2), (3, 4))
[show source]
# File lib/sequel/extensions/core_refinements.rb, line 42
def sql_value_list
  ::Sequel::SQL::ValueList.new(self)
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_refinements.rb, line 184
def to_sequel_blob
  ::Sequel::SQL::Blob.new(self)
end
| (ce)

Return a Sequel::SQL::BooleanExpression created from this hash, matching all of the conditions in this hash or the condition specified by the given argument.

{:a=>1} | :b # SQL: a = 1 OR b
{:a=>true} | ~:b # SQL: a IS TRUE OR NOT b
[show source]
# File lib/sequel/extensions/core_refinements.rb, line 108
def |(ce)
  ::Sequel::SQL::BooleanExpression.new(:OR, self, ce)
end
~ ()

Return a Sequel::SQL::BooleanExpression created from this array, not matching all of the conditions.

~[[:a, true]] # SQL: a IS NOT TRUE
~[[:a, 1], [:b, [2, 3]]] # SQL: a != 1 OR b NOT IN (2, 3)
[show source]
# File lib/sequel/extensions/core_refinements.rb, line 20
def ~
  Sequel.~(self)
end