dlex v0.5.0 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
Alter dgraph schema
Alter dgraph schema
Supervisor callback.
The same as Dlex.delete(conn, "", deletion, [])
The same as Dlex.delete(conn, query, deletion, [])
or Dlex.delete(conn, "", deletion, opts)
Send mutation to dgraph
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, "", mutations, [])
The same as Dlex.mutate(conn, "", mutations, 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/4
.
Runs a mutation and returns the result or raises Dlex.Error
if there was an error.
See mutate/5
.
Send query to dgraph
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
The same as Dlex.set(conn, "", statement, [])
The same as Dlex.set(conn, "", statement, opts)
.
Send mutation to dgraph. Shortcut for mutate(conn, query, %{set: statement}, opts)
Runs a mutation and returns the result or raises Dlex.Error
if there was an error.
See set/2
.
Runs a mutation and returns the result or raises Dlex.Error
if there was an error.
See set/3
.
Runs a mutation and returns the result or raises Dlex.Error
if there was an error.
See set/4
.
Start dgraph connection process.
Execute serie of queries and mutations in a transactions
Link to this section Types
conn()
Specs
conn() :: DBConnection.conn()
mutation()
Specs
mutations()
Specs
mutations() :: [mutation()]
query()
Specs
query() :: iodata()
query_map()
Specs
statement()
Specs
uid()
Specs
uid() :: String.t()
Link to this section Functions
alter(conn, statement, opts \\ [])
Specs
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
)
alter!(conn, statement, opts \\ [])
Alter dgraph schema
child_spec(opts)
Specs
child_spec(Keyword.t()) :: Supervisor.Spec.spec()
Supervisor callback.
For available options, see: start_link/1
.
delete(conn, statement)
Specs
delete(conn(), statement()) :: {:ok, map()} | {:error, Dlex.Error.t() | term()}
delete(conn(), statement()) :: map() | no_return()
The same as Dlex.delete(conn, "", deletion, [])
delete(conn, query, statement)
Specs
delete(conn(), query() | statement(), statement() | Keyword.t()) :: {:ok, map()} | {:error, Dlex.Error.t() | term()}
delete(conn(), query() | statement(), statement() | Keyword.t()) :: map() | no_return()
The same as Dlex.delete(conn, query, deletion, [])
or Dlex.delete(conn, "", deletion, opts)
delete(conn, query, statement, opts)
Specs
delete(conn(), query(), statement(), 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> Dlex.delete(conn, %{"uid" => "0xfe04c"})
{:ok, %{queries: %{}, uids: %{}}}
Using json
iex> json = %{"uid" => "0xfe04c"}
Dlex.delete(conn, json)
{:ok, %{queries: %{}, uids: %{}}}
iex> Dlex.delete(conn, json, return_json: true)
{:ok, %{json: %{"uid" => "0xfe04c"}, queries: %{}, uids: %{}}}
Options
:timeout
- Call timeout (default:15000
)
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
.
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
.
delete!(conn, query, statement, opts)
Specs
Runs a mutation with delete target and returns the result or raises Dlex.Error
if there was
an error. See delete/4
.
mutate(conn, mutations)
Specs
mutate(conn(), mutations()) :: {:ok, map()} | {:error, Dlex.Error.t() | term()}
The same as Dlex.mutate(conn, "", mutations, [])
mutate(conn, query, mutations)
Specs
mutate(conn(), query_map() | mutations(), mutations() | Keyword.t()) :: {:ok, map()} | {:error, Dlex.Error.t() | term()}
The same as Dlex.mutate(conn, "", mutations, opts)
.
mutate(conn, query_map, mutations, opts)
Specs
mutate(conn(), query_map(), mutations(), 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, %{set: mutation})
{:ok, %{uids: %{"bar" => "0xfe04c", "foo" => "0xfe04b"}, queries: %{}}}
Using json
iex> json = %{"name" => "Foo", "owns" => [%{"name" => "Bar"}]}
Dlex.mutate(conn, %{set: json})
{:ok, %{uids: %{"blank-0" => "0xfe04d", "blank-1" => "0xfe04e"}, queries: %{}}}
iex> Dlex.mutate(conn, %{set: json}, return_json: true)
{:ok,
%{json: %{
"name" => "Foo",
"owns" => [%{"name" => "Bar", "uid" => "0xfe050"}],
"uid" => "0xfe04f"
}}}
Options
:timeout
- Call timeout (default:15000
)
mutate!(conn, mutations)
Specs
mutate!(conn(), statement()) :: map() | no_return()
mutate!(conn(), mutations()) :: map() | no_return()
Runs a mutation and returns the result or raises Dlex.Error
if there was an error.
See mutate/2
.
mutate!(conn, mutations, opts)
Specs
Runs a mutation and returns the result or raises Dlex.Error
if there was an error.
See mutate/4
.
mutate!(conn, query, mutations, opts)
Specs
Runs a mutation and returns the result or raises Dlex.Error
if there was an error.
See mutate/5
.
query(conn, statement, parameters \\ %{}, opts \\ [])
Specs
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"}]}}
Query options (see DGraph documentation for more information):
* `best_effort` - `boolean`
* `read_only` - `boolean`
query!(conn, statement, parameters \\ %{}, opts \\ [])
Specs
Runs a query and returns the result or raises Dlex.Error
if there was an error.
See query/3
.
query_schema(conn)
Specs
query_schema(conn()) :: {:ok, map()} | {:error, Dlex.Error.t() | term()}
Query schema of dgraph
query_schema!(conn)
Specs
Query schema of dgraph
set(conn, statement)
Specs
set(conn(), statement()) :: {:ok, map()} | {:error, Dlex.Error.t() | term()}
The same as Dlex.set(conn, "", statement, [])
set(conn, query, statement)
Specs
set(conn(), query_map() | statement(), statement() | Keyword.t()) :: {:ok, map()} | {:error, Dlex.Error.t() | term()}
The same as Dlex.set(conn, "", statement, opts)
.
set(conn, query, statement, opts)
Specs
set(conn(), query_map(), statement(), Keyword.t()) :: {:ok, map()} | {:error, Dlex.Error.t() | term()}
Send mutation to dgraph. Shortcut for mutate(conn, query, %{set: statement}, opts)
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.set(conn, mutation)
{:ok, %{uids: %{"bar" => "0xfe04c", "foo" => "0xfe04b"}, queries: %{}}}
Using json
iex> json = %{"name" => "Foo", "owns" => [%{"name" => "Bar"}]}
Dlex.set(conn, json)
{:ok, %{uids: %{"blank-0" => "0xfe04d", "blank-1" => "0xfe04e"}, queries: %{}}}
iex> Dlex.set(conn, json, return_json: true)
{:ok,
%{json: %{
"name" => "Foo",
"owns" => [%{"name" => "Bar", "uid" => "0xfe050"}],
"uid" => "0xfe04f"
}}}
Options
:timeout
- Call timeout (default:15000
)
set!(conn, statement)
Runs a mutation and returns the result or raises Dlex.Error
if there was an error.
See set/2
.
set!(conn, statement, opts)
Specs
Runs a mutation and returns the result or raises Dlex.Error
if there was an error.
See set/3
.
set!(conn, query, statement, opts)
Specs
Runs a mutation and returns the result or raises Dlex.Error
if there was an error.
See set/4
.
start_link(opts \\ [])
Specs
start_link(Keyword.t()) :: {:ok, pid()} | {:error, Dlex.Error.t() | term()}
Start dgraph connection process.
Options
:hostname
- Server hostname (default: DGRAPH_HOST, thanlocalhost
):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
);
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 inGenServer.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>}
transaction(conn, fun, opts \\ [])
Specs
transaction(conn(), (DBConnection.t() -> result :: any()), Keyword.t()) :: {:ok, result :: any()} | {:error, any()}
Execute serie of queries and mutations in a transactions