Class: Arango::AQL

Inherits:
Object
  • Object
show all
Includes:
Helper::Satisfaction
Defined in:
lib/arango/aql.rb

Overview

Arango Query Language

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

Parameters:

  • query
  • database
  • batch_size (defaults to: nil)
  • bind_vars (defaults to: nil)
  • cache (defaults to: nil)
  • count (defaults to: nil)
  • fail_on_warning (defaults to: nil)
  • full_count (defaults to: nil)
  • intermediate_commit_count (defaults to: nil)
  • intermediate_commit_size (defaults to: nil)
  • max_plans (defaults to: nil)
  • max_transaction_size (defaults to: nil)
  • max_warning_count (defaults to: nil)
  • memory_limit (defaults to: nil)
  • optimizer_rules (defaults to: nil)
  • profile (defaults to: nil)
  • satellite_sync_wait (defaults to: nil)
  • skip_inaccessible_collections (defaults to: nil)
  • ttl (defaults to: nil)
  • query_id (defaults to: nil)
  • run_time (defaults to: nil)
  • started (defaults to: nil)
  • state (defaults to: nil)
  • stream (defaults to: nil)
  • block (defaults to: nil)
  • &ruby_block


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

  @options  = {}
  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_sizeObject

Returns the value of attribute batch_size.



138
139
140
# File 'lib/arango/aql.rb', line 138

def batch_size
  @batch_size
end

#bind_varsObject

Returns the value of attribute bind_vars.



138
139
140
# File 'lib/arango/aql.rb', line 138

def bind_vars
  @bind_vars
end

#cacheObject

Returns the value of attribute cache.



138
139
140
# File 'lib/arango/aql.rb', line 138

def cache
  @cache
end

#cachedObject (readonly)

Returns the value of attribute cached.



140
141
142
# File 'lib/arango/aql.rb', line 140

def cached
  @cached
end

#countObject

Returns the value of attribute count.



138
139
140
# File 'lib/arango/aql.rb', line 138

def count
  @count
end

#databaseObject (readonly)

Returns the value of attribute database.



140
141
142
# File 'lib/arango/aql.rb', line 140

def database
  @database
end

#extraObject (readonly)

Returns the value of attribute extra.



140
141
142
# File 'lib/arango/aql.rb', line 140

def extra
  @extra
end

#failOnWarningBoolean (readonly)

Returns fail on warning.

Returns:

  • (Boolean)

    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

#fullCountInteger (readonly)

Returns full count.

Returns:

  • (Integer)

    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

#idObject (readonly)

Returns the value of attribute id.



140
141
142
# File 'lib/arango/aql.rb', line 140

def id
  @id
end

#id_cacheObject (readonly)

Returns the value of attribute id_cache.



140
141
142
# File 'lib/arango/aql.rb', line 140

def id_cache
  @id_cache
end

#intermediateCommitCountInteger (readonly)

Returns intermediate commit count.

Returns:

  • (Integer)

    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

#intermediateCommitSizeInteger (readonly)

Returns intermediate commit size.

Returns:

  • (Integer)

    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

#maxPlansInteger (readonly)

Returns max plans.

Returns:

  • (Integer)

    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

#maxTransactionSizeInteger (readonly)

Returns max transaction size.

Returns:

  • (Integer)

    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

#maxWarningCountInteger (readonly)

Returns max warning count.

Returns:

  • (Integer)

    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_rulesObject

Returns the value of attribute optimizer_rules.



140
141
142
# File 'lib/arango/aql.rb', line 140

def optimizer_rules
  @optimizer_rules
end

#optionsObject

Returns the value of attribute options.



138
139
140
# File 'lib/arango/aql.rb', line 138

def options
  @options
end

#profileHash (readonly)

Returns profile.

Returns:

  • (Hash)

    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

#queryObject

Returns the value of attribute query.



138
139
140
# File 'lib/arango/aql.rb', line 138

def query
  @query
end

#resultObject (readonly)

Returns the value of attribute result.



140
141
142
# File 'lib/arango/aql.rb', line 140

def result
  @result
end

#run_timeObject (readonly)

Returns the value of attribute run_time.



141
142
143
# File 'lib/arango/aql.rb', line 141

def run_time
  @run_time
end

#satelliteSyncWaitBoolean (readonly)

Returns satellite sync wait.

Returns:

  • (Boolean)

    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

#serverObject (readonly)

Returns the value of attribute server.



140
141
142
# File 'lib/arango/aql.rb', line 140

def server
  @server
end

#skipInaccessibleCollectionsBoolean (readonly)

Returns skip inaccessible collections.

Returns:

  • (Boolean)

    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

#startedObject (readonly)

Returns the value of attribute started.



141
142
143
# File 'lib/arango/aql.rb', line 141

def started
  @started
end

#stateObject (readonly)

Returns the value of attribute state.



141
142
143
# File 'lib/arango/aql.rb', line 141

def state
  @state
end

#streamObject (readonly)

Returns the value of attribute stream.



141
142
143
# File 'lib/arango/aql.rb', line 141

def stream
  @stream
end

#ttlObject

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

Parameters:

  • query_hash (Hash)

Returns:



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

#deleteObject

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

#executeObject

see #request



188
189
190
# File 'lib/arango/aql.rb', line 188

def execute
  request
end

#explainObject

explain current query



219
220
221
222
223
224
225
226
# File 'lib/arango/aql.rb', line 219

def explain
  body = {
    query:    @query,
    options:  @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

Returns:

  • (Boolean)


145
146
147
# File 'lib/arango/aql.rb', line 145

def has_more?
  @has_more
end

#killObject

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

#nextArango::AQL

get next result of query

Returns:



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

#parseObject

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

#requestArango::AQL

run an AQL request

Parameters:

  • &block

Returns:



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:     @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_hHash

return Hash representation

Returns:

  • (Hash)


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:     @options,
    query:       @query,
    result:      @result,
    ttl:         @ttl
  }.delete_if{|_,v| v.nil?}
end