class Sequel::Postgres::PGRow::HashRow

  1. lib/sequel/extensions/pg_row.rb
  2. lib/sequel/extensions/pg_row_ops.rb
  3. show all
Superclass: DelegateClass(Hash)

Class for row-valued/composite types that are treated as hashes. Types registered via Database#register_row_type will use this class by default.

:nocov:

Included modules

  1. Sequel::SQL::AliasMethods

Attributes

columns [RW]

The columns associated with this class.

db_type [RW]

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

columns [W]

Sets the columns associated with this instance. This is used to override the class’s default columns.

db_type [W]

Sets the database type associated with this instance. This is used to override the class’s default database type.

Public Class methods

subclass(db_type, columns)

Create a new subclass of this class with the given database type and columns.

[show source]
    # File lib/sequel/extensions/pg_row.rb
172 def self.subclass(db_type, columns)
173   Class.new(self) do
174     Sequel.set_temp_name(self){"Sequel::Postgres::PGRow::HashRow::_Subclass(#{db_type})"}
175     @db_type = db_type
176     @columns = columns
177   end
178 end

Public Instance methods

check_columns!()

Check that the HashRow has valid columns. This should be used before all attempts to literalize the object, since literalization depends on the columns to get the column order.

[show source]
    # File lib/sequel/extensions/pg_row.rb
206 def check_columns!
207   if columns.nil? || columns.empty?
208     raise Error, 'cannot literalize HashRow without columns'
209   end
210 end
columns()

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

[show source]
    # File lib/sequel/extensions/pg_row.rb
193 def columns
194   @columns || self.class.columns
195 end
db_type()

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

[show source]
    # File lib/sequel/extensions/pg_row.rb
199 def db_type
200   @db_type || self.class.db_type
201 end
op()

Wrap the PGRow::ArrayRow instance in an PGRowOp, allowing you to easily use the PostgreSQL row functions and operators with literal rows.

[show source]
    # File lib/sequel/extensions/pg_row_ops.rb
180 def op
181   Sequel.pg_row_op(self)
182 end
sequel_auto_param_type(ds)

Allow automatic parameterization if all values support it.

[show source]
    # File lib/sequel/extensions/pg_row.rb
224 def sequel_auto_param_type(ds)
225   if db_type && all?{|_,v| nil == v || ds.send(:auto_param_type, v)}
226     s = String.new << "::"
227     ds.quote_schema_table_append(s, db_type)
228     s
229   end
230 end
sql_literal_append(ds, sql)

Append SQL fragment related to this object to the sql.

[show source]
    # File lib/sequel/extensions/pg_row.rb
213 def sql_literal_append(ds, sql)
214   check_columns!
215   sql << 'ROW'
216   ds.literal_append(sql, values_at(*columns))
217   if db_type
218     sql << '::'
219     ds.quote_schema_table_append(sql, db_type)
220   end
221 end