Class: Sequel::Postgres::PGMultiRange
- Includes:
- SQL::AliasMethods
- Defined in:
- lib/sequel/extensions/pg_range_ops.rb,
lib/sequel/extensions/pg_multirange.rb
Overview
:nocov:
Defined Under Namespace
Modules: DatabaseMethods Classes: Creator, Parser
Instance Attribute Summary collapse
-
#db_type ⇒ Object
The type of this multirange (e.g. ‘int4multirange’).
Instance Method Summary collapse
-
#==(other) ⇒ Object
Don’t consider multiranges with different database types equal.
-
#cover?(value) ⇒ Boolean
(also: #===)
Return whether the value is inside any of the ranges in the multirange.
-
#eql?(other) ⇒ Boolean
Don’t consider multiranges with different database types equal.
-
#initialize(ranges, db_type) ⇒ PGMultiRange
constructor
Set the array of ranges to delegate to, and the database type.
-
#op ⇒ Object
Wrap the PGRange instance in an RangeOp, allowing you to easily use the PostgreSQL range functions and operators with literal ranges.
-
#sequel_auto_param_type(ds) ⇒ Object
Allow automatic parameterization.
-
#sql_literal_append(ds, sql) ⇒ Object
Append the multirange SQL to the given sql string.
-
#unquoted_literal(ds) ⇒ Object
Return a string containing the unescaped version of the multirange.
Methods included from SQL::AliasMethods
Methods inherited from Array
#case, #pg_array, #pg_json, #pg_jsonb, #pg_row, #sql_expr, #sql_negate, #sql_or, #sql_string_join, #sql_value_list, #~
Constructor Details
#initialize(ranges, db_type) ⇒ PGMultiRange
Set the array of ranges to delegate to, and the database type.
266 267 268 269 |
# File 'lib/sequel/extensions/pg_multirange.rb', line 266 def initialize(ranges, db_type) super(ranges) @db_type = db_type.to_s end |
Instance Attribute Details
#db_type ⇒ Object
The type of this multirange (e.g. ‘int4multirange’).
263 264 265 |
# File 'lib/sequel/extensions/pg_multirange.rb', line 263 def db_type @db_type end |
Instance Method Details
#==(other) ⇒ Object
Don’t consider multiranges with different database types equal.
309 310 311 312 |
# File 'lib/sequel/extensions/pg_multirange.rb', line 309 def ==(other) return false if PGMultiRange === other && other.db_type != db_type super end |
#cover?(value) ⇒ Boolean Also known as: ===
Return whether the value is inside any of the ranges in the multirange.
294 295 296 |
# File 'lib/sequel/extensions/pg_multirange.rb', line 294 def cover?(value) any?{|range| range.cover?(value)} end |
#eql?(other) ⇒ Boolean
Don’t consider multiranges with different database types equal.
300 301 302 303 304 305 306 |
# File 'lib/sequel/extensions/pg_multirange.rb', line 300 def eql?(other) if PGMultiRange === other return false unless other.db_type == db_type other = other.__getobj__ end __getobj__.eql?(other) end |
#op ⇒ Object
Wrap the PGRange instance in an RangeOp, allowing you to easily use the PostgreSQL range functions and operators with literal ranges.
153 154 155 |
# File 'lib/sequel/extensions/pg_range_ops.rb', line 153 def op RangeOp.new(self) end |
#sequel_auto_param_type(ds) ⇒ Object
Allow automatic parameterization.
341 342 343 |
# File 'lib/sequel/extensions/pg_multirange.rb', line 341 def sequel_auto_param_type(ds) "::#{db_type}" end |
#sql_literal_append(ds, sql) ⇒ Object
Append the multirange SQL to the given sql string.
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/sequel/extensions/pg_multirange.rb', line 272 def sql_literal_append(ds, sql) sql << db_type << '(' joiner = nil conversion_meth = nil each do |range| if joiner sql << joiner else joiner = ', ' end unless range.is_a?(PGRange) conversion_meth ||= :"typecast_value_#{db_type.sub('multi', '')}" range = ds.db.send(conversion_meth, range) end ds.literal_append(sql, range) end sql << ')' end |
#unquoted_literal(ds) ⇒ Object
Return a string containing the unescaped version of the multirange. Separated out for use by the bound argument code.
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/sequel/extensions/pg_multirange.rb', line 316 def unquoted_literal(ds) val = String.new val << "{" joiner = nil conversion_meth = nil each do |range| if joiner val << joiner else joiner = ', ' end unless range.is_a?(PGRange) conversion_meth ||= :"typecast_value_#{db_type.sub('multi', '')}" range = ds.db.send(conversion_meth, range) end val << range.unquoted_literal(ds) end val << "}" end |