Class: Sequel::Postgres::PGNumericArray

Inherits:
PGArray show all
Defined in:
lib/sequel/extensions/pg_array.rb

Overview

PGArray subclass handling integer and float types, using a fast JSON parser. Does not handle numeric/decimal types, since JSON does deal with arbitrary precision (see PGDecimalArray for that).

Direct Known Subclasses

PGFloatArray, PGIntegerArray

Constant Summary collapse

SUBST =

Character conversion map mapping input strings to JSON replacements

{'{'.freeze=>'['.freeze, '}'.freeze=>']'.freeze, 'NULL'.freeze=>'null'.freeze}
SUBST_RE =

Regular expression matching input strings to convert

%r[\{|\}|NULL].freeze

Constants inherited from PGArray

Sequel::Postgres::PGArray::ARRAY, Sequel::Postgres::PGArray::BACKSLASH, Sequel::Postgres::PGArray::CLOSE_BRACE, Sequel::Postgres::PGArray::CLOSE_BRACKET, Sequel::Postgres::PGArray::COMMA, Sequel::Postgres::PGArray::DOUBLE_COLON, Sequel::Postgres::PGArray::EMPTY_BRACKET, Sequel::Postgres::PGArray::EMPTY_STRING, Sequel::Postgres::PGArray::NULL, Sequel::Postgres::PGArray::OPEN_BRACE, Sequel::Postgres::PGArray::OPEN_BRACKET, Sequel::Postgres::PGArray::QUOTE

Instance Attribute Summary

Attributes inherited from PGArray

#array_type

Class Method Summary collapse

Methods inherited from PGArray

#initialize, #op, #sql_literal_append

Methods inherited from Array

#case, #pg_array, #sql_expr, #sql_negate, #sql_or, #sql_string_join, #sql_value_list, #~

Constructor Details

This class inherits a constructor from Sequel::Postgres::PGArray

Class Method Details

.parse(string, type = nil) ⇒ Object

Parse the input string by using a gsub to convert non-JSON characters to JSON, running it through a regular JSON parser, and the doing a recursive map over the output to make sure the entries are in the correct type (mostly, to make sure real/double precision database types are returned as float and not integer).



349
350
351
# File 'lib/sequel/extensions/pg_array.rb', line 349

def self.parse(string, type=nil)
  new(recursive_map(JSON.parse(string.gsub(SUBST_RE){|m| SUBST[m]})), type)
end