Class: Sequel::Postgres::PGRow::HashRow
- Defined in:
- lib/sequel/extensions/pg_row.rb
Overview
Class for row-valued/composite types that are treated as hashes. Types registered via Database#register_row_type will use this class by default.
Class Attribute Summary collapse
-
.columns ⇒ Object
The columns associated with this class.
-
.db_type ⇒ Object
The database type for this class.
Instance Attribute Summary collapse
-
#columns ⇒ Object
Return the instance’s columns, or the class’s columns if the instance has not overridden it.
-
#db_type ⇒ Object
Return the instance’s database type, or the class’s columns if the instance has not overridden it.
Class Method Summary collapse
-
.subclass(db_type, columns) ⇒ Object
Create a new subclass of this class with the given database type and columns.
Instance Method Summary collapse
-
#check_columns! ⇒ Object
Check that the HashRow has valid columns.
-
#sql_literal_append(ds, sql) ⇒ Object
Append SQL fragment related to this object to the sql.
Methods inherited from Hash
#&, #case, #hstore, #pg_json, #sql_expr, #sql_negate, #sql_or, #|, #~
Class Attribute Details
.columns ⇒ Object
The columns associated with this class.
130 131 132 |
# File 'lib/sequel/extensions/pg_row.rb', line 130 def columns @columns end |
.db_type ⇒ Object
The database type for this class. May be nil if this class done not have a specific database type.
134 135 136 |
# File 'lib/sequel/extensions/pg_row.rb', line 134 def db_type @db_type end |
Instance Attribute Details
#columns ⇒ Object
Return the instance’s columns, or the class’s columns if the instance has not overridden it.
163 164 165 |
# File 'lib/sequel/extensions/pg_row.rb', line 163 def columns @columns || self.class.columns end |
#db_type ⇒ Object
Return the instance’s database type, or the class’s columns if the instance has not overridden it.
169 170 171 |
# File 'lib/sequel/extensions/pg_row.rb', line 169 def db_type @db_type || self.class.db_type end |
Class Method Details
.subclass(db_type, columns) ⇒ Object
Create a new subclass of this class with the given database type and columns.
143 144 145 146 147 148 |
# File 'lib/sequel/extensions/pg_row.rb', line 143 def self.subclass(db_type, columns) sc = Class.new(self) do @db_type = db_type @columns = columns end end |
Instance Method Details
#check_columns! ⇒ Object
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.
176 177 178 179 180 |
# File 'lib/sequel/extensions/pg_row.rb', line 176 def check_columns! if columns.nil? || columns.empty? raise Error, 'cannot literalize HashRow without columns' end end |
#sql_literal_append(ds, sql) ⇒ Object
Append SQL fragment related to this object to the sql.
183 184 185 186 187 188 189 190 191 |
# File 'lib/sequel/extensions/pg_row.rb', line 183 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 |