Parent

Class Index [+]

Quicksearch

Hash

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

Public Instance Methods

&(ce) click to toggle source

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 102
102:   def &(ce)
103:     ::Sequel::SQL::BooleanExpression.new(:AND, self, ce)
104:   end
case(*args) click to toggle source

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 132
132:   def case(*args)
133:     ::Sequel::SQL::CaseExpression.new(to_a, *args)
134:   end
hstore() click to toggle source

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 293
293:   def hstore
294:     Sequel::Postgres::HStore.new(self)
295:   end
pg_json() click to toggle source

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 175
175:   def pg_json
176:     Sequel::Postgres::JSONHash.new(self)
177:   end
sql_expr() click to toggle source

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 142
142:   def sql_expr
143:     ::Sequel::SQL::BooleanExpression.from_value_pairs(self)
144:   end
sql_negate() click to toggle source

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 151
151:   def sql_negate
152:     ::Sequel::SQL::BooleanExpression.from_value_pairs(self, :AND, true)
153:   end
sql_or() click to toggle source

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 160
160:   def sql_or
161:     ::Sequel::SQL::BooleanExpression.from_value_pairs(self, :OR)
162:   end
|(ce) click to toggle source

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 112
112:   def |(ce)
113:     ::Sequel::SQL::BooleanExpression.new(:OR, self, ce)
114:   end
~() click to toggle source

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 121
121:   def ~
122:     ::Sequel::SQL::BooleanExpression.from_value_pairs(self, :OR, true)
123:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.