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.

Methods

new   op   parse   sql_literal_append  

Classes and Modules

Module Sequel::Postgres::PGArray::DatabaseMethods
Class Sequel::Postgres::PGArray::Parser

Constants

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

External Aliases

__getobj__ -> to_a
  The delegated object is always an array.

Attributes

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‘

Public Class methods

Set the array to delegate to, and a database type.

[Source]

     # 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.

[Source]

     # 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

Public Instance methods

Wrap the PGArray instance in an ArrayOp, allowing you to easily use the PostgreSQL array functions and operators with literal arrays.

[Source]

     # File lib/sequel/extensions/pg_array_ops.rb, line 202
202:         def op
203:           ArrayOp.new(self)
204:         end

Append the array SQL to the given sql string. If the receiver has a type, add a cast to the database array type.

[Source]

     # 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

[Validate]