Class: Sequel::Postgres::PGRow::HashRow

Inherits:
Hash show all
Includes:
SQL::AliasMethods
Defined in:
lib/sequel/extensions/pg_row.rb,
lib/sequel/extensions/pg_row_ops.rb

Overview

:nocov:

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SQL::AliasMethods

#as

Methods inherited from Hash

#&, #case, #hstore, #pg_json, #pg_jsonb, #sql_expr, #sql_negate, #sql_or, #|, #~

Class Attribute Details

.columnsObject

The columns associated with this class.


149
150
151
# File 'lib/sequel/extensions/pg_row.rb', line 149

def columns
  @columns
end

.db_typeObject

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


153
154
155
# File 'lib/sequel/extensions/pg_row.rb', line 153

def db_type
  @db_type
end

Instance Attribute Details

#columnsObject

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


182
183
184
# File 'lib/sequel/extensions/pg_row.rb', line 182

def columns
  @columns || self.class.columns
end

#db_typeObject

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


188
189
190
# File 'lib/sequel/extensions/pg_row.rb', line 188

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.


162
163
164
165
166
167
# File 'lib/sequel/extensions/pg_row.rb', line 162

def self.subclass(db_type, columns)
  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.


195
196
197
198
199
# File 'lib/sequel/extensions/pg_row.rb', line 195

def check_columns!
  if columns.nil? || columns.empty?
    raise Error, 'cannot literalize HashRow without columns'
  end
end

#opObject

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


180
181
182
# File 'lib/sequel/extensions/pg_row_ops.rb', line 180

def op
  Sequel.pg_row_op(self)
end

#sql_literal_append(ds, sql) ⇒ Object

Append SQL fragment related to this object to the sql.


202
203
204
205
206
207
208
209
210
# File 'lib/sequel/extensions/pg_row.rb', line 202

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