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
-
.extended(db) ⇒ Object
Create the local hash of database type strings to schema type symbols, used for array types local to this database.
Instance Method Summary collapse
-
#bound_variable_arg(arg, conn) ⇒ Object
Handle arrays in bound variables.
-
#register_array_type(db_type, opts = OPTS, &block) ⇒ Object
Register a database specific array type.
-
#schema_type_class(type) ⇒ Object
Return PGArray if this type matches any supported array type.
Class Method Details
.extended(db) ⇒ Object
Create the local hash of database type strings to schema type symbols, used for array types local to this database.
223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/sequel/extensions/pg_array.rb', line 223 def self.extended(db) db.instance_eval do @pg_array_schema_types ||= {} copy_conversion_procs([1009, 1007, 1016, 1231, 1022, 1000, 1001, 1182, 1183, 1270, 1005, 1028, 1021, 1014, 1015]) [:string_array, :integer_array, :decimal_array, :float_array, :boolean_array, :blob_array, :date_array, :time_array, :datetime_array].each do |v| @schema_type_classes[v] = PGArray end end procs = db.conversion_procs procs[1115] = Creator.new("timestamp without time zone", procs[1114]) procs[1185] = Creator.new("timestamp with time zone", procs[1184]) end |
Instance Method Details
#bound_variable_arg(arg, conn) ⇒ Object
Handle arrays in bound variables
238 239 240 241 242 243 244 245 246 247 |
# File 'lib/sequel/extensions/pg_array.rb', line 238 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 |
#register_array_type(db_type, opts = OPTS, &block) ⇒ Object
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.
253 254 255 256 257 258 259 260 261 262 |
# File 'lib/sequel/extensions/pg_array.rb', line 253 def register_array_type(db_type, opts=OPTS, &block) opts = {:type_procs=>conversion_procs, :typecast_method_map=>@pg_array_schema_types, :typecast_methods_module=>(class << self; self; end)}.merge(opts) unless (opts.has_key?(:scalar_oid) || block) && opts.has_key?(:oid) array_oid, scalar_oid = from(:pg_type).where(:typname=>db_type.to_s).get([:typarray, :oid]) opts[:scalar_oid] = scalar_oid unless opts.has_key?(:scalar_oid) || block opts[:oid] = array_oid unless opts.has_key?(:oid) end PGArray.register(db_type, opts, &block) @schema_type_classes[:"#{opts[:typecast_method] || opts[:type_symbol] || db_type}_array"] = PGArray end |
#schema_type_class(type) ⇒ Object
Return PGArray if this type matches any supported array type.
265 266 267 |
# File 'lib/sequel/extensions/pg_array.rb', line 265 def schema_type_class(type) super || (ARRAY_TYPES.each_value{|v| return PGArray if type == v}; nil) end |