Class: Sequel::Postgres::PGArray
- Includes:
- SQL::AliasMethods
- Defined in:
- lib/sequel/extensions/pg_array.rb,
 lib/sequel/extensions/pg_array_ops.rb
Overview
:nocov:
Defined Under Namespace
Modules: DatabaseMethods Classes: Creator, Parser
Instance Attribute Summary collapse
- 
  
    
      #array_type  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    The type of this array. 
Instance Method Summary collapse
- 
  
    
      #initialize(array, type = nil)  ⇒ PGArray 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Set the array to delegate to, and a database type. 
- 
  
    
      #op  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Wrap the PGArray instance in an ArrayOp, allowing you to easily use the PostgreSQL array functions and operators with literal arrays. 
- 
  
    
      #sequel_auto_param_type(ds)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Allow automatic parameterization of the receiver if all elements can be can be automatically parameterized. 
- 
  
    
      #sql_literal_append(ds, sql)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Append the array SQL to the given sql string. 
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(array, type = nil) ⇒ PGArray
Set the array to delegate to, and a database type.
| 460 461 462 463 | # File 'lib/sequel/extensions/pg_array.rb', line 460 def initialize(array, type=nil) super(array) @array_type = type end | 
Instance Attribute Details
#array_type ⇒ Object
The type of this array. May be nil if no type was given. If a type is provided, the array is automatically casted to this type when literalizing. This type is the underlying type, not the array type itself, so for an int4[] database type, it should be :int4 or ‘int4’
| 457 458 459 | # File 'lib/sequel/extensions/pg_array.rb', line 457 def array_type @array_type end | 
Instance Method Details
#op ⇒ Object
Wrap the PGArray instance in an ArrayOp, allowing you to easily use the PostgreSQL array functions and operators with literal arrays.
| 335 336 337 | # File 'lib/sequel/extensions/pg_array_ops.rb', line 335 def op ArrayOp.new(self) end | 
#sequel_auto_param_type(ds) ⇒ Object
Allow automatic parameterization of the receiver if all elements can be can be automatically parameterized.
| 483 484 485 486 487 | # File 'lib/sequel/extensions/pg_array.rb', line 483 def sequel_auto_param_type(ds) if array_type && all?{|x| nil == x || ds.send(:auto_param_type, x)} "::#{array_type}[]" end end | 
#sql_literal_append(ds, sql) ⇒ Object
Append the array SQL to the given sql string. If the receiver has a type, add a cast to the database array type.
| 468 469 470 471 472 473 474 475 476 477 478 479 | # File 'lib/sequel/extensions/pg_array.rb', line 468 def sql_literal_append(ds, sql) at = array_type if empty? && at sql << "'{}'" else sql << "ARRAY" _literal_append(sql, ds, to_a) end if at sql << '::' << at.to_s << '[]' end end |