Module | Sequel::Postgres::PGArray::DatabaseMethods |
In: |
lib/sequel/extensions/pg_array.rb
|
APOS | = | "'".freeze |
DOUBLE_APOS | = | "''".freeze |
ESCAPE_RE | = | /("|\\)/.freeze |
ESCAPE_REPLACEMENT | = | '\\\\\1'.freeze |
BLOB_RANGE | = | 1...-1 |
Create the local hash of database type strings to schema type symbols, used for array types local to this database.
# File lib/sequel/extensions/pg_array.rb, line 221 221: def self.extended(db) 222: db.instance_eval do 223: @pg_array_schema_types ||= {} 224: copy_conversion_procs([1009, 1007, 1016, 1231, 1022, 1000, 1001, 1182, 1183, 1270, 1005, 1028, 1021, 1014, 1015]) 225: [:string_array, :integer_array, :decimal_array, :float_array, :boolean_array, :blob_array, :date_array, :time_array, :datetime_array].each do |v| 226: @schema_type_classes[v] = PGArray 227: end 228: end 229: 230: procs = db.conversion_procs 231: procs[1115] = Creator.new("timestamp without time zone", procs[1114]) 232: procs[1185] = Creator.new("timestamp with time zone", procs[1184]) 233: end
Handle arrays in bound variables
# File lib/sequel/extensions/pg_array.rb, line 236 236: def bound_variable_arg(arg, conn) 237: case arg 238: when PGArray 239: bound_variable_array(arg.to_a) 240: when Array 241: bound_variable_array(arg) 242: else 243: super 244: end 245: end
Register a database specific array type. This can be used to support different array types per Database. Use of this method does not affect global state, unlike PGArray.register. See PGArray.register for possible options.
# File lib/sequel/extensions/pg_array.rb, line 251 251: def register_array_type(db_type, opts=OPTS, &block) 252: opts = {:type_procs=>conversion_procs, :typecast_method_map=>@pg_array_schema_types, :typecast_methods_module=>(class << self; self; end)}.merge(opts) 253: unless (opts.has_key?(:scalar_oid) || block) && opts.has_key?(:oid) 254: array_oid, scalar_oid = from(:pg_type).where(:typname=>db_type.to_s).get([:typarray, :oid]) 255: opts[:scalar_oid] = scalar_oid unless opts.has_key?(:scalar_oid) || block 256: opts[:oid] = array_oid unless opts.has_key?(:oid) 257: end 258: PGArray.register(db_type, opts, &block) 259: @schema_type_classes["#{opts[:typecast_method] || opts[:type_symbol] || db_type}_array""#{opts[:typecast_method] || opts[:type_symbol] || db_type}_array"] = PGArray 260: end