Class: Ashikawa::Core::Query
- Inherits:
-
Object
- Object
- Ashikawa::Core::Query
- Extended by:
- Forwardable
- Defined in:
- lib/ashikawa-core/query.rb
Overview
Formulate a Query on a collection or on a database
Constant Summary collapse
- ALLOWED_KEYS_FOR_PATH =
For each simple query define the allowed attributes for filtering
{ 'simple/all' => [:limit, :skip, :collection], 'simple/by-example' => [:limit, :skip, :example, :collection], 'simple/near' => [:latitude, :longitude, :distance, :skip, :limit, :geo, :collection], 'simple/within' => [:latitude, :longitude, :radius, :distance, :skip, :limit, :geo, :collection], 'simple/range' => [:attribute, :left, :right, :closed, :limit, :skip, :collection], 'cursor' => [:query, :count, :batch_size, :collection, :bind_vars], 'query' => [:query], 'simple/first-example' => [:example, :collection] }
Instance Method Summary collapse
-
#all(options = {}) ⇒ Cursor
Retrieves all documents for a collection.
-
#by_example(example = {}, options = {}) ⇒ Cursor
Looks for documents in a collection which match the given criteria.
-
#execute(query, options = {}) ⇒ Cursor
Send an AQL query to the database.
-
#first_example(example = {}) ⇒ Document
Looks for one document in a collection which matches the given criteria.
-
#in_range(options = {}) ⇒ Cursor
Looks for documents in a collection with an attribute between two values.
-
#initialize(connection) ⇒ Query
constructor
Initializes a Query.
-
#near(options = {}) ⇒ Cursor
Looks for documents in a collection based on location.
-
#valid?(query) ⇒ Boolean
Test if an AQL query is valid.
-
#within(options = {}) ⇒ Cursor
Looks for documents in a collection within a radius.
Constructor Details
#initialize(connection) ⇒ Query
Initializes a Query
37 38 39 |
# File 'lib/ashikawa-core/query.rb', line 37 def initialize(connection) @connection = connection end |
Instance Method Details
#all(options = {}) ⇒ Cursor
It is advised to NOT use this method due to possible HUGE data amounts requested
Retrieves all documents for a collection
52 53 54 |
# File 'lib/ashikawa-core/query.rb', line 52 def all( = {}) simple_query_request('simple/all', ) end |
#by_example(example = {}, options = {}) ⇒ Cursor
Looks for documents in a collection which match the given criteria
68 69 70 |
# File 'lib/ashikawa-core/query.rb', line 68 def by_example(example = {}, = {}) simple_query_request('simple/by-example', { example: example }.merge()) end |
#execute(query, options = {}) ⇒ Cursor
Send an AQL query to the database
157 158 159 |
# File 'lib/ashikawa-core/query.rb', line 157 def execute(query, = {}) wrapped_request('cursor', :post, .merge({ query: query })) end |
#first_example(example = {}) ⇒ Document
Looks for one document in a collection which matches the given criteria
81 82 83 84 85 |
# File 'lib/ashikawa-core/query.rb', line 81 def first_example(example = {}) request = prepare_request('simple/first-example', { example: example, collection: collection.name }) response = send_request('simple/first-example', { put: request }) Document.new(database, response['document']) end |
#in_range(options = {}) ⇒ Cursor
Looks for documents in a collection with an attribute between two values
138 139 140 |
# File 'lib/ashikawa-core/query.rb', line 138 def in_range( = {}) simple_query_request('simple/range', ) end |
#near(options = {}) ⇒ Cursor
Looks for documents in a collection based on location
101 102 103 |
# File 'lib/ashikawa-core/query.rb', line 101 def near( = {}) simple_query_request('simple/near', ) end |
#valid?(query) ⇒ Boolean
Test if an AQL query is valid
169 170 171 172 173 |
# File 'lib/ashikawa-core/query.rb', line 169 def valid?(query) !!wrapped_request('query', :post, { query: query }) rescue Ashikawa::Core::BadSyntax false end |
#within(options = {}) ⇒ Cursor
Looks for documents in a collection within a radius
120 121 122 |
# File 'lib/ashikawa-core/query.rb', line 120 def within( = {}) simple_query_request('simple/within', ) end |