class Arango::Transaction
Attributes
action[RW]
intermedateCommitSize[RW]
intermediateCommitCount[RW]
lockTimeout[RW]
maxTransactionSize[RW]
params[RW]
waitForSync[RW]
Public Class Methods
new(database:, action:, write: [], read: [], params: nil, maxTransactionSize: nil, lockTimeout: nil, waitForSync: nil, intermediateCommitCount: nil, intermedateCommitSize: nil)
click to toggle source
# File lib/Transaction.rb, line 9 def initialize(database:, action:, write: [], read: [], params: nil, maxTransactionSize: nil, lockTimeout: nil, waitForSync: nil, intermediateCommitCount: nil, intermedateCommitSize: nil) assign_database(database) @action = action @write = return_write_or_read(write) @read = return_write_or_read(read) @params = params @maxTransactionSize = maxTransactionSize @lockTimeout = lockTimeout @waitForSync = waitForSync @intermediateCommitCount = intermediateCommitCount @intermedateCommitSize = intermedateCommitSize @result = nil end
Public Instance Methods
addRead(read)
click to toggle source
# File lib/Transaction.rb, line 45 def addRead(read) read = return_write_or_read(read) @read ||= [] @read << read end
addWrite(write)
click to toggle source
# File lib/Transaction.rb, line 35 def addWrite(write) write = return_write_or_read(write) @write ||= [] @write << write end
execute(action: @action, params: @params, maxTransactionSize: @maxTransactionSize, lockTimeout: @lockTimeout, waitForSync: @waitForSync, intermediateCommitCount: @intermediateCommitCount, intermedateCommitSize: @intermedateCommitSize)
click to toggle source
EXECUTE ===¶ ↑
# File lib/Transaction.rb, line 91 def execute(action: @action, params: @params, maxTransactionSize: @maxTransactionSize, lockTimeout: @lockTimeout, waitForSync: @waitForSync, intermediateCommitCount: @intermediateCommitCount, intermedateCommitSize: @intermedateCommitSize) body = { "collections": { "read": @read.map{|x| x.name}, "write": @write.map{|x| x.name} }, "action": action, "params": params, "lockTimeout": lockTimeout, "waitForSync": waitForSync, "maxTransactionSize": maxTransactionSize, "intermediateCommitCount": intermediateCommitCount, "intermedateCommitSize": intermedateCommitSize } result = @database.request("POST", "_api/transaction", body: body) return result if @server.async != false @result = result[:result] return return_directly?(result) ? result : result[:result] end
read=(read)
click to toggle source
# File lib/Transaction.rb, line 41 def read=(read) @read = return_write_or_read(read) end
to_h()
click to toggle source
write=(write)
click to toggle source
# File lib/Transaction.rb, line 31 def write=(write) @write = return_write_or_read(write) end
Private Instance Methods
return_collection(collection, type=nil)
click to toggle source
# File lib/Transaction.rb, line 65 def return_collection(collection, type=nil) satisfy_class?(collection, [Arango::Collection, String]) case collection when Arango::Collection return collection when String return Arango::Collection.new(name: collection, database: @database) end end
return_write_or_read(value)
click to toggle source
# File lib/Transaction.rb, line 51 def return_write_or_read(value) case value when Array return value.map{|x| return_collection(x)} when String, Arango::Collection return [return_collection(value)] when NilClass return [] else raise Arango::Error.new err: :read_or_write_should_be_string_or_collections, data: {"wrong_value": value, "wrong_class": value.class} end end