Module: ArangoDb::Queries::ClassMethods
- Included in:
- Base
- Defined in:
- lib/queries.rb
Instance Method Summary collapse
-
#all(options = {}) ⇒ Object
PUT /_api/simple/all Returns all documents of a collections.
- #attribute(attr_name) ⇒ Object
- #closed(boolean) ⇒ Object
-
#first(options = {}) ⇒ Object
PUT /_api/simple/first-example This will return the first document matching a given example.
- #left(number) ⇒ Object
- #limit(number) ⇒ Object
- #right(number) ⇒ Object
- #skip(number) ⇒ Object
- #where(hash) ⇒ Object
Instance Method Details
#all(options = {}) ⇒ Object
PUT /_api/simple/all Returns all documents of a collections. The call expects an JSON object as body with the following attributes: collection: The identifier or name of the collection to query. skip: The documents to skip in the query. (optional) limit: The maximal amount of documents to return. The skip is applied before the limit restriction. (optional)
PUT /_api/simple/by-example This will find all documents matching a given example. The call expects a JSON hash array as body with the following attributes: collection: The identifier or name of the collection to query. example: The example. skip: The documents to skip in the query. (optional) limit: The maximal amount of documents to return. (optional)
PUT /_api/simple/range This will find all documents within a given range. You must declare a skip-list index on the attribute in order to be able to use a range query.The call expects a JSON hash array as body with the following attributes: collection: The identifier or name of the collection to query. attribute: The attribute path to check. left: The lower bound. right: The upper bound. closed: If true, use interval including left and right, otherwise exclude right, but include left. skip: The documents to skip in the query. (optional) limit: The maximal amount of documents to return. (optional)
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/queries.rb', line 95 def all( = {}) query_parameters = {'collection' => collection}; endpoint = '/_api/simple/all' if and ['example'] and ['example'].any? endpoint = '/_api/simple/by-example' elsif and ['left'] and ['right'] and ['attribute'] endpoint = '/_api/simple/range' end res = transport.put(endpoint, :body => query_parameters.merge().to_json) if res.code == 201 and res.parsed_response and res.parsed_response["result"] query_result = QueryResult.new res["result"].each {|json_doc| query_result << self.new.build(json_doc)} query_result end end |
#attribute(attr_name) ⇒ Object
135 136 137 |
# File 'lib/queries.rb', line 135 def attribute(attr_name) Query.new(self).attribute(attr_name) end |
#closed(boolean) ⇒ Object
147 148 149 |
# File 'lib/queries.rb', line 147 def closed(boolean) Query.new(self).closed(boolean) end |
#first(options = {}) ⇒ Object
PUT /_api/simple/first-example This will return the first document matching a given example. The call expects a JSON hash array as body with the following attributes: collection: The identifier or name of the collection to query. example: The example.
115 116 117 118 119 120 121 |
# File 'lib/queries.rb', line 115 def first( = {}) query_parameters = {'collection' => collection}; endpoint = '/_api/simple/first-example' res = transport.put(endpoint, :body => query_parameters.merge().to_json) if res.code == 200 and res.parsed_response and (json_doc = res.parsed_response["document"]) self.new.build(json_doc) end end |
#left(number) ⇒ Object
139 140 141 |
# File 'lib/queries.rb', line 139 def left(number) Query.new(self).left(number) end |
#limit(number) ⇒ Object
127 128 129 |
# File 'lib/queries.rb', line 127 def limit(number) Query.new(self).limit(number) end |
#right(number) ⇒ Object
143 144 145 |
# File 'lib/queries.rb', line 143 def right(number) Query.new(self).right(number) end |