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
Source
# File lib/sequel/extensions/pg_row.rb 171 def self.subclass(db_type, columns) 172 Class.new(self) do 173 @db_type = db_type 174 @columns = columns 175 end 176 end
Create a new subclass of this class with the given database type and columns.
Public Instance Methods
Source
# File lib/sequel/extensions/pg_row.rb 204 def check_columns! 205 if columns.nil? || columns.empty? 206 raise Error, 'cannot literalize HashRow without columns' 207 end 208 end
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.
Source
# File lib/sequel/extensions/pg_row.rb 191 def columns 192 @columns || self.class.columns 193 end
Return the instance’s columns, or the class’s columns if the instance has not overridden it.
Source
# File lib/sequel/extensions/pg_row.rb 197 def db_type 198 @db_type || self.class.db_type 199 end
Return the instance’s database type, or the class’s columns if the instance has not overridden it.
Source
# File lib/sequel/extensions/pg_row_ops.rb 180 def op 181 Sequel.pg_row_op(self) 182 end
Wrap the PGRow::ArrayRow
instance in an PGRowOp
, allowing you to easily use the PostgreSQL row functions and operators with literal rows.
Source
# File lib/sequel/extensions/pg_row.rb 222 def sequel_auto_param_type(ds) 223 if db_type && all?{|_,v| nil == v || ds.send(:auto_param_type, v)} 224 s = String.new << "::" 225 ds.quote_schema_table_append(s, db_type) 226 s 227 end 228 end
Allow automatic parameterization if all values support it.
Source
# File lib/sequel/extensions/pg_row.rb 211 def sql_literal_append(ds, sql) 212 check_columns! 213 sql << 'ROW' 214 ds.literal_append(sql, values_at(*columns)) 215 if db_type 216 sql << '::' 217 ds.quote_schema_table_append(sql, db_type) 218 end 219 end
Append SQL
fragment related to this object to the sql.