dlex v0.2.2 Dlex

Dgraph driver for Elixir.

This module handles the connection to Dgraph, providing pooling (via DBConnection), queries, mutations and transactions.

Link to this section Summary

Functions

Supervisor callback.

The same as Dlex.delete(conn, "", deletion, [])

The same as Dlex.delete(conn, query, deletion, []) or Dlex.delete(conn, "", deletion, opts)

Runs a mutation with delete target and returns the result or raises Dlex.Error if there was an error. See delete/2.

Runs a mutation with delete target and returns the result or raises Dlex.Error if there was an error. See delete/3.

Runs a mutation with delete target and returns the result or raises Dlex.Error if there was an error. See delete/4.

The same as Dlex.mutate(conn, "", mutation, [])

The same as Dlex.mutate(conn, query, mutation, []) or Dlex.mutate(conn, "", mutation, opts)

Send mutation to dgraph

Runs a mutation and returns the result or raises Dlex.Error if there was an error. See mutate/2.

Runs a mutation and returns the result or raises Dlex.Error if there was an error. See mutate/3.

Runs a mutation and returns the result or raises Dlex.Error if there was an error. See mutate/4.

Runs a query and returns the result or raises Dlex.Error if there was an error. See query/3.

Query schema of dgraph

Query schema of dgraph

Start dgraph connection process.

Execute serie of queries and mutations in a transactions

Link to this section Types

Link to this section Functions

Link to this function

alter(conn, statement, opts \\ [])
alter(conn(), iodata() | map(), Keyword.t()) ::
  {:ok, map()} | {:error, Dlex.Error.t() | term()}
alter(conn(), iodata() | map(), Keyword.t()) :: map()

Alter dgraph schema

Example

iex> Dlex.alter(conn, "name: string @index(term) .")
{:ok, ""}

Options

  • :timeout - Call timeout (default: 15000)
Link to this function

alter!(conn, statement, opts \\ [])

Alter dgraph schema

Link to this function

child_spec(opts)
child_spec(Keyword.t()) :: Supervisor.Spec.spec()

Supervisor callback.

For available options, see: start_link/1.

Link to this function

delete(conn, statement)

The same as Dlex.delete(conn, "", deletion, [])

Link to this function

delete(conn, query, statement)
delete(conn(), iodata() | map(), Keyword.t()) ::
  {:ok, map()} | {:error, Dlex.Error.t() | term()}

The same as Dlex.delete(conn, query, deletion, []) or Dlex.delete(conn, "", deletion, opts)

Link to this function

delete(conn, condition, statement, opts)

Send mutation to dgraph

Options:

  • return_json - if json with uids should be returned (default: false)

Example of usage

iex> mutation = "
     _:foo <name> "Foo" .
     _:foo <owns> _:bar .
      _:bar <name> "Bar" .
     "
iex> Dlex.delete(conn, mutation)
{:ok, %{"bar" => "0xfe04c", "foo" => "0xfe04b"}}

Using json

iex> json = %{"name" => "Foo",
              "owns" => [%{"name" => "Bar"}]}
     Dlex.delete(conn, json)
{:ok, %{"blank-0" => "0xfe04d", "blank-1" => "0xfe04e"}}

iex> Dlex.delete(conn, json, return_json: true)
{:ok,
 %{
   "name" => "Foo",
   "owns" => [%{"name" => "Bar", "uid" => "0xfe050"}],
   "uid" => "0xfe04f"
 }}

Options

  • :timeout - Call timeout (default: 15000)
Link to this function

delete!(conn, statement)

Runs a mutation with delete target and returns the result or raises Dlex.Error if there was an error. See delete/2.

Link to this function

delete!(conn, query_or_statement, statement_or_opts)

Runs a mutation with delete target and returns the result or raises Dlex.Error if there was an error. See delete/3.

Link to this function

delete!(conn, query, statement, opts)
delete!(conn(), iodata(), iodata() | map(), Keyword.t()) ::
  map() | no_return()

Runs a mutation with delete target and returns the result or raises Dlex.Error if there was an error. See delete/4.

Link to this function

mutate(conn, statement)

The same as Dlex.mutate(conn, "", mutation, [])

Link to this function

mutate(conn, query, statement)

The same as Dlex.mutate(conn, query, mutation, []) or Dlex.mutate(conn, "", mutation, opts)

Link to this function

mutate(conn, query, statement, opts)
mutate(conn(), iodata(), iodata() | map(), Keyword.t()) ::
  {:ok, map()} | {:error, Dlex.Error.t() | term()}

Send mutation to dgraph

Options:

  • return_json - if json with uids should be returned (default: false)

Example of usage

iex> mutation = "
     _:foo <name> "Foo" .
     _:foo <owns> _:bar .
      _:bar <name> "Bar" .
     "
iex> Dlex.mutate(conn, mutation)
{:ok, %{"bar" => "0xfe04c", "foo" => "0xfe04b"}}

Using json

iex> json = %{"name" => "Foo",
              "owns" => [%{"name" => "Bar"}]}
     Dlex.mutate(conn, json)
{:ok, %{"blank-0" => "0xfe04d", "blank-1" => "0xfe04e"}}
iex> Dlex.mutate(conn, json, return_json: true)
{:ok,
 %{
   "name" => "Foo",
   "owns" => [%{"name" => "Bar", "uid" => "0xfe050"}],
   "uid" => "0xfe04f"
 }}

Options

  • :timeout - Call timeout (default: 15000)
Link to this function

mutate!(conn, statement)

Runs a mutation and returns the result or raises Dlex.Error if there was an error. See mutate/2.

Link to this function

mutate!(conn, query_or_statement, statement_or_opts)

Runs a mutation and returns the result or raises Dlex.Error if there was an error. See mutate/3.

Link to this function

mutate!(conn, query, statement, opts)
mutate!(conn(), iodata(), iodata() | map(), Keyword.t()) ::
  map() | no_return()

Runs a mutation and returns the result or raises Dlex.Error if there was an error. See mutate/4.

Link to this function

query(conn, statement, parameters \\ %{}, opts \\ [])
query(conn(), iodata(), map(), Keyword.t()) ::
  {:ok, map()} | {:error, Dlex.Error.t() | term()}

Send query to dgraph

Example of usage

iex> query = "
     query foo($a: string) {
        foo(func: eq(name, $a)) {
          uid
          expand(_all_)
        }
      }
     "
iex> Dlex.query(conn, query, %{"$a" => "Foo"})
{:ok, %{"foo" => [%{"name" => "Foo", "uid" => "0xfe04d"}]}}
Link to this function

query!(conn, statement, parameters \\ %{}, opts \\ [])
query!(conn(), iodata(), map(), Keyword.t()) :: map() | no_return()

Runs a query and returns the result or raises Dlex.Error if there was an error. See query/3.

Link to this function

query_schema(conn)
query_schema(conn()) :: {:ok, map()} | {:error, Dlex.Error.t() | term()}

Query schema of dgraph

Link to this function

query_schema!(conn)
query_schema!(conn()) :: map() | no_return()

Query schema of dgraph

Link to this function

set(conn, statement, opts \\ [])
set(conn(), iodata() | map(), Keyword.t()) ::
  {:ok, map()} | {:error, Dlex.Error.t() | term()}

See mutate/3 for documentation.

Link to this function

set!(conn, statement, opts \\ [])
set!(conn(), iodata() | map(), Keyword.t()) :: map()

See mutate!/3 for documentation.

Link to this function

start_link(opts \\ [])
start_link(Keyword.t()) :: {:ok, pid()} | {:error, Dlex.Error.t() | term()}

Start dgraph connection process.

Options

  • :hostname - Server hostname (default: DGRAPH_HOST, than localhost)
  • :port - Server port (default: DGRAPH_PORT env var, then 9080)
  • :keepalive - Keepalive option for http client (default: :infinity)
  • :json_library - Specifies json library to use (default: Jason)
  • :transport - Specify if grpc or http should be used (default: grpc)
  • :connect_timeout - Connection timeout in milliseconds (default: 15000);
  • :timeout - Call timeout in milliseconds (default: 15000);

SSL/TLS configuration (automaticly enabled, if required files provided)

  • :cacertfile - Path to your CA certificate. Should be provided for SSL authentication
  • :certfile - Path to client certificate. Should be additionally provided for TSL authentication
  • :keyfile - Path to client key. Should be additionally provided for TSL authentication

DBConnection options

  • :backoff_min - The minimum backoff interval (default: 1_000)
  • :backoff_max - The maximum backoff interval (default: 30_000)
  • :backoff_type - The backoff strategy, :stop for no backoff and to stop, :exp for exponential, :rand for random and :rand_exp for random exponential (default: :rand_exp)
  • :name - A name to register the started process (see the :name option in GenServer.start_link/3)
  • :pool - Chooses the pool to be started
  • :pool_size - Chooses the size of the pool
  • :queue_target in microseconds, defaults to 50
  • :queue_interval in microseconds, defaults to 1000

Example of usage

iex> {:ok, conn} = Dlex.start_link()
{:ok, #PID<0.216.0>}
Link to this function

transaction(conn, fun, opts \\ [])
transaction(conn(), (DBConnection.t() -> result :: any()), Keyword.t()) ::
  {:ok, result :: any()} | {:error, any()}

Execute serie of queries and mutations in a transactions