class Guacamole::Query
Build a query for ArangoDB
Attributes
Connection to the database
@return [Ashikawa::Core::Collection]
The example to search for
@return [Hash] the example
The mapper class
@return [Class]
Currently set options
@return [Hash] @api private
Public Class Methods
Create a new Query
@param [Ashikawa::Core::Collection] connection The collection to use to talk to the database @param [Class] mapper the class of the mapper to use
# File lib/guacamole/query.rb, line 31 def initialize(connection, mapper) @connection = connection @mapper = mapper @options = {} end
Public Instance Methods
Is this {Query} equal to another {Query}
Two {Query} objects are equal if their examples are equal
@param [Query] other The query to compare to
# File lib/guacamole/query.rb, line 69 def ==(other) other.instance_of?(self.class) && example == other.example end
Iterate over the result of the query
This will execute the query you have build
# File lib/guacamole/query.rb, line 40 def each(&block) return to_enum(__callee__) unless block_given? perfom_query ->(document) { block.call mapper.document_to_model(document) }, &block end
Limit the results of the query
@param [Fixnum] limit @return [self]
# File lib/guacamole/query.rb, line 50 def limit(limit) options[:limit] = limit self end
The number of results to skip
@param [Fixnum] skip @return [self]
# File lib/guacamole/query.rb, line 59 def skip(skip) options[:skip] = skip self end
Private Instance Methods
Performs the query against the database connection.
This can be changed by subclasses to implement other types of queries, such as AQL queries.
@param [Lambda] iterator To be called on each document returned from
the database
# File lib/guacamole/query.rb, line 84 def perfom_query(iterator, &block) if example connection.by_example(example, options).each(&iterator) else connection.all(options).each(&iterator) end end