Module Sequel::CoreRefinements
In: lib/sequel/extensions/pg_row.rb
lib/sequel/extensions/pg_row_ops.rb
lib/sequel/extensions/pg_hstore_ops.rb
lib/sequel/extensions/pg_inet_ops.rb
lib/sequel/extensions/pg_range.rb
lib/sequel/extensions/pg_array_ops.rb
lib/sequel/extensions/pg_json_ops.rb
lib/sequel/extensions/core_refinements.rb
lib/sequel/extensions/pg_range_ops.rb
lib/sequel/extensions/pg_array.rb
lib/sequel/extensions/pg_hstore.rb
lib/sequel/extensions/pg_json.rb

Methods

&   case   case   hstore   identifier   lit   pg_array   pg_json   pg_json   pg_jsonb   pg_jsonb   pg_range   pg_row   sql_expr   sql_expr   sql_function   sql_negate   sql_negate   sql_or   sql_or   sql_string_join   sql_value_list   to_sequel_blob   |   ~   ~  

Included Modules

Sequel::Postgres::PGRowOp::ExpressionMethods Sequel::Postgres::HStoreOpMethods Sequel::Postgres::InetOpMethods Sequel::Postgres::ArrayOpMethods Sequel::Postgres::JSONOpMethods Sequel::SQL::AliasMethods Sequel::SQL::CastMethods Sequel::SQL::AliasMethods Sequel::SQL::CastMethods Sequel::SQL::OrderMethods Sequel::SQL::BooleanMethods Sequel::SQL::NumericMethods Sequel::SQL::QualifyingMethods Sequel::SQL::StringMethods Sequel::SQL::SubscriptMethods Sequel::SQL::ComplexExpressionMethods Sequel::Postgres::RangeOpMethods

Public Instance methods

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

[Source]

     # File lib/sequel/extensions/core_refinements.rb, line 100
100:     def &(ce)
101:       ::Sequel::SQL::BooleanExpression.new(:AND, self, ce)
102:     end

Return a Sequel::SQL::CaseExpression with this hash as the conditions and the given default value. Note that the order of the conditions will be arbitrary on ruby 1.8, so all conditions should be orthogonal.

  {{: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
                                #  or: CASE c WHEN b THEN 2 WHEN a THEN 1 ELSE d END

[Source]

     # File lib/sequel/extensions/core_refinements.rb, line 130
130:     def case(*args)
131:       ::Sequel::SQL::CaseExpression.new(to_a, *args)
132:     end

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

[Source]

    # File lib/sequel/extensions/core_refinements.rb, line 31
31:     def case(*args)
32:       ::Sequel::SQL::CaseExpression.new(self, *args)
33:     end

[Source]

     # File lib/sequel/extensions/pg_hstore.rb, line 351
351:       def hstore
352:         Sequel::Postgres::HStore.new(self)
353:       end

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"

[Source]

     # File lib/sequel/extensions/core_refinements.rb, line 207
207:     def identifier
208:       Sequel::SQL::Identifier.new(self)
209:     end

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"

[Source]

     # File lib/sequel/extensions/core_refinements.rb, line 180
180:     def lit(*args)
181:       args.empty? ? Sequel::LiteralString.new(self) : Sequel::SQL::PlaceholderLiteralString.new(self, args)
182:     end

[Source]

     # File lib/sequel/extensions/pg_array.rb, line 587
587:       def pg_array(type=nil)
588:         Sequel::Postgres::PGArray.new(self, type)
589:       end

[Source]

     # File lib/sequel/extensions/pg_json.rb, line 347
347:       def pg_json
348:         Sequel::Postgres::JSONArray.new(self)
349:       end

[Source]

     # File lib/sequel/extensions/pg_json.rb, line 357
357:       def pg_json
358:         Sequel::Postgres::JSONHash.new(self)
359:       end

[Source]

     # File lib/sequel/extensions/pg_json.rb, line 351
351:       def pg_jsonb
352:         Sequel::Postgres::JSONBArray.new(self)
353:       end

[Source]

     # File lib/sequel/extensions/pg_json.rb, line 361
361:       def pg_jsonb
362:         Sequel::Postgres::JSONBHash.new(self)
363:       end

[Source]

     # File lib/sequel/extensions/pg_range.rb, line 619
619:       def pg_range(db_type=nil)
620:         Sequel::Postgres::PGRange.from_range(self, db_type)
621:       end

[Source]

     # File lib/sequel/extensions/pg_row.rb, line 609
609:       def pg_row
610:         Sequel::Postgres::PGRow::ArrayRow.new(self)
611:       end

Return a Sequel::SQL::BooleanExpression created from this hash, matching all of the conditions. Rarely do you need to call this explicitly, as Sequel generally assumes that hashes specify this type of condition.

  {:a=>true}.sql_expr # SQL: a IS TRUE
  {:a=>1, :b=>[2, 3]}.sql_expr # SQL: a = 1 AND b IN (2, 3)

[Source]

     # File lib/sequel/extensions/core_refinements.rb, line 140
140:     def sql_expr
141:       ::Sequel::SQL::BooleanExpression.from_value_pairs(self)
142:     end

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)

[Source]

    # File lib/sequel/extensions/core_refinements.rb, line 57
57:     def sql_expr
58:       Sequel[self]
59:     end

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)

[Source]

     # File lib/sequel/extensions/core_refinements.rb, line 219
219:     def sql_function(*args)
220:       Sequel::SQL::Function.new(self, *args)
221:     end

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)

[Source]

    # File lib/sequel/extensions/core_refinements.rb, line 66
66:     def sql_negate
67:       Sequel.negate(self)
68:     end

Return a Sequel::SQL::BooleanExpression created from this hash, 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)

[Source]

     # File lib/sequel/extensions/core_refinements.rb, line 149
149:     def sql_negate
150:       ::Sequel::SQL::BooleanExpression.from_value_pairs(self, :AND, true)
151:     end

Return a Sequel::SQL::BooleanExpression created from this hash, 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)

[Source]

     # File lib/sequel/extensions/core_refinements.rb, line 158
158:     def sql_or
159:       ::Sequel::SQL::BooleanExpression.from_value_pairs(self, :OR)
160:     end

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)

[Source]

    # File lib/sequel/extensions/core_refinements.rb, line 75
75:     def sql_or
76:       Sequel.or(self)
77:     end

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

[Source]

    # File lib/sequel/extensions/core_refinements.rb, line 88
88:     def sql_string_join(joiner=nil)
89:       Sequel.join(self, joiner)
90:     end

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))

[Source]

    # File lib/sequel/extensions/core_refinements.rb, line 44
44:     def sql_value_list
45:       ::Sequel::SQL::ValueList.new(self)
46:     end

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

[Source]

     # File lib/sequel/extensions/core_refinements.rb, line 186
186:     def to_sequel_blob
187:       ::Sequel::SQL::Blob.new(self)
188:     end

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

[Source]

     # File lib/sequel/extensions/core_refinements.rb, line 110
110:     def |(ce)
111:       ::Sequel::SQL::BooleanExpression.new(:OR, self, ce)
112:     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)

[Source]

    # File lib/sequel/extensions/core_refinements.rb, line 22
22:     def ~
23:       Sequel.~(self)
24:     end

Return a Sequel::SQL::BooleanExpression created from this hash, 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)

[Source]

     # File lib/sequel/extensions/core_refinements.rb, line 119
119:     def ~
120:       ::Sequel::SQL::BooleanExpression.from_value_pairs(self, :OR, true)
121:     end

[Validate]