class NoSE::Backend::PreparedQuery
A prepared query which can be executed against the backend
Attributes
query[R]
steps[R]
Public Class Methods
new(query, steps)
click to toggle source
# File lib/nose/backend.rb, line 364 def initialize(query, steps) @query = query @steps = steps end
Public Instance Methods
execute(conditions)
click to toggle source
Execute the query for the given set of conditions @return [Array<Hash>]
# File lib/nose/backend.rb, line 371 def execute(conditions) results = nil @steps.each do |step| if step.is_a?(Backend::IndexLookupStatementStep) field_ids = step.index.all_fields.map(&:id) field_conds = conditions.select { |key| field_ids.include? key } else field_conds = conditions end results = step.process field_conds, results # The query can't return any results at this point, so we're done break if results.empty? end # Only return fields selected by the query if one is given # (we have no query to refer to for manually-defined plans) unless @query.nil? select_ids = @query.select.map(&:id).to_set results.map { |row| row.select! { |k, _| select_ids.include? k } } end results end