Class Sequel::Postgres::HStoreOp
In: lib/sequel/extensions/pg_hstore_ops.rb
Parent: 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

Methods

-   []   akeys   avals   concat   contain_all   contain_any   contained_by   contains   defined   delete   each   exist?   has_key?   hstore   include?   key?   keys   member?   merge   populate   record_set   skeys   slice   svals   to_array   to_matrix   values  

Constants

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

Public Instance methods

Delete entries from an hstore using the subtraction operator:

  hstore_op - 'a' # (hstore - 'a')

[Source]

    # File lib/sequel/extensions/pg_hstore_ops.rb, line 84
84:       def -(other)
85:         other = if other.is_a?(String) && !other.is_a?(Sequel::LiteralString)
86:           Sequel.cast_string(other)
87:         else
88:           wrap_input_array(wrap_input_hash(other))
89:         end
90:         HStoreOp.new(super)
91:       end

Lookup the value for the given key in an hstore:

  hstore_op['a'] # (hstore -> 'a')

[Source]

     # File lib/sequel/extensions/pg_hstore_ops.rb, line 96
 96:       def [](key)
 97:         v = Sequel::SQL::PlaceholderLiteralString.new(LOOKUP, [value, wrap_input_array(key)])
 98:         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))
 99:           wrap_output_array(v)
100:         else
101:           Sequel::SQL::StringExpression.new(:NOOP, v)
102:         end
103:       end
akeys()

Alias for keys

avals()

Alias for values

concat(other)

Alias for merge

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

  hstore_op.contain_all(:a) # (hstore ?& a)

[Source]

     # File lib/sequel/extensions/pg_hstore_ops.rb, line 108
108:       def contain_all(other)
109:         bool_op(CONTAIN_ALL, wrap_input_array(other))
110:       end

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

  hstore_op.contain_any(:a) # (hstore ?| a)

[Source]

     # File lib/sequel/extensions/pg_hstore_ops.rb, line 115
115:       def contain_any(other)
116:         bool_op(CONTAIN_ANY, wrap_input_array(other))
117:       end

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

  hstore_op.contained_by(:h) # (hstore <@ h)

[Source]

     # File lib/sequel/extensions/pg_hstore_ops.rb, line 129
129:       def contained_by(other)
130:         bool_op(CONTAINED_BY, wrap_input_hash(other))
131:       end

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

  hstore_op.contains(:h) # (hstore @> h)

[Source]

     # File lib/sequel/extensions/pg_hstore_ops.rb, line 122
122:       def contains(other)
123:         bool_op(CONTAINS, wrap_input_hash(other))
124:       end

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

  hstore_op.defined('a') # defined(hstore, 'a')

[Source]

     # File lib/sequel/extensions/pg_hstore_ops.rb, line 136
136:       def defined(key)
137:         Sequel::SQL::BooleanExpression.new(:NOOP, function(:defined, key))
138:       end

Delete the matching entries from the receiver:

  hstore_op.delete('a') # delete(hstore, 'a')

[Source]

     # File lib/sequel/extensions/pg_hstore_ops.rb, line 143
143:       def delete(key)
144:         HStoreOp.new(function(:delete, wrap_input_array(wrap_input_hash(key))))
145:       end

Transform the receiver into a set of keys and values:

  hstore_op.each # each(hstore)

[Source]

     # File lib/sequel/extensions/pg_hstore_ops.rb, line 150
150:       def each
151:         function(:each)
152:       end
exist?(key)

Alias for has_key?

Check if the receiver contains the given key:

  hstore_op.has_key?('a') # (hstore ? 'a')

[Source]

     # File lib/sequel/extensions/pg_hstore_ops.rb, line 157
157:       def has_key?(key)
158:         bool_op(HAS_KEY, key)
159:       end

Return the receiver.

[Source]

     # File lib/sequel/extensions/pg_hstore_ops.rb, line 166
166:       def hstore
167:         self
168:       end
include?(key)

Alias for has_key?

key?(key)

Alias for has_key?

Return the keys as a PostgreSQL array:

  hstore_op.keys # akeys(hstore)

[Source]

     # File lib/sequel/extensions/pg_hstore_ops.rb, line 173
173:       def keys
174:         wrap_output_array(function(:akeys))
175:       end
member?(key)

Alias for has_key?

Merge a given hstore into the receiver:

  hstore_op.merge(:a) # (hstore || a)

[Source]

     # File lib/sequel/extensions/pg_hstore_ops.rb, line 181
181:       def merge(other)
182:         HStoreOp.new(Sequel::SQL::PlaceholderLiteralString.new(CONCAT, [self, wrap_input_hash(other)]))
183:       end

Create a new record populated with entries from the receiver:

  hstore_op.populate(:a) # populate_record(a, hstore)

[Source]

     # File lib/sequel/extensions/pg_hstore_ops.rb, line 189
189:       def populate(record)
190:         SQL::Function.new(:populate_record, record, self)
191:       end

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

  hstore_op.record_set(:a) # (a #= hstore)

[Source]

     # File lib/sequel/extensions/pg_hstore_ops.rb, line 196
196:       def record_set(record)
197:         Sequel::SQL::PlaceholderLiteralString.new(RECORD_SET, [record, value])
198:       end

Return the keys as a PostgreSQL set:

  hstore_op.skeys # skeys(hstore)

[Source]

     # File lib/sequel/extensions/pg_hstore_ops.rb, line 203
203:       def skeys
204:         function(:skeys)
205:       end

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

  hstore_op.slice(:a) # slice(hstore, a)

[Source]

     # File lib/sequel/extensions/pg_hstore_ops.rb, line 210
210:       def slice(keys)
211:         HStoreOp.new(function(:slice, wrap_input_array(keys)))
212:       end

Return the values as a PostgreSQL set:

  hstore_op.svals # svals(hstore)

[Source]

     # File lib/sequel/extensions/pg_hstore_ops.rb, line 217
217:       def svals
218:         function(:svals)
219:       end

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

  hstore_op.to_array # hstore_to_array(hstore)

[Source]

     # File lib/sequel/extensions/pg_hstore_ops.rb, line 225
225:       def to_array
226:         wrap_output_array(function(:hstore_to_array))
227:       end

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

  hstore_op.to_matrix # hstore_to_matrix(hstore)

[Source]

     # File lib/sequel/extensions/pg_hstore_ops.rb, line 233
233:       def to_matrix
234:         wrap_output_array(function(:hstore_to_matrix))
235:       end

Return the values as a PostgreSQL array:

  hstore_op.values # avals(hstore)

[Source]

     # File lib/sequel/extensions/pg_hstore_ops.rb, line 240
240:       def values
241:         wrap_output_array(function(:avals))
242:       end

[Validate]