class Sequel::Postgres::PGRow::HashRow
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:
Attributes
The columns associated with this class.
The database type for this class. May be nil if this class done not have a specific database type.
Sets the columns associated with this instance. This is used to override the class's default columns.
Sets the database type associated with this instance. This is used to override the class's default database type.
Public Class Methods
Create a new subclass of this class with the given database type and columns.
# File lib/sequel/extensions/pg_row.rb, line 170 def self.subclass(db_type, columns) Class.new(self) do @db_type = db_type @columns = columns end end
Public Instance Methods
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.
# File lib/sequel/extensions/pg_row.rb, line 203 def check_columns! if columns.nil? || columns.empty? raise Error, 'cannot literalize HashRow without columns' end end
Return the instance's columns, or the class's columns if the instance has not overridden it.
# File lib/sequel/extensions/pg_row.rb, line 190 def columns @columns || self.class.columns end
Return the instance's database type, or the class's columns if the instance has not overridden it.
# File lib/sequel/extensions/pg_row.rb, line 196 def db_type @db_type || self.class.db_type end
Wrap the PGRow::ArrayRow instance in an PGRowOp, allowing you to easily use the PostgreSQL row functions and operators with literal rows.
# File lib/sequel/extensions/pg_row_ops.rb, line 179 def op Sequel.pg_row_op(self) end
Allow automatic parameterization if all values support it.
# File lib/sequel/extensions/pg_row.rb, line 221 def sequel_auto_param_type(ds) if db_type && all?{|_,v| nil == v || ds.send(:auto_param_type, v)} s = String.new << "::" ds.quote_schema_table_append(s, db_type) s end end
Append SQL fragment related to this object to the sql.
# File lib/sequel/extensions/pg_row.rb, line 210 def sql_literal_append(ds, sql) check_columns! sql << 'ROW' ds.literal_append(sql, values_at(*columns)) if db_type sql << '::' ds.quote_schema_table_append(sql, db_type) end end