Class: Sequel::Postgres::HStoreOp
- Inherits:
-
SQL::Wrapper
- Object
- SQL::Expression
- SQL::GenericExpression
- SQL::Wrapper
- Sequel::Postgres::HStoreOp
- Defined in:
- lib/sequel/extensions/pg_hstore_ops.rb
Overview
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
Constant Summary collapse
- 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
Instance Attribute Summary
Attributes inherited from SQL::Wrapper
Instance Method Summary collapse
-
#-(other) ⇒ Object
Delete entries from an hstore using the subtraction operator:.
-
#[](key) ⇒ Object
Lookup the value for the given key in an hstore:.
-
#contain_all(other) ⇒ Object
Check if the receiver contains all of the keys in the given array:.
-
#contain_any(other) ⇒ Object
Check if the receiver contains any of the keys in the given array:.
-
#contained_by(other) ⇒ Object
Check if the other hstore contains all entries in the receiver:.
-
#contains(other) ⇒ Object
Check if the receiver contains all entries in the other hstore:.
-
#defined(key) ⇒ Object
Check if the receiver contains a non-NULL value for the given key:.
-
#delete(key) ⇒ Object
Delete the matching entries from the receiver:.
-
#each ⇒ Object
Transform the receiver into a set of keys and values:.
-
#has_key?(key) ⇒ Boolean
(also: #include?, #key?, #member?, #exist?)
Check if the receiver contains the given key:.
-
#hstore ⇒ Object
Return the receiver.
-
#keys ⇒ Object
(also: #akeys)
Return the keys as a PostgreSQL array:.
-
#merge(other) ⇒ Object
(also: #concat)
Merge a given hstore into the receiver:.
-
#populate(record) ⇒ Object
Create a new record populated with entries from the receiver:.
-
#record_set(record) ⇒ Object
Update the values in a record using entries in the receiver:.
-
#skeys ⇒ Object
Return the keys as a PostgreSQL set:.
-
#slice(keys) ⇒ Object
Return an hstore with only the keys in the given array:.
-
#svals ⇒ Object
Return the values as a PostgreSQL set:.
-
#to_array ⇒ Object
Return a flattened array of the receiver with alternating keys and values:.
-
#to_matrix ⇒ Object
Return a nested array of the receiver, with arrays of 2 element (key/value) arrays:.
-
#values ⇒ Object
(also: #avals)
Return the values as a PostgreSQL array:.
Methods inherited from SQL::Wrapper
Methods included from RangeOpMethods
Methods included from ArrayOpMethods
Methods included from PGRowOp::ExpressionMethods
Methods included from SQL::SubscriptMethods
Methods included from SQL::StringMethods
Methods included from SQL::OrderMethods
Methods included from SQL::NumericMethods
Methods included from SQL::ComplexExpressionMethods
#extract, #sql_boolean, #sql_number, #sql_string
Methods included from SQL::CastMethods
#cast, #cast_numeric, #cast_string
Methods included from SQL::BooleanMethods
Methods included from SQL::AliasMethods
Methods inherited from SQL::Expression
#==, attr_reader, #eql?, #hash, inherited, #inspect, #lit, #sql_literal
Constructor Details
This class inherits a constructor from Sequel::SQL::Wrapper
Instance Method Details
#-(other) ⇒ Object
Delete entries from an hstore using the subtraction operator:
hstore_op - 'a' # (hstore - 'a')
84 85 86 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 84 def -(other) HStoreOp.new(super) end |
#[](key) ⇒ Object
Lookup the value for the given key in an hstore:
hstore_op['a'] # (hstore -> 'a')
91 92 93 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 91 def [](key) Sequel::SQL::StringExpression.new(:NOOP, Sequel::SQL::PlaceholderLiteralString.new(LOOKUP, [value, key])) end |
#contain_all(other) ⇒ Object
Check if the receiver contains all of the keys in the given array:
hstore_op.contain_all(:a) # (hstore ?& a)
98 99 100 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 98 def contain_all(other) bool_op(CONTAIN_ALL, other) end |
#contain_any(other) ⇒ Object
Check if the receiver contains any of the keys in the given array:
hstore_op.contain_any(:a) # (hstore ?| a)
105 106 107 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 105 def contain_any(other) bool_op(CONTAIN_ANY, other) end |
#contained_by(other) ⇒ Object
Check if the other hstore contains all entries in the receiver:
hstore_op.contained_by(:h) # (hstore <@ h)
119 120 121 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 119 def contained_by(other) bool_op(CONTAINED_BY, other) end |
#contains(other) ⇒ Object
Check if the receiver contains all entries in the other hstore:
hstore_op.contains(:h) # (hstore @> h)
112 113 114 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 112 def contains(other) bool_op(CONTAINS, other) end |
#defined(key) ⇒ Object
Check if the receiver contains a non-NULL value for the given key:
hstore_op.defined('a') # defined(hstore, 'a')
126 127 128 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 126 def defined(key) Sequel::SQL::BooleanExpression.new(:NOOP, function(:defined, key)) end |
#delete(key) ⇒ Object
Delete the matching entries from the receiver:
hstore_op.delete('a') # delete(hstore, 'a')
133 134 135 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 133 def delete(key) HStoreOp.new(function(:delete, key)) end |
#each ⇒ Object
Transform the receiver into a set of keys and values:
hstore_op.each # each(hstore)
140 141 142 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 140 def each function(:each) end |
#has_key?(key) ⇒ Boolean Also known as: include?, key?, member?, exist?
Check if the receiver contains the given key:
hstore_op.has_key?('a') # (hstore ? 'a')
147 148 149 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 147 def has_key?(key) bool_op(HAS_KEY, key) end |
#hstore ⇒ Object
Return the receiver.
156 157 158 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 156 def hstore self end |
#keys ⇒ Object Also known as: akeys
Return the keys as a PostgreSQL array:
hstore_op.keys # akeys(hstore)
163 164 165 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 163 def keys function(:akeys) end |
#merge(other) ⇒ Object Also known as: concat
Merge a given hstore into the receiver:
hstore_op.merge(:a) # (hstore || a)
171 172 173 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 171 def merge(other) HStoreOp.new(Sequel::SQL::PlaceholderLiteralString.new(CONCAT, [self, other])) end |
#populate(record) ⇒ Object
Create a new record populated with entries from the receiver:
hstore_op.populate(:a) # populate_record(a, hstore)
179 180 181 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 179 def populate(record) SQL::Function.new(:populate_record, record, self) end |
#record_set(record) ⇒ Object
Update the values in a record using entries in the receiver:
hstore_op.record_set(:a) # (a #= hstore)
186 187 188 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 186 def record_set(record) Sequel::SQL::PlaceholderLiteralString.new(RECORD_SET, [record, value]) end |
#skeys ⇒ Object
Return the keys as a PostgreSQL set:
hstore_op.skeys # skeys(hstore)
193 194 195 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 193 def skeys function(:skeys) end |
#slice(keys) ⇒ Object
Return an hstore with only the keys in the given array:
hstore_op.slice(:a) # slice(hstore, a)
200 201 202 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 200 def slice(keys) HStoreOp.new(function(:slice, keys)) end |
#svals ⇒ Object
Return the values as a PostgreSQL set:
hstore_op.svals # svals(hstore)
207 208 209 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 207 def svals function(:svals) end |
#to_array ⇒ Object
Return a flattened array of the receiver with alternating keys and values:
hstore_op.to_array # hstore_to_array(hstore)
215 216 217 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 215 def to_array function(:hstore_to_array) end |
#to_matrix ⇒ Object
Return a nested array of the receiver, with arrays of 2 element (key/value) arrays:
hstore_op.to_matrix # hstore_to_matrix(hstore)
223 224 225 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 223 def to_matrix function(:hstore_to_matrix) end |
#values ⇒ Object Also known as: avals
Return the values as a PostgreSQL array:
hstore_op.values # avals(hstore)
230 231 232 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 230 def values function(:avals) end |