Class: Arango::AQL
- Inherits:
-
Object
- Object
- Arango::AQL
- Includes:
- Helper::Satisfaction
- Defined in:
- lib/arango/aql.rb
Overview
Arango Query Language
Instance Attribute Summary collapse
-
#batch_size ⇒ Object
Returns the value of attribute batch_size.
-
#bind_vars ⇒ Object
Returns the value of attribute bind_vars.
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#cached ⇒ Object
readonly
Returns the value of attribute cached.
-
#count ⇒ Object
Returns the value of attribute count.
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#extra ⇒ Object
readonly
Returns the value of attribute extra.
-
#failOnWarning ⇒ Boolean
readonly
Fail on warning.
-
#fullCount ⇒ Integer
readonly
Full count.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#id_cache ⇒ Object
readonly
Returns the value of attribute id_cache.
-
#intermediateCommitCount ⇒ Integer
readonly
Intermediate commit count.
-
#intermediateCommitSize ⇒ Integer
readonly
Intermediate commit size.
-
#maxPlans ⇒ Integer
readonly
Max plans.
-
#maxTransactionSize ⇒ Integer
readonly
Max transaction size.
-
#maxWarningCount ⇒ Integer
readonly
Max warning count.
-
#optimizer_rules ⇒ Object
Returns the value of attribute optimizer_rules.
-
#options ⇒ Object
Returns the value of attribute options.
-
#profile ⇒ Hash
readonly
Profile.
-
#query ⇒ Object
Returns the value of attribute query.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#run_time ⇒ Object
readonly
Returns the value of attribute run_time.
-
#satelliteSyncWait ⇒ Boolean
readonly
Satellite sync wait.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#skipInaccessibleCollections ⇒ Boolean
readonly
Skip inaccessible collections.
-
#started ⇒ Object
readonly
Returns the value of attribute started.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
-
#ttl ⇒ Object
Returns the value of attribute ttl.
Class Method Summary collapse
-
.from_result_hash(query_hash) ⇒ Arango::AQL
-
id: the query’s id * query: the query string (potentially truncated) * bindVars: the bind parameter values used by the query * started: the date and time when the query was started * runTime: the query’s run time up to the point the list of queries was queried * state: the query’s current execution state (as a string) * stream: whether or not the query uses a streaming cursor.
-
Instance Method Summary collapse
-
#delete ⇒ Object
delete current query.
-
#execute ⇒ Object
see #request.
-
#explain ⇒ Object
explain current query.
-
#has_more? ⇒ Boolean
check if more results are pending.
-
#initialize(query:, database:, batch_size: nil, bind_vars: nil, cache: nil, count: nil, fail_on_warning: nil, full_count: nil, intermediate_commit_count: nil, intermediate_commit_size: nil, max_plans: nil, max_transaction_size: nil, max_warning_count: nil, memory_limit: nil, optimizer_rules: nil, profile: nil, satellite_sync_wait: nil, skip_inaccessible_collections: nil, ttl: nil, query_id: nil, run_time: nil, started: nil, state: nil, stream: nil, block: nil, &ruby_block) ⇒ AQL
constructor
Create a new AQL query.
-
#kill ⇒ Object
kill current query.
-
#next ⇒ Arango::AQL
get next result of query.
-
#parse ⇒ Object
parse current query.
-
#request ⇒ Arango::AQL
run an AQL request.
-
#to_h ⇒ Hash
return Hash representation.
Methods included from Helper::Satisfaction
#satisfy_category?, #satisfy_class?, #satisfy_class_or_string?, #satisfy_module?, #satisfy_module_or_nil?, #satisfy_module_or_string?, #warning_deprecated
Constructor Details
#initialize(query:, database:, batch_size: nil, bind_vars: nil, cache: nil, count: nil, fail_on_warning: nil, full_count: nil, intermediate_commit_count: nil, intermediate_commit_size: nil, max_plans: nil, max_transaction_size: nil, max_warning_count: nil, memory_limit: nil, optimizer_rules: nil, profile: nil, satellite_sync_wait: nil, skip_inaccessible_collections: nil, ttl: nil, query_id: nil, run_time: nil, started: nil, state: nil, stream: nil, block: nil, &ruby_block) ⇒ AQL
Create a new AQL query
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/arango/aql.rb', line 53 def initialize(query:, database:, batch_size: nil, bind_vars: nil, cache: nil, count: nil, fail_on_warning: nil, full_count: nil, intermediate_commit_count: nil, intermediate_commit_size: nil, max_plans: nil, max_transaction_size: nil, max_warning_count: nil, memory_limit: nil, optimizer_rules: nil, profile: nil, satellite_sync_wait: nil, skip_inaccessible_collections: nil, ttl: nil, query_id: nil, run_time: nil, started: nil, state: nil, stream: nil, block: nil, &ruby_block) block = ruby_block if block_given? satisfy_class?(query, String) @query = query @database = database @server = database.server @block = block @count = count @batch_size = batch_size @cache = cache @memory_limit = memory_limit @ttl = ttl @bind_vars = bind_vars @has_more = false @id = nil # cursor id @query_id = query_id @result = nil @run_time = run_time @started = started @state = state @stream = stream = {} set_option(fail_on_warning, 'failOnWarning', :fail_on_warning) if fail_on_warning set_option(full_count, 'fullCount', :full_count) if full_count set_option(intermediate_commit_count, 'intermediateCommitCount', :intermediate_commit_count) if intermediate_commit_count set_option(intermediate_commit_size, 'intermediateCommitSize', :intermediate_commit_size) if intermediate_commit_size set_option(max_plans, 'maxPlans', :max_plans) if max_plans set_option(max_transaction_size, 'maxTransactionSize', :max_transaction_size) if max_transaction_size set_option(max_warning_count, 'maxWarningCount', :max_warning_count) if max_warning_count set_option(profile, 'profile', :profile) if profile set_option(satellite_sync_wait, 'satelliteSyncWait', :satellite_sync_wait) if satellite_sync_wait set_option(skip_inaccessible_collections, 'skipInaccessibleCollections', :skip_inaccessible_collections) if skip_inaccessible_collections send(:optimizer_rules=, optimizer_rules) if optimizer_rules end |
Instance Attribute Details
#batch_size ⇒ Object
Returns the value of attribute batch_size.
138 139 140 |
# File 'lib/arango/aql.rb', line 138 def batch_size @batch_size end |
#bind_vars ⇒ Object
Returns the value of attribute bind_vars.
138 139 140 |
# File 'lib/arango/aql.rb', line 138 def bind_vars @bind_vars end |
#cache ⇒ Object
Returns the value of attribute cache.
138 139 140 |
# File 'lib/arango/aql.rb', line 138 def cache @cache end |
#cached ⇒ Object (readonly)
Returns the value of attribute cached.
140 141 142 |
# File 'lib/arango/aql.rb', line 140 def cached @cached end |
#count ⇒ Object
Returns the value of attribute count.
138 139 140 |
# File 'lib/arango/aql.rb', line 138 def count @count end |
#database ⇒ Object (readonly)
Returns the value of attribute database.
140 141 142 |
# File 'lib/arango/aql.rb', line 140 def database @database end |
#extra ⇒ Object (readonly)
Returns the value of attribute extra.
140 141 142 |
# File 'lib/arango/aql.rb', line 140 def extra @extra end |
#failOnWarning ⇒ Boolean (readonly)
Returns fail on warning.
129 130 131 132 133 134 135 136 |
# File 'lib/arango/aql.rb', line 129 %w[failOnWarning fullCount intermediateCommitCount intermediateCommitSize maxPlans maxTransactionSize maxWarningCount profile satelliteSyncWait skipInaccessibleCollections].each do |param_name| var_name = param_name.underscore.to_sym attr_reader var_name define_method("#{var_name}=") do |value| set_option(value, param_name, var_name) end end |
#fullCount ⇒ Integer (readonly)
Returns full count.
129 130 131 132 133 134 135 136 |
# File 'lib/arango/aql.rb', line 129 %w[failOnWarning fullCount intermediateCommitCount intermediateCommitSize maxPlans maxTransactionSize maxWarningCount profile satelliteSyncWait skipInaccessibleCollections].each do |param_name| var_name = param_name.underscore.to_sym attr_reader var_name define_method("#{var_name}=") do |value| set_option(value, param_name, var_name) end end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
140 141 142 |
# File 'lib/arango/aql.rb', line 140 def id @id end |
#id_cache ⇒ Object (readonly)
Returns the value of attribute id_cache.
140 141 142 |
# File 'lib/arango/aql.rb', line 140 def id_cache @id_cache end |
#intermediateCommitCount ⇒ Integer (readonly)
Returns intermediate commit count.
129 130 131 132 133 134 135 136 |
# File 'lib/arango/aql.rb', line 129 %w[failOnWarning fullCount intermediateCommitCount intermediateCommitSize maxPlans maxTransactionSize maxWarningCount profile satelliteSyncWait skipInaccessibleCollections].each do |param_name| var_name = param_name.underscore.to_sym attr_reader var_name define_method("#{var_name}=") do |value| set_option(value, param_name, var_name) end end |
#intermediateCommitSize ⇒ Integer (readonly)
Returns intermediate commit size.
129 130 131 132 133 134 135 136 |
# File 'lib/arango/aql.rb', line 129 %w[failOnWarning fullCount intermediateCommitCount intermediateCommitSize maxPlans maxTransactionSize maxWarningCount profile satelliteSyncWait skipInaccessibleCollections].each do |param_name| var_name = param_name.underscore.to_sym attr_reader var_name define_method("#{var_name}=") do |value| set_option(value, param_name, var_name) end end |
#maxPlans ⇒ Integer (readonly)
Returns max plans.
129 130 131 132 133 134 135 136 |
# File 'lib/arango/aql.rb', line 129 %w[failOnWarning fullCount intermediateCommitCount intermediateCommitSize maxPlans maxTransactionSize maxWarningCount profile satelliteSyncWait skipInaccessibleCollections].each do |param_name| var_name = param_name.underscore.to_sym attr_reader var_name define_method("#{var_name}=") do |value| set_option(value, param_name, var_name) end end |
#maxTransactionSize ⇒ Integer (readonly)
Returns max transaction size.
129 130 131 132 133 134 135 136 |
# File 'lib/arango/aql.rb', line 129 %w[failOnWarning fullCount intermediateCommitCount intermediateCommitSize maxPlans maxTransactionSize maxWarningCount profile satelliteSyncWait skipInaccessibleCollections].each do |param_name| var_name = param_name.underscore.to_sym attr_reader var_name define_method("#{var_name}=") do |value| set_option(value, param_name, var_name) end end |
#maxWarningCount ⇒ Integer (readonly)
Returns max warning count.
129 130 131 132 133 134 135 136 |
# File 'lib/arango/aql.rb', line 129 %w[failOnWarning fullCount intermediateCommitCount intermediateCommitSize maxPlans maxTransactionSize maxWarningCount profile satelliteSyncWait skipInaccessibleCollections].each do |param_name| var_name = param_name.underscore.to_sym attr_reader var_name define_method("#{var_name}=") do |value| set_option(value, param_name, var_name) end end |
#optimizer_rules ⇒ Object
Returns the value of attribute optimizer_rules.
140 141 142 |
# File 'lib/arango/aql.rb', line 140 def optimizer_rules @optimizer_rules end |
#options ⇒ Object
Returns the value of attribute options.
138 139 140 |
# File 'lib/arango/aql.rb', line 138 def end |
#profile ⇒ Hash (readonly)
Returns profile.
129 130 131 132 133 134 135 136 |
# File 'lib/arango/aql.rb', line 129 %w[failOnWarning fullCount intermediateCommitCount intermediateCommitSize maxPlans maxTransactionSize maxWarningCount profile satelliteSyncWait skipInaccessibleCollections].each do |param_name| var_name = param_name.underscore.to_sym attr_reader var_name define_method("#{var_name}=") do |value| set_option(value, param_name, var_name) end end |
#query ⇒ Object
Returns the value of attribute query.
138 139 140 |
# File 'lib/arango/aql.rb', line 138 def query @query end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
140 141 142 |
# File 'lib/arango/aql.rb', line 140 def result @result end |
#run_time ⇒ Object (readonly)
Returns the value of attribute run_time.
141 142 143 |
# File 'lib/arango/aql.rb', line 141 def run_time @run_time end |
#satelliteSyncWait ⇒ Boolean (readonly)
Returns satellite sync wait.
129 130 131 132 133 134 135 136 |
# File 'lib/arango/aql.rb', line 129 %w[failOnWarning fullCount intermediateCommitCount intermediateCommitSize maxPlans maxTransactionSize maxWarningCount profile satelliteSyncWait skipInaccessibleCollections].each do |param_name| var_name = param_name.underscore.to_sym attr_reader var_name define_method("#{var_name}=") do |value| set_option(value, param_name, var_name) end end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
140 141 142 |
# File 'lib/arango/aql.rb', line 140 def server @server end |
#skipInaccessibleCollections ⇒ Boolean (readonly)
Returns skip inaccessible collections.
129 130 131 132 133 134 135 136 |
# File 'lib/arango/aql.rb', line 129 %w[failOnWarning fullCount intermediateCommitCount intermediateCommitSize maxPlans maxTransactionSize maxWarningCount profile satelliteSyncWait skipInaccessibleCollections].each do |param_name| var_name = param_name.underscore.to_sym attr_reader var_name define_method("#{var_name}=") do |value| set_option(value, param_name, var_name) end end |
#started ⇒ Object (readonly)
Returns the value of attribute started.
141 142 143 |
# File 'lib/arango/aql.rb', line 141 def started @started end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
141 142 143 |
# File 'lib/arango/aql.rb', line 141 def state @state end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
141 142 143 |
# File 'lib/arango/aql.rb', line 141 def stream @stream end |
#ttl ⇒ Object
Returns the value of attribute ttl.
138 139 140 |
# File 'lib/arango/aql.rb', line 138 def ttl @ttl end |
Class Method Details
.from_result_hash(query_hash) ⇒ Arango::AQL
-
id: the query’s id
-
query: the query string (potentially truncated)
-
bindVars: the bind parameter values used by the query
-
started: the date and time when the query was started
-
runTime: the query’s run time up to the point the list of queries was queried
-
state: the query’s current execution state (as a string)
-
stream: whether or not the query uses a streaming cursor
19 20 21 22 23 |
# File 'lib/arango/aql.rb', line 19 def from_result_hash(query_hash) new_query_hash = query_hash.transform_keys { |k| k.to_s.underscore.to_sym } new_query_hash[:query_id] = query_hash.delete(:id) Arango::AQL.new(**new_query_hash) end |
Instance Method Details
#delete ⇒ Object
delete current query
205 206 207 208 |
# File 'lib/arango/aql.rb', line 205 def delete Arango::Requests::Cursor::Delete.execute(server: @server, args: { id: @id }) true end |
#execute ⇒ Object
see #request
188 189 190 |
# File 'lib/arango/aql.rb', line 188 def execute request end |
#explain ⇒ Object
explain current query
219 220 221 222 223 224 225 226 |
# File 'lib/arango/aql.rb', line 219 def explain body = { query: @query, options: } body[:bindVars] = @bind_vars if @bind_vars Arango::Requests::AQL::Explain.execute(server: @server, body: body) end |
#has_more? ⇒ Boolean
check if more results are pending
145 146 147 |
# File 'lib/arango/aql.rb', line 145 def has_more? @has_more end |
#kill ⇒ Object
kill current query
211 212 213 214 |
# File 'lib/arango/aql.rb', line 211 def kill Arango::Requests::AQL::KillQuery.execute(server: @server, args: { id: @query_id }) true end |
#next ⇒ Arango::AQL
get next result of query
194 195 196 197 198 199 200 201 202 |
# File 'lib/arango/aql.rb', line 194 def next if @has_more result = Arango::Requests::Cursor::NextBatch.execute(server: @server, args: { id: @id }) set_instance_vars(result) self else raise Arango::Error.new err: :no_other_aql_next, data: { has_more: false } end end |
#parse ⇒ Object
parse current query
229 230 231 |
# File 'lib/arango/aql.rb', line 229 def parse Arango::Requests::AQL::Parse.execute(server: @server, body: { query: @query }) end |
#request ⇒ Arango::AQL
run an AQL request
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/arango/aql.rb', line 170 def request body = { batchSize: @batch_size, cache: @cache, count: @count, memoryLimit: @memory_limit, options: , query: @query, ttl: @ttl } body[:bindVars] = @bind_vars if @bind_vars result = Arango::Requests::Cursor::Create.execute(server: @server, body: body) set_instance_vars(result) @block ? @block.call(self, result) : self end |
#to_h ⇒ Hash
return Hash representation
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/arango/aql.rb', line 151 def to_h { batchSize: @batch_size, bindVars: @bind_vars, cache: @cache, count: @count, database: @database.name, idCache: @id_cache, memoryLimit: @memory_limit, options: , query: @query, result: @result, ttl: @ttl }.delete_if{|_,v| v.nil?} end |