class Sequel::Postgres::PGRow::HashRow

  1. lib/sequel/extensions/pg_row.rb
Parent: PGRow

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

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, line 160
def self.subclass(db_type, columns)
  Class.new(self) do
    @db_type = db_type
    @columns = columns
  end
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, line 193
def check_columns!
  if columns.nil? || columns.empty?
    raise Error, 'cannot literalize HashRow without columns'
  end
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, line 180
def columns
  @columns || self.class.columns
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, line 186
def db_type
  @db_type || self.class.db_type
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, line 200
def sql_literal_append(ds, sql)
  check_columns!
  sql << ROW
  ds.literal_append(sql, values_at(*columns))
  if db_type
    sql << CAST
    ds.quote_schema_table_append(sql, db_type)
  end
end