Class: Sequel::Postgres::ArrayOp
- Inherits:
-
SQL::Wrapper
- Object
- SQL::Expression
- SQL::GenericExpression
- SQL::Wrapper
- Sequel::Postgres::ArrayOp
- Defined in:
- lib/sequel/extensions/pg_array_ops.rb
Overview
The ArrayOp class is a simple container for a single object that defines methods that yield Sequel expression objects representing PostgreSQL array operators and functions.
In the method documentation examples, assume that:
array_op = :array.pg_array
Constant Summary collapse
- CONCAT =
["(".freeze, " || ".freeze, ")".freeze].freeze
- CONTAINS =
["(".freeze, " @> ".freeze, ")".freeze].freeze
- CONTAINED_BY =
["(".freeze, " <@ ".freeze, ")".freeze].freeze
- OVERLAPS =
["(".freeze, " && ".freeze, ")".freeze].freeze
Instance Attribute Summary
Attributes inherited from SQL::Wrapper
Instance Method Summary collapse
-
#[](key) ⇒ Object
Access a member of the array, returns an SQL::Subscript instance:.
-
#all ⇒ Object
Call the ALL function:.
-
#any ⇒ Object
Call the ANY function:.
-
#contained_by(other) ⇒ Object
Use the contained by (<@) operator:.
-
#contains(other) ⇒ Object
Use the contains (@>) operator:.
-
#dims ⇒ Object
Call the array_dims method:.
-
#length(dimension = 1) ⇒ Object
Call the array_length method:.
-
#lower(dimension = 1) ⇒ Object
Call the array_lower method:.
-
#overlaps(other) ⇒ Object
Use the overlaps (&&) operator:.
-
#pg_array ⇒ Object
Return the receiver.
-
#push(other) ⇒ Object
(also: #concat)
Use the concatentation (||) operator:.
-
#to_string(joiner = "", null = nil) ⇒ Object
(also: #join)
Call the array_to_string method:.
-
#unnest ⇒ Object
Call the unnest method:.
-
#unshift(other) ⇒ Object
Use the concatentation (||) operator, reversing the order:.
Methods inherited from SQL::Wrapper
Methods included from HStoreOpMethods
Methods included from RangeOpMethods
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
#[](key) ⇒ Object
Access a member of the array, returns an SQL::Subscript instance:
array_op[1] # array[1]
77 78 79 |
# File 'lib/sequel/extensions/pg_array_ops.rb', line 77 def [](key) Sequel::SQL::Subscript.new(self, [key]) end |
#all ⇒ Object
Call the ALL function:
array_op.all # ALL(array)
Usually used like:
dataset.where(1=>array_op.all)
# WHERE (1 = ALL(array))
89 90 91 |
# File 'lib/sequel/extensions/pg_array_ops.rb', line 89 def all function(:ALL) end |
#any ⇒ Object
Call the ANY function:
array_op.all # ANY(array)
Usually used like:
dataset.where(1=>array_op.any)
# WHERE (1 = ANY(array))
101 102 103 |
# File 'lib/sequel/extensions/pg_array_ops.rb', line 101 def any function(:ANY) end |
#contained_by(other) ⇒ Object
Use the contained by (<@) operator:
array_op.contained_by(:a) # (array <@ a)
115 116 117 |
# File 'lib/sequel/extensions/pg_array_ops.rb', line 115 def contained_by(other) bool_op(CONTAINED_BY, wrap_array(other)) end |
#contains(other) ⇒ Object
Use the contains (@>) operator:
array_op.contains(:a) # (array @> a)
108 109 110 |
# File 'lib/sequel/extensions/pg_array_ops.rb', line 108 def contains(other) bool_op(CONTAINS, wrap_array(other)) end |
#dims ⇒ Object
Call the array_dims method:
array_op.dims # array_dims(array)
122 123 124 |
# File 'lib/sequel/extensions/pg_array_ops.rb', line 122 def dims function(:array_dims) end |
#length(dimension = 1) ⇒ Object
Call the array_length method:
array_op.length # array_length(array, 1)
array_op.length(2) # array_length(array, 2)
130 131 132 |
# File 'lib/sequel/extensions/pg_array_ops.rb', line 130 def length(dimension = 1) function(:array_length, dimension) end |
#lower(dimension = 1) ⇒ Object
Call the array_lower method:
array_op.lower # array_lower(array, 1)
array_op.lower(2) # array_lower(array, 2)
138 139 140 |
# File 'lib/sequel/extensions/pg_array_ops.rb', line 138 def lower(dimension = 1) function(:array_lower, dimension) end |
#overlaps(other) ⇒ Object
Use the overlaps (&&) operator:
array_op.overlaps(:a) # (array && a)
145 146 147 |
# File 'lib/sequel/extensions/pg_array_ops.rb', line 145 def overlaps(other) bool_op(OVERLAPS, wrap_array(other)) end |
#pg_array ⇒ Object
Return the receiver.
159 160 161 |
# File 'lib/sequel/extensions/pg_array_ops.rb', line 159 def pg_array self end |
#push(other) ⇒ Object Also known as: concat
Use the concatentation (||) operator:
array_op.push(:a) # (array || a)
array_op.concat(:a) # (array || a)
153 154 155 |
# File 'lib/sequel/extensions/pg_array_ops.rb', line 153 def push(other) array_op(CONCAT, [self, wrap_array(other)]) end |
#to_string(joiner = "", null = nil) ⇒ Object Also known as: join
Call the array_to_string method:
array_op.join # array_to_string(array, '', NULL)
array_op.to_string # array_to_string(array, '', NULL)
array_op.join(":") # array_to_string(array, ':', NULL)
array_op.join(":", "*") # array_to_string(array, ':', '*')
169 170 171 |
# File 'lib/sequel/extensions/pg_array_ops.rb', line 169 def to_string(joiner="", null=nil) function(:array_to_string, joiner, null) end |
#unnest ⇒ Object
Call the unnest method:
array_op.unnest # unnest(array)
177 178 179 |
# File 'lib/sequel/extensions/pg_array_ops.rb', line 177 def unnest function(:unnest) end |