Parent

Class Index [+]

Quicksearch

Sequel::Postgres::PGArray

Base class for the PostgreSQL array types. Subclasses generally just deal with parsing, so instances manually created from arrays can use this class correctly.

Constants

ARRAY
DOUBLE_COLON
EMPTY_BRACKET
OPEN_BRACKET
CLOSE_BRACKET
COMMA
BACKSLASH
EMPTY_STRING
OPEN_BRACE
CLOSE_BRACE
NULL
QUOTE

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

new(array, type=nil) click to toggle source

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(string, type=nil) click to toggle source

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

Private Class Methods

convert_item(s) click to toggle source

Return the item as-is by default, making conversion a no-op.

     # File lib/sequel/extensions/pg_array.rb, line 281
281:       def self.convert_item(s)
282:         s
283:       end

Public Instance Methods

op() click to toggle source

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

     # File lib/sequel/extensions/pg_array_ops.rb, line 202
202:         def op
203:           ArrayOp.new(self)
204:         end
sql_literal_append(ds, sql) click to toggle source

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

Private Instance Methods

_literal_append(sql, ds, array) click to toggle source

Recursive method that handles multi-dimensional arrays, surrounding each with [] and interspersing entries with ,.

     # File lib/sequel/extensions/pg_array.rb, line 317
317:       def _literal_append(sql, ds, array)
318:         sql << OPEN_BRACKET
319:         comma = false
320:         commas = COMMA
321:         array.each do |i|
322:           sql << commas if comma
323:           if i.is_a?(Array)
324:             _literal_append(sql, ds, i)
325:           else
326:             ds.literal_append(sql, i)
327:           end
328:           comma = true
329:         end
330:         sql << CLOSE_BRACKET
331:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.