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

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

Constant Summary collapse

APOS =
"'".freeze
DOUBLE_APOS =
"''".freeze
ESCAPE_RE =
/("|\\)/.freeze
ESCAPE_REPLACEMENT =
'\\\\\1'.freeze
BLOB_RANGE =
1...-1

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.define_array_typecast_method(type, creator, scalar_typecast) ⇒ Object

Define a private array typecasting method for the given type that uses the creator argument to do the type conversion.



193
194
195
196
197
198
# File 'lib/sequel/extensions/pg_array.rb', line 193

def self.define_array_typecast_method(type, creator, scalar_typecast)
  meth = :"typecast_value_#{type}_array"
  scalar_typecast_method = :"typecast_value_#{scalar_typecast}"
  define_method(meth){|v| typecast_value_pg_array(v, creator, scalar_typecast_method)}
  private meth
end

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



187
188
189
# File 'lib/sequel/extensions/pg_array.rb', line 187

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



201
202
203
204
205
206
207
208
209
210
# File 'lib/sequel/extensions/pg_array.rb', line 201

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 handle registered array types.



213
214
215
216
217
218
219
# File 'lib/sequel/extensions/pg_array.rb', line 213

def schema_column_type(db_type)
  if (db_type =~ /\A([^(]+)(?:\([^(]+\))?\[\]\z/io) && (type = ARRAY_TYPES[$1])
    type
  else
    super
  end
end