Module: Sequel::Postgres::PGRange::DatabaseMethods
- Defined in:
- lib/sequel/extensions/pg_range.rb
Class Method Summary collapse
-
.extended(db) ⇒ Object
Reset the conversion procs if using the native postgres adapter, and extend the datasets to correctly literalize ruby Range values.
Instance Method Summary collapse
-
#bound_variable_arg(arg, conn) ⇒ Object
Handle Range and PGRange values in bound variables.
-
#register_range_type(db_type, opts = OPTS, &block) ⇒ Object
Register a database specific range type.
Class Method Details
.extended(db) ⇒ Object
Reset the conversion procs if using the native postgres adapter, and extend the datasets to correctly literalize ruby Range values.
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/sequel/extensions/pg_range.rb', line 240 def self.extended(db) db.instance_eval do @pg_range_schema_types ||= {} extend_datasets(DatasetMethods) copy_conversion_procs([3904, 3906, 3912, 3926, 3905, 3907, 3913, 3927]) [:int4range, :numrange, :tsrange, :tstzrange, :daterange, :int8range].each do |v| @schema_type_classes[v] = PGRange end end procs = db.conversion_procs procs[3908] = Parser.new("tsrange", procs[1114]) procs[3910] = Parser.new("tstzrange", procs[1184]) if defined?(PGArray::Creator) procs[3909] = PGArray::Creator.new("tsrange", procs[3908]) procs[3911] = PGArray::Creator.new("tstzrange", procs[3910]) end end |
Instance Method Details
#bound_variable_arg(arg, conn) ⇒ Object
Handle Range and PGRange values in bound variables
261 262 263 264 265 266 267 268 269 270 |
# File 'lib/sequel/extensions/pg_range.rb', line 261 def bound_variable_arg(arg, conn) case arg when PGRange arg.unquoted_literal(schema_utility_dataset) when Range PGRange.from_range(arg).unquoted_literal(schema_utility_dataset) else super end end |
#register_range_type(db_type, opts = OPTS, &block) ⇒ Object
Register a database specific range type. This can be used to support different range types per Database. Use of this method does not affect global state, unlike PGRange.register. See PGRange.register for possible options.
276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/sequel/extensions/pg_range.rb', line 276 def register_range_type(db_type, opts=OPTS, &block) opts = {:type_procs=>conversion_procs, :typecast_method_map=>@pg_range_schema_types, :typecast_methods_module=>(class << self; self; end)}.merge!(opts) unless (opts.has_key?(:subtype_oid) || block) && opts.has_key?(:oid) range_oid, subtype_oid = from(:pg_range).join(:pg_type, :oid=>:rngtypid).where(:typname=>db_type.to_s).get([:rngtypid, :rngsubtype]) opts[:subtype_oid] = subtype_oid unless opts.has_key?(:subtype_oid) || block opts[:oid] = range_oid unless opts.has_key?(:oid) end PGRange.register(db_type, opts, &block) @schema_type_classes[:"#{opts[:type_symbol] || db_type}"] = PGRange conversion_procs_updated end |