Class: Graphd::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/graphd/client.rb

Overview

Client initialized to talk to a DGraph instance Accepts multiple instances of Graphd::ClientStub Examples: client_stub = Graphd::ClientStub.new(‘localhost:9080’) client = Graphd::Cilent.new(client_stub)

Instance Method Summary collapse

Constructor Details

#initialize(*clients) ⇒ Client

Create a new instance of Graphd::Client

Parameters:

  • clients (Array<Graphd::ClientStub>)

    The stubs that can be used to communicate with a DGraph server

Raises:



17
18
19
20
21
22
# File 'lib/graphd/client.rb', line 17

def initialize(*clients)
  raise ClientError unless clients

  @clients = clients
  @jwt = Api::Jwt.new
end

Instance Method Details

#alter(operation) ⇒ Object



33
34
35
# File 'lib/graphd/client.rb', line 33

def alter(operation)
  client.alter(operation)
end

#check_versionString

Get the version of the DGraph server

Returns:

  • (String)

    the version of the DGraph server



27
28
29
30
31
# File 'lib/graphd/client.rb', line 27

def check_version
  request = Api::Check.new
  response = client.check_version(request)
  response.tag
end

#clientObject



47
48
49
# File 'lib/graphd/client.rb', line 47

def client
  @clients.sample
end

#txn(read_only: false, best_effort: false) ⇒ Transaction

Create a new transaction

Parameters:

  • read_only (true, false) (defaults to: false)

    whether the transaction should be read only

  • best_effort (true, false) (defaults to: false)

    Enable best-effort queries for the transaction

Returns:



43
44
45
# File 'lib/graphd/client.rb', line 43

def txn(read_only: false, best_effort: false)
  Transaction.new(self, read_only: read_only, best_effort: best_effort)
end