Class: Sequel::Postgres::PGArray
- Defined in:
- lib/sequel/extensions/pg_array.rb,
lib/sequel/extensions/pg_array_ops.rb
Overview
Base class for the PostgreSQL array types. Subclasses generally just deal with parsing, so instances manually created from arrays can use this class correctly.
Direct Known Subclasses
Defined Under Namespace
Modules: DatabaseMethods Classes: Parser
Constant Summary collapse
- ARRAY =
"ARRAY".freeze
- DOUBLE_COLON =
'::'.freeze
- EMPTY_BRACKET =
'[]'.freeze
- OPEN_BRACKET =
'['.freeze
- CLOSE_BRACKET =
']'.freeze
- COMMA =
','.freeze
- BACKSLASH =
'\\'.freeze
- EMPTY_STRING =
''.freeze
- OPEN_BRACE =
'{'.freeze
- CLOSE_BRACE =
'}'.freeze
- NULL =
'NULL'.freeze
- QUOTE =
'"'.freeze
Instance Attribute Summary collapse
-
#array_type ⇒ Object
The type of this array.
Class Method Summary collapse
-
.parse(string, type = nil) ⇒ Object
Parse the string using the generalized parser, setting the type if given.
Instance Method Summary collapse
-
#initialize(array, type = nil) ⇒ PGArray
constructor
Set the array to delegate to, and a database type.
-
#op ⇒ Object
Wrap the PGArray instance in an ArrayOp, allowing you to easily use the PostgreSQL array functions and operators with literal arrays.
-
#sql_literal_append(ds, sql) ⇒ Object
Append the array SQL to the given sql string.
Methods inherited from Array
#case, #pg_array, #pg_json, #sql_expr, #sql_negate, #sql_or, #sql_string_join, #sql_value_list, #~
Constructor Details
#initialize(array, type = nil) ⇒ PGArray
Set the array to delegate to, and a database type.
293 294 295 296 |
# File 'lib/sequel/extensions/pg_array.rb', line 293 def initialize(array, type=nil) super(array) self.array_type = type end |
Instance Attribute Details
#array_type ⇒ Object
The type of this array. May be nil if no type was given. If a type is provided, the array is automatically casted to this type when literalizing. This type is the underlying type, not the array type itself, so for an int4[] database type, it should be :int4 or ‘int4’
290 291 292 |
# File 'lib/sequel/extensions/pg_array.rb', line 290 def array_type @array_type end |
Class Method Details
Instance Method Details
#op ⇒ Object
Wrap the PGArray instance in an ArrayOp, allowing you to easily use the PostgreSQL array functions and operators with literal arrays.
202 203 204 |
# File 'lib/sequel/extensions/pg_array_ops.rb', line 202 def op ArrayOp.new(self) end |
#sql_literal_append(ds, sql) ⇒ Object
Append the array SQL to the given sql string. If the receiver has a type, add a cast to the database array type.
304 305 306 307 308 309 310 |
# File 'lib/sequel/extensions/pg_array.rb', line 304 def sql_literal_append(ds, sql) sql << ARRAY _literal_append(sql, ds, to_a) if at = array_type sql << DOUBLE_COLON << at.to_s << EMPTY_BRACKET end end |