| Class | Hash |
| In: |
lib/sequel/extensions/pg_hstore.rb
lib/sequel/extensions/core_extensions.rb lib/sequel/extensions/pg_json.rb lib/sequel/deprecated_core_extensions.rb |
| Parent: | Object |
# File lib/sequel/deprecated_core_extensions.rb, line 44
44: def &(ce)
45: Sequel::Deprecation.deprecate('Hash#&', 'Please use Sequel.& instead, or Sequel.extension(:core_extensions) to continue using it')
46: ::Sequel::SQL::BooleanExpression.new(:AND, self, ce)
47: end
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
# File lib/sequel/extensions/core_extensions.rb, line 108
108: def &(ce)
109: ::Sequel::SQL::BooleanExpression.new(:AND, self, ce)
110: 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
# File lib/sequel/extensions/core_extensions.rb, line 138
138: def case(*args)
139: ::Sequel::SQL::CaseExpression.new(to_a, *args)
140: end
# File lib/sequel/deprecated_core_extensions.rb, line 59
59: def case(*args)
60: Sequel::Deprecation.deprecate('Hash#case', 'Please use Sequel.case instead, or Sequel.extension(:core_extensions) to continue using it')
61: ::Sequel::SQL::CaseExpression.new(to_a, *args)
62: end
Create a new HStore using the receiver as the input hash. Note that the HStore created will not use the receiver as the backing store, since it has to modify the hash. To get the new backing store, use:
hash.hstore.to_hash
# File lib/sequel/extensions/pg_hstore.rb, line 339
339: def hstore
340: Sequel::Postgres::HStore.new(self)
341: end
Return a Sequel::Postgres::JSONHash proxy to the receiver. This is mostly useful as a short cut for creating JSONHash objects that didn‘t come from the database.
# File lib/sequel/extensions/pg_json.rb, line 217
217: def pg_json
218: Sequel::Postgres::JSONHash.new(self)
219: end
# File lib/sequel/deprecated_core_extensions.rb, line 64
64: def sql_expr
65: Sequel::Deprecation.deprecate('Hash#sql_expr', 'Please use Sequel.expr instead, or Sequel.extension(:core_extensions) to continue using it')
66: ::Sequel::SQL::BooleanExpression.from_value_pairs(self)
67: 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)
# File lib/sequel/extensions/core_extensions.rb, line 148
148: def sql_expr
149: ::Sequel::SQL::BooleanExpression.from_value_pairs(self)
150: 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)
# File lib/sequel/extensions/core_extensions.rb, line 157
157: def sql_negate
158: ::Sequel::SQL::BooleanExpression.from_value_pairs(self, :AND, true)
159: end
# File lib/sequel/deprecated_core_extensions.rb, line 69
69: def sql_negate
70: Sequel::Deprecation.deprecate('Hash#sql_negate', 'Please use Sequel.negate instead, or Sequel.extension(:core_extensions) to continue using it')
71: ::Sequel::SQL::BooleanExpression.from_value_pairs(self, :AND, true)
72: 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)
# File lib/sequel/extensions/core_extensions.rb, line 166
166: def sql_or
167: ::Sequel::SQL::BooleanExpression.from_value_pairs(self, :OR)
168: end
# File lib/sequel/deprecated_core_extensions.rb, line 74
74: def sql_or
75: Sequel::Deprecation.deprecate('Hash#sql_or', 'Please use Sequel.or instead, or Sequel.extension(:core_extensions) to continue using it')
76: ::Sequel::SQL::BooleanExpression.from_value_pairs(self, :OR)
77: 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
# File lib/sequel/extensions/core_extensions.rb, line 118
118: def |(ce)
119: ::Sequel::SQL::BooleanExpression.new(:OR, self, ce)
120: end
# File lib/sequel/deprecated_core_extensions.rb, line 49
49: def |(ce)
50: Sequel::Deprecation.deprecate('Hash#|', 'Please use Sequel.| instead, or Sequel.extension(:core_extensions) to continue using it')
51: ::Sequel::SQL::BooleanExpression.new(:OR, self, ce)
52: 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)
# File lib/sequel/extensions/core_extensions.rb, line 127
127: def ~
128: ::Sequel::SQL::BooleanExpression.from_value_pairs(self, :OR, true)
129: end