class Sequel::Postgres::HStoreOp

  1. lib/sequel/extensions/pg_hstore_ops.rb
Superclass: Sequel::SQL::Wrapper

The HStoreOp class is a simple container for a single object that defines methods that yield Sequel expression objects representing PostgreSQL hstore operators and functions.

In the method documentation examples, assume that:

hstore_op = :hstore.hstore

Constants

CONCAT = ["(".freeze, " || ".freeze, ")".freeze].freeze  
CONTAINED_BY = ["(".freeze, " <@ ".freeze, ")".freeze].freeze  
CONTAINS = ["(".freeze, " @> ".freeze, ")".freeze].freeze  
CONTAIN_ALL = ["(".freeze, " ?& ".freeze, ")".freeze].freeze  
CONTAIN_ANY = ["(".freeze, " ?| ".freeze, ")".freeze].freeze  
HAS_KEY = ["(".freeze, " ? ".freeze, ")".freeze].freeze  
LOOKUP = ["(".freeze, " -> ".freeze, ")".freeze].freeze  
RECORD_SET = ["(".freeze, " #= ".freeze, ")".freeze].freeze  

Public Instance Aliases

akeys -> keys
avals -> values
concat -> merge
exist? -> has_key?
include? -> has_key?
key? -> has_key?
member? -> has_key?

Public Instance methods

-(other)

Delete entries from an hstore using the subtraction operator:

hstore_op - 'a' # (hstore - 'a')
[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
117 def -(other)
118   other = if other.is_a?(String) && !other.is_a?(Sequel::LiteralString)
119     Sequel.cast_string(other)
120   else
121     wrap_input_array(wrap_input_hash(other))
122   end
123   HStoreOp.new(super)
124 end
[](key)

Lookup the value for the given key in an hstore:

hstore_op['a'] # (hstore -> 'a')
[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
129 def [](key)
130   if key.is_a?(Array) || (defined?(Sequel::Postgres::PGArray) && key.is_a?(Sequel::Postgres::PGArray)) || (defined?(Sequel::Postgres::ArrayOp) && key.is_a?(Sequel::Postgres::ArrayOp))
131     wrap_output_array(Sequel::SQL::PlaceholderLiteralString.new(LOOKUP, [value, wrap_input_array(key)]))
132   else
133     v = case @value
134     when Symbol, SQL::Identifier, SQL::QualifiedIdentifier
135       HStoreSubscriptOp.new(self, key)
136     else
137       Sequel::SQL::PlaceholderLiteralString.new(LOOKUP, [value, key])
138     end
139     Sequel::SQL::StringExpression.new(:NOOP, v)
140   end
141 end
contain_all(other)

Check if the receiver contains all of the keys in the given array:

hstore_op.contain_all(:a) # (hstore ?& a)
[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
146 def contain_all(other)
147   bool_op(CONTAIN_ALL, wrap_input_array(other))
148 end
contain_any(other)

Check if the receiver contains any of the keys in the given array:

hstore_op.contain_any(:a) # (hstore ?| a)
[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
153 def contain_any(other)
154   bool_op(CONTAIN_ANY, wrap_input_array(other))
155 end
contained_by(other)

Check if the other hstore contains all entries in the receiver:

hstore_op.contained_by(:h) # (hstore <@ h)
[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
167 def contained_by(other)
168   bool_op(CONTAINED_BY, wrap_input_hash(other))
169 end
contains(other)

Check if the receiver contains all entries in the other hstore:

hstore_op.contains(:h) # (hstore @> h)
[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
160 def contains(other)
161   bool_op(CONTAINS, wrap_input_hash(other))
162 end
defined(key)

Check if the receiver contains a non-NULL value for the given key:

hstore_op.defined('a') # defined(hstore, 'a')
[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
174 def defined(key)
175   Sequel::SQL::BooleanExpression.new(:NOOP, function(:defined, key))
176 end
delete(key)

Delete the matching entries from the receiver:

hstore_op.delete('a') # delete(hstore, 'a')
[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
181 def delete(key)
182   HStoreOp.new(function(:delete, wrap_input_array(wrap_input_hash(key))))
183 end
each()

Transform the receiver into a set of keys and values:

hstore_op.each # each(hstore)
[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
188 def each
189   function(:each)
190 end
has_key?(key)

Check if the receiver contains the given key:

hstore_op.has_key?('a') # (hstore ? 'a')
[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
195 def has_key?(key)
196   bool_op(HAS_KEY, key)
197 end
hstore()

Return the receiver.

[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
204 def hstore
205   self
206 end
keys()

Return the keys as a PostgreSQL array:

hstore_op.keys # akeys(hstore)
[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
211 def keys
212   wrap_output_array(function(:akeys))
213 end
merge(other)

Merge a given hstore into the receiver:

hstore_op.merge(:a) # (hstore || a)
[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
219 def merge(other)
220   HStoreOp.new(Sequel::SQL::PlaceholderLiteralString.new(CONCAT, [self, wrap_input_hash(other)]))
221 end
populate(record)

Create a new record populated with entries from the receiver:

hstore_op.populate(:a) # populate_record(a, hstore)
[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
227 def populate(record)
228   SQL::Function.new(:populate_record, record, self)
229 end
record_set(record)

Update the values in a record using entries in the receiver:

hstore_op.record_set(:a) # (a #= hstore)
[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
234 def record_set(record)
235   Sequel::SQL::PlaceholderLiteralString.new(RECORD_SET, [record, value])
236 end
skeys()

Return the keys as a PostgreSQL set:

hstore_op.skeys # skeys(hstore)
[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
241 def skeys
242   function(:skeys)
243 end
slice(keys)

Return an hstore with only the keys in the given array:

hstore_op.slice(:a) # slice(hstore, a)
[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
248 def slice(keys)
249   HStoreOp.new(function(:slice, wrap_input_array(keys)))
250 end
svals()

Return the values as a PostgreSQL set:

hstore_op.svals # svals(hstore)
[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
255 def svals
256   function(:svals)
257 end
to_array()

Return a flattened array of the receiver with alternating keys and values:

hstore_op.to_array # hstore_to_array(hstore)
[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
263 def to_array
264   wrap_output_array(function(:hstore_to_array))
265 end
to_matrix()

Return a nested array of the receiver, with arrays of 2 element (key/value) arrays:

hstore_op.to_matrix # hstore_to_matrix(hstore)
[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
271 def to_matrix
272   wrap_output_array(function(:hstore_to_matrix))
273 end
values()

Return the values as a PostgreSQL array:

hstore_op.values # avals(hstore)
[show source]
    # File lib/sequel/extensions/pg_hstore_ops.rb
278 def values
279   wrap_output_array(function(:avals))
280 end