Class: Sequel::Postgres::PGRow::ArrayRow

Inherits:
Array show all
Includes:
SQL::AliasMethods
Defined in:
lib/sequel/extensions/pg_row.rb

Overview

Class for row-valued/composite types that are treated as arrays. By default, this is only used for generic PostgreSQL record types, as registered types use HashRow by default.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SQL::AliasMethods

#as

Methods inherited from Array

#case, #pg_array, #pg_json, #pg_row, #sql_expr, #sql_negate, #sql_or, #sql_string_join, #sql_value_list, #~

Class Attribute Details

.db_typeObject

The database type for this class. May be nil if this class done not have a specific database type.



90
91
92
# File 'lib/sequel/extensions/pg_row.rb', line 90

def db_type
  @db_type
end

Instance Attribute Details

#db_typeObject

Return the instance’s database type, or the class’s database type if the instance has not overridden it.



112
113
114
# File 'lib/sequel/extensions/pg_row.rb', line 112

def db_type
  @db_type || self.class.db_type
end

Class Method Details

.subclass(db_type) ⇒ Object

Create a subclass associated with a specific database type. This is done so that instances of this subclass are automatically casted to the database type when literalizing.



100
101
102
103
104
# File 'lib/sequel/extensions/pg_row.rb', line 100

def self.subclass(db_type)
  sc = Class.new(self) do
    @db_type = db_type
  end
end

Instance Method Details

#sql_literal_append(ds, sql) ⇒ Object

Append SQL fragment related to this object to the sql.



117
118
119
120
121
122
123
124
# File 'lib/sequel/extensions/pg_row.rb', line 117

def sql_literal_append(ds, sql)
  sql << ROW
  ds.literal_append(sql, to_a)
  if db_type
    sql << CAST
    ds.quote_schema_table_append(sql, db_type)
  end
end