class Praxis::Mapper::Query::Sequel
Sequel-centric query class
Public Class Methods
new(identity_map, model, &block)
click to toggle source
Calls superclass method
Praxis::Mapper::Query::Base::new
# File lib/praxis-mapper/query/sequel.rb, line 10 def initialize(identity_map, model, &block) super end
Public Instance Methods
_execute(ds=nil)
click to toggle source
Executes this SQL statement. Does not perform any validation of the statement before execution.
@return [Array] result-set
# File lib/praxis-mapper/query/sequel.rb, line 54 def _execute(ds=nil) Praxis::Mapper.logger.debug "SQL:\n#{self.describe(ds)}\n" self.statistics[:datastore_interactions] += 1 start_time = Time.now rows = if @raw_query unless ds.nil? warn 'WARNING: Query::Sequel#_execute ignoring passed dataset due to previously-specified raw SQL' end connection[@raw_query].to_a else (ds || self.dataset).to_a end self.statistics[:datastore_interaction_time] += (Time.now - start_time) return rows end
_multi_get(identity, values)
click to toggle source
Executes a 'SELECT' statement.
@param identity [Symbol|Array] a simple or composite key for this model @param values [Array] list of identifier values (ideally a sorted set) @return [Array] SQL result set
@example numeric key
_multi_get(:id, [1, 2])
@example string key
_multi_get(:uid, ['foo', 'bar'])
@example composite key (possibly a combination of numeric and string keys)
_multi_get([:cloud_id, :account_id], [['foo1', 'bar1'], ['foo2', 'bar2']])
# File lib/praxis-mapper/query/sequel.rb, line 45 def _multi_get(identity, values) ds = self.dataset.where(identity => values) _execute(ds) end
dataset()
click to toggle source
# File lib/praxis-mapper/query/sequel.rb, line 14 def dataset ds = connection[model.table_name.to_sym] # TODO: support column aliases if @select && @select != true ds = ds.select(*@select.keys) end if @where ds = ds.where(@where) end if @limit ds = ds.limit(@limit) end ds end
describe(ds=nil)
click to toggle source
@see sql
# File lib/praxis-mapper/query/sequel.rb, line 73 def describe(ds=nil) (ds || self).sql end
raw(sql_text)
click to toggle source
Constructs a raw SQL statement. No validation is performed here (security risk?).
@param sql_text a custom SQL query
# File lib/praxis-mapper/query/sequel.rb, line 82 def raw(sql_text) @raw_query = sql_text end
sql()
click to toggle source
@return [String] raw or assembled SQL statement
# File lib/praxis-mapper/query/sequel.rb, line 87 def sql if @raw_query @raw_query else dataset.sql end end
to_records(rows)
click to toggle source
Calls superclass method
Praxis::Mapper::Query::Base#to_records
# File lib/praxis-mapper/query/sequel.rb, line 95 def to_records(rows) if model < ::Sequel::Model rows.collect do |row| m = model.call(row) m._query = self m end else super end end