View Source README
Unreal
Unofficial SurrealDB client for Elixir. Supports both WebSocket and HTTP connection.
⚠️ Unreal is well tested. But still may contains some bugs. Please report an issue if you got an one. ⚠️
installation
Installation
Add unreal
to your list of dependencies in mix.exs
:
def deps do
[
{:unreal, "~> 0.2.0"}
]
end
usage
Usage
simple-websocket-connection
Simple WebSocket Connection
config = %Unreal.Core.Config{
host: "ws://127.0.0.1:8000",
username: "root",
password: "root",
database: "test",
namespace: "test"
}
{:ok, pid} = Unreal.start_link(protocol: :websocket, config: config, name: :database)
Unreal.insert(pid, "users", "bob", %{age: 18, active: true})
Unreal.get(:database, "users")
with-supervisor
With Supervisor
children = [
{Unreal,
protocol: :websocket,
config: %Unreal.Core.Config{
host: "ws://127.0.0.1:8000",
username: "root",
password: "root",
namespace: "test",
database: "test"
},
name: :database}
]
opts = [strategy: :one_for_one, name: Example.Supervisor]
Supervisor.start_link(children, opts)
Unreal.insert(:database, "users", "bob", %{age: 18, active: true})
with-tables
With Tables
This macro allows you to use a table directly. Adds insert
, update
, get
, change
, modify
and delete
functions.
defmodule Users do
# name: the name of the connection
# table: table to use
use Unreal.Table, name: :database, table: "users"
end
Users.get("bob")
queries
Queries
NOTE: Sending a variable to query is not supported in HTTP connection.
Unreal.query(:database, "SELECT * FROM users")
Unreal.query(:database, "SELECT * FROM users WHERE age > $age", %{
age: 30
})
query-builders
Query Builders
This feature is inspired from Cirql and currently not finished.
alias Unreal.Writer
{query, params} =
Writer.Select.init()
|> Writer.Select.from("users")
|> Writer.Select.get([:id, :username, :age])
|> Writer.Select.where(age: {:>, 18}, verified: true)
|> Writer.Select.build()
{:ok, result} = Unreal.query(:database, query, params)
documentation
Documentation
Documentation is avaible at HexDocs.
contributing
Contributing
- Please don't send any pull request to main branch.
- Report bugs or request features here.
- Always use
mix format
before sending a pull request.
license
License
Unreal is licensed under the MIT License.