dlex v0.3.1 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, "", 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
.
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
See mutate/3
for documentation.
See mutate!/3
for documentation.
Start dgraph connection process.
Execute serie of queries and mutations in a transactions
Link to this section Types
Link to this section Functions
alter(conn, statement, opts \\ [])
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
Supervisor callback.
For available options, see: start_link/1
.
delete(conn, statement)
The same as Dlex.delete(conn, "", deletion, [])
delete(conn, query, statement)
The same as Dlex.delete(conn, query, deletion, [])
or Dlex.delete(conn, "", deletion, opts)
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
)
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)
Runs a mutation with delete target and returns the result or raises Dlex.Error
if there was
an error. See delete/4
.
mutate(conn, statement)
The same as Dlex.mutate(conn, "", mutation, [])
mutate(conn, query, statement)
The same as Dlex.mutate(conn, query, mutation, [])
or Dlex.mutate(conn, "", mutation, opts)
mutate(conn, query, 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.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
)
mutate!(conn, statement)
Runs a mutation and returns the result or raises Dlex.Error
if there was an error.
See mutate/2
.
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
.
mutate!(conn, query, statement, opts)
Runs a mutation and returns the result or raises Dlex.Error
if there was an error.
See mutate/4
.
query(conn, statement, parameters \\ %{}, opts \\ [])
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!(conn, statement, parameters \\ %{}, opts \\ [])
Runs a query and returns the result or raises Dlex.Error
if there was an error.
See query/3
.
query_schema(conn)
query_schema(conn()) :: {:ok, map()} | {:error, Dlex.Error.t() | term()}
Query schema of dgraph
Query schema of dgraph
set(conn, statement, opts \\ [])
See mutate/3
for documentation.
set!(conn, statement, opts \\ [])
See mutate!/3
for documentation.
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, 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
);: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 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 \\ [])
Execute serie of queries and mutations in a transactions