Module: Sequel::Postgres::PGArray::DatabaseMethods

Defined in:
lib/sequel/extensions/pg_array.rb

Constant Summary collapse

ESCAPE_RE =
/("|\\)/.freeze
ESCAPE_REPLACEMENT =
'\\\\\1'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(db) ⇒ Object

Reset the conversion procs when extending the Database object, so it will pick up the array convertors. This is only done for the native postgres adapter.



103
104
105
# File 'lib/sequel/extensions/pg_array.rb', line 103

def self.extended(db)
  db.reset_conversion_procs if db.respond_to?(:reset_conversion_procs)
end

Instance Method Details

#bound_variable_arg(arg, conn) ⇒ Object

Handle arrays in bound variables



108
109
110
111
112
113
114
115
116
117
# File 'lib/sequel/extensions/pg_array.rb', line 108

def bound_variable_arg(arg, conn)
  case arg
  when PGArray
    bound_variable_array(arg.to_a)
  when Array
    bound_variable_array(arg)
  else
    super
  end
end

#schema_column_type(db_type) ⇒ Object

Make the column type detection deal with string and numeric array types.



120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/sequel/extensions/pg_array.rb', line 120

def schema_column_type(db_type)
  case db_type
  when /\A(character( varying)?|text).*\[\]\z/io
    :string_array
  when /\A(integer|bigint|smallint)\[\]\z/io
    :integer_array
  when /\A(real|double precision)\[\]\z/io
    :float_array
  when /\Anumeric.*\[\]\z/io
    :decimal_array
  else
    super
  end
end