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

-(other)

Delete entries from an hstore using the subtraction operator:

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

[Source]

        # File lib/sequel/extensions/pg_hstore_ops.rb, line 83
    83:       def -(other)
    84:         HStoreOp.new(super)
    85:       end

[](key)

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 90
    90:       def [](key)
    91:         Sequel::SQL::StringExpression.new(:NOOP, Sequel::SQL::PlaceholderLiteralString.new(LOOKUP, [value, key]))
    92:       end

akeys()

Alias for keys

avals()

Alias for values

concat(other)

Alias for merge

contain_all(other)

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 97
    97:       def contain_all(other)
    98:         bool_op(CONTAIN_ALL, other)
    99:       end

contain_any(other)

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 104
    104:       def contain_any(other)
    105:         bool_op(CONTAIN_ANY, other)
    106:       end

contained_by(other)

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 118
    118:       def contained_by(other)
    119:         bool_op(CONTAINED_BY, other)
    120:       end

contains(other)

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 111
    111:       def contains(other)
    112:         bool_op(CONTAINS, other)
    113:       end

defined(key)

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 125
    125:       def defined(key)
    126:         Sequel::SQL::BooleanExpression.new(:NOOP, function(:defined, key))
    127:       end

delete(key)

Delete the matching entries from the receiver:

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

[Source]

         # File lib/sequel/extensions/pg_hstore_ops.rb, line 132
    132:       def delete(key)
    133:         HStoreOp.new(function(:delete, key))
    134:       end

each()

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 139
    139:       def each
    140:         function(:each)
    141:       end

exist?(key)

Alias for has_key?

has_key?(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 146
    146:       def has_key?(key)
    147:         bool_op(HAS_KEY, key)
    148:       end

hstore()

Return the receiver.

[Source]

         # File lib/sequel/extensions/pg_hstore_ops.rb, line 155
    155:       def hstore
    156:         self
    157:       end

include?(key)

Alias for has_key?

key?(key)

Alias for has_key?

keys()

Return the keys as a PostgreSQL array:

      hstore_op.keys # akeys(hstore)

[Source]

         # File lib/sequel/extensions/pg_hstore_ops.rb, line 162
    162:       def keys
    163:         function(:akeys)
    164:       end

member?(key)

Alias for has_key?

merge(other)

Merge a given hstore into the receiver:

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

[Source]

         # File lib/sequel/extensions/pg_hstore_ops.rb, line 170
    170:       def merge(other)
    171:         HStoreOp.new(Sequel::SQL::PlaceholderLiteralString.new(CONCAT, [self, other]))
    172:       end

populate(record)

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 178
    178:       def populate(record)
    179:         SQL::Function.new(:populate_record, record, self)
    180:       end

record_set(record)

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 185
    185:       def record_set(record)
    186:         Sequel::SQL::PlaceholderLiteralString.new(RECORD_SET, [record, value])
    187:       end

skeys()

Return the keys as a PostgreSQL set:

      hstore_op.skeys # skeys(hstore)

[Source]

         # File lib/sequel/extensions/pg_hstore_ops.rb, line 192
    192:       def skeys
    193:         function(:skeys)
    194:       end

slice(keys)

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 199
    199:       def slice(keys)
    200:         HStoreOp.new(function(:slice, keys))
    201:       end

svals()

Return the values as a PostgreSQL set:

      hstore_op.svals # svals(hstore)

[Source]

         # File lib/sequel/extensions/pg_hstore_ops.rb, line 206
    206:       def svals
    207:         function(:svals)
    208:       end

to_array()

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 214
    214:       def to_array
    215:         function(:hstore_to_array)
    216:       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)

[Source]

         # File lib/sequel/extensions/pg_hstore_ops.rb, line 222
    222:       def to_matrix
    223:         function(:hstore_to_matrix)
    224:       end

values()

Return the values as a PostgreSQL array:

      hstore_op.values # avals(hstore)

[Source]

         # File lib/sequel/extensions/pg_hstore_ops.rb, line 229
    229:       def values
    230:         function(:avals)
    231:       end

[Validate]