Class: ArangoAQL

Inherits:
ArangoServer show all
Defined in:
lib/ArangoRB_AQL.rb

Overview

AQL ===

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ArangoServer

address, async, async=, batch, cancelAsync, changePropertyWAL, checkPort, cluster, cluster=, clusterRoundtrip, clusterStatistics, collection, collection=, createDumpBatch, database, database=, databaseVersion, databases, default_server, destroyAllAsync, destroyAsync, destroyCluster, destroyDumpBatch, destroyExpiredAsync, echo, endpoints, execute, executeCluster, executeClusterHead, executeClusterPut, fetchAsync, flushWAL, graph, graph=, log, pendingAsync, prolongDumpBatch, propertyWAL, reload, request, restart, retrieveAsync, retrieveDoneAsync, retrievePendingAsync, return_result, return_result_async, role, server, serverId, shutdown, sleep, statistics, tasks, test, time, transactions, updateCluster, user, user=, username, users, verbose, verbose=, version

Constructor Details

#initialize(query: nil, batchSize: nil, ttl: nil, cache: nil, options: nil, bindVars: nil, database: @@database) ⇒ ArangoAQL

TESTED



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ArangoRB_AQL.rb', line 4

def initialize(query: nil, batchSize: nil, ttl: nil, cache: nil, options: nil, bindVars: nil, database: @@database)  # TESTED
  if query.is_a?(String)
    @query = query
  elsif query.is_a?(ArangoAQL)
    @query = query.query
  else
    raise "query should be String or ArangoAQL instance, not a #{query.class}"
  end

  if database.is_a?(String)
    @database = database
  elsif database.is_a?(ArangoDatabase)
    @database = database.database
  else
    raise "databaseshould be String or ArangoDatabase instance, not a #{database.class}"
  end

  @batchSize = batchSize
  @ttl = ttl
  @cache = cache
  @options = options
  @bindVars = bindVars

  @count = true
  @quantity = nil
  @hasMore = false
  @id = ""
  @result = []
  @idCache = "AQL_#{@query}"
end

Instance Attribute Details

#batchSizeObject Also known as: size

Returns the value of attribute batchSize.



35
36
37
# File 'lib/ArangoRB_AQL.rb', line 35

def batchSize
  @batchSize
end

#bindVarsObject

Returns the value of attribute bindVars.



35
36
37
# File 'lib/ArangoRB_AQL.rb', line 35

def bindVars
  @bindVars
end

#cacheObject

Returns the value of attribute cache.



35
36
37
# File 'lib/ArangoRB_AQL.rb', line 35

def cache
  @cache
end

#countObject

Returns the value of attribute count.



35
36
37
# File 'lib/ArangoRB_AQL.rb', line 35

def count
  @count
end

#hasMoreObject (readonly)

Returns the value of attribute hasMore.



36
37
38
# File 'lib/ArangoRB_AQL.rb', line 36

def hasMore
  @hasMore
end

#idObject (readonly)

Returns the value of attribute id.



36
37
38
# File 'lib/ArangoRB_AQL.rb', line 36

def id
  @id
end

#idCacheObject (readonly)

Returns the value of attribute idCache.



36
37
38
# File 'lib/ArangoRB_AQL.rb', line 36

def idCache
  @idCache
end

#optionsObject

Returns the value of attribute options.



35
36
37
# File 'lib/ArangoRB_AQL.rb', line 35

def options
  @options
end

#quantityObject

Returns the value of attribute quantity.



35
36
37
# File 'lib/ArangoRB_AQL.rb', line 35

def quantity
  @quantity
end

#queryObject

Returns the value of attribute query.



35
36
37
# File 'lib/ArangoRB_AQL.rb', line 35

def query
  @query
end

#resultObject (readonly)

Returns the value of attribute result.



36
37
38
# File 'lib/ArangoRB_AQL.rb', line 36

def result
  @result
end

#ttlObject

Returns the value of attribute ttl.



35
36
37
# File 'lib/ArangoRB_AQL.rb', line 35

def ttl
  @ttl
end

Instance Method Details

#changeProperties(slowQueryThreshold: nil, enabled: nil, maxSlowQueries: nil, trackSlowQueries: nil, maxQueryStringLength: nil) ⇒ Object

TESTED



160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/ArangoRB_AQL.rb', line 160

def changeProperties(slowQueryThreshold: nil, enabled: nil, maxSlowQueries: nil, trackSlowQueries: nil, maxQueryStringLength: nil) # TESTED
  body = {
    "slowQueryThreshold" => slowQueryThreshold,
    "enabled" => enabled,
    "maxSlowQueries" => maxSlowQueries,
    "trackSlowQueries" => trackSlowQueries,
    "maxQueryStringLength" => maxQueryStringLength
  }.delete_if{|k,v| v.nil?}
  request = @@request.merge({ :body => body.to_json })
  result = self.class.put("/_db/#{@database}/_api/query/properties", request)
  return_result result: result
end

#currentObject

TESTED



138
139
140
141
# File 'lib/ArangoRB_AQL.rb', line 138

def current # TESTED
  result = self.class.get("/_db/#{@database}/_api/query/current", @@request)
  return_result result: result
end

#databaseObject



59
60
61
# File 'lib/ArangoRB_AQL.rb', line 59

def database
  ArangoDatabase.new(database: @database)
end

#executeObject

EXECUTE QUERY ===



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
# File 'lib/ArangoRB_AQL.rb', line 65

def execute # TESTED
  body = {
    "query" => @query,
    "count" => count,
    "batchSize" => @batchSize,
    "ttl" => @ttl,
    "cache" => @cache,
    "options" => @options,
    "bindVars" => @bindVars
  }.delete_if{|k,v| v.nil?}
  request = @@request.merge({ :body => body.to_json })
  result = self.class.post("/_db/#{@database}/_api/cursor", request)
  return result.headers["x-arango-async-id"] if @@async == "store"
  return true if @@async
  result = result.parsed_response
  return @@verbose ? result : result["errorMessage"] if result["error"]
  @quantity = result["count"]
  @hasMore = result["hasMore"]
  @id = result["id"]
  if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key"))
    @result = result["result"]
  else
    @result = result["result"].map{|x| ArangoDocument.new(key: x["_key"], collection: x["_id"].split("/")[0], database: @database, body: x)}
  end
  return @@verbose ? result : self
end

#explainObject

PROPERTY QUERY ===



115
116
117
118
119
120
121
122
123
124
# File 'lib/ArangoRB_AQL.rb', line 115

def explain  # TESTED
  body = {
    "query" => @query,
    "options" => @options,
    "bindVars" => @bindVars
  }.delete_if{|k,v| v.nil?}
  request = @@request.merge({ :body => body.to_json })
  result = self.class.post("/_db/#{@database}/_api/explain", request)
  return_result result: result
end

#kill(id: @id) ⇒ Object

TESTED



155
156
157
158
# File 'lib/ArangoRB_AQL.rb', line 155

def kill(id: @id) # TESTED
  result = self.class.delete("/_db/#{@database}/_api/query/#{id}", @@request)
  return_result result: result, caseTrue: true
end

#nextObject

TESTED



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/ArangoRB_AQL.rb', line 92

def next  # TESTED
  unless @hasMore
    print "No other results"
  else
    result = self.class.put("/_db/#{@database}/_api/cursor/#{@id}", @@request)
    return result.headers["x-arango-async-id"] if @@async == "store"
    return true if @@async
    result = result.parsed_response
    return @@verbose ? result : result["errorMessage"] if result["error"]
    @count = result["count"]
    @hasMore = result["hasMore"]
    @id = result["id"]
    if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key"))
      @result = result["result"]
    else
      @result = result["result"].map{|x| ArangoDocument.new(key: x["_key"], collection: x["_id"].split("/")[0], database: @database, body: x)}
    end
    return @@verbose ? result : self
  end
end

#parseObject

TESTED



126
127
128
129
130
131
# File 'lib/ArangoRB_AQL.rb', line 126

def parse # TESTED
  body = { "query" => @query }
  request = @@request.merge({ :body => body.to_json })
  result = self.class.post("/_db/#{@database}/_api/query", request)
  return_result result: result
end

#propertiesObject

TESTED



133
134
135
136
# File 'lib/ArangoRB_AQL.rb', line 133

def properties # TESTED
  result = self.class.get("/_db/#{@database}/_api/query/properties", @@request)
  return_result result: result
end

#return_result(result:, caseTrue: false) ⇒ Object

UTILITY ===



175
176
177
178
179
180
# File 'lib/ArangoRB_AQL.rb', line 175

def return_result(result:, caseTrue: false)
  return result.headers["x-arango-async-id"] if @@async == "store"
  return true if @@async
  result = result.parsed_response
  @@verbose ? result : (result.is_a?(Hash) && result["error"]) ? result["errorMessage"] : caseTrue ? true : result
end

#slowObject

TESTED



143
144
145
146
# File 'lib/ArangoRB_AQL.rb', line 143

def slow # TESTED
  result = self.class.get("/_db/#{@database}/_api/query/slow", @@request)
  return_result result: result
end

#stopSlowObject

DELETE ===



150
151
152
153
# File 'lib/ArangoRB_AQL.rb', line 150

def stopSlow # TESTED
  result = self.class.delete("/_db/#{@database}/_api/query/slow", @@request)
  return_result result: result, caseTrue: true
end

#to_hashObject Also known as: to_h

RETRIEVE ===



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ArangoRB_AQL.rb', line 42

def to_hash
  {
    "query" => @query,
    "database" => @database,
    "result" => @result.map{|x| x.is_a?(ArangoServer) ? x.to_h : x},
    "count" => @count,
    "quantity" => @quantity,
    "ttl" => @ttl,
    "cache" => @cache,
    "batchSize" => @batchSize,
    "bindVars" => @bindVars,
    "options" => @options,
    "idCache" => @idCache,
  }.delete_if{|k,v| v.nil?}
end