Class: Relix::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/relix/query.rb

Defined Under Namespace

Classes: Clause

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Query

Returns a new instance of Query.



3
4
5
6
# File 'lib/relix/query.rb', line 3

def initialize(model)
  @model = model
  @offset = 0
end

Instance Method Details

#[](index_name) ⇒ Object

Raises:



8
9
10
11
12
# File 'lib/relix/query.rb', line 8

def [](index_name)
  index = @model[index_name]
  raise MissingIndexError.new("No index declared for #{index_name}") unless index
  @clause = index.create_query_clause(@model.redis)
end

#runObject



14
15
16
17
18
19
20
# File 'lib/relix/query.rb', line 14

def run
  if @clause
    @clause.lookup
  else
    @model.primary_key_index.lookup
  end
end