Class | Sequel::Postgres::PGArray |
In: |
lib/sequel/extensions/pg_array.rb
lib/sequel/extensions/pg_array_ops.rb |
Parent: | DelegateClass(Array) |
Base class for the PostgreSQL array types. Subclasses generally just deal with parsing, so instances manually created from arrays can use this class correctly.
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 |
__getobj__ | -> | to_a |
The delegated object is always an array. |
array_type | [RW] | 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‘ |
Set the array to delegate to, and a database type.
# File lib/sequel/extensions/pg_array.rb, line 293 293: def initialize(array, type=nil) 294: super(array) 295: self.array_type = type 296: end
Parse the string using the generalized parser, setting the type if given.
# File lib/sequel/extensions/pg_array.rb, line 276 276: def self.parse(string, type=nil) 277: new(Parser.new(string, method(:convert_item)).parse, type) 278: end
Append the array SQL to the given sql string. If the receiver has a type, add a cast to the database array type.
# File lib/sequel/extensions/pg_array.rb, line 304 304: def sql_literal_append(ds, sql) 305: sql << ARRAY 306: _literal_append(sql, ds, to_a) 307: if at = array_type 308: sql << DOUBLE_COLON << at.to_s << EMPTY_BRACKET 309: end 310: end