• Stars
    star
    3
  • Rank 3,963,521 (Top 79 %)
  • Language
    Erlang
  • License
    MIT License
  • Created over 1 year ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Erlang driver for SurrealDB

banner

SurrealDB Erlang

Erlang driver for SurrealDB.

⚠️ You are currently viewing main branch ⚠️

Package name named as surreal on hex. Because an Erlang implementation can be used in other languages that runs on BEAM virtual machine, such as Elixir and Gleam.

This library tries to be compatible with the official implementation.

Installation

Add surreal to your list of dependencies in rebar.config file:

{deps, [{surreal, "1.1.0"}]}.

Usage

Simple Connection

1> {ok, Pid} = surreal:start_link("ws://localhost:8000").
% {ok, <pid>}
2> surreal:signin(Pid, "root", "root").
% {ok, null}
3> surreal:use(Pid, "test", "test").
% {ok, null}
4> surreal:create(Pid, "example:bob",
4>  #{<<"name">> => <<"bob">>}).
% {ok, #{<<"id">> => <<"example:bob">>, <<"name">> => <<"bob">>}},
5> surreal:query(Pid, "SELECT * FROM type::table($tb);",
5>    #{<<"tb">> => <<"test">>}).
% [{ok, [#{<<"id">> => <<"example:bob">>, <<"name">> => <<"bob">>}]}]

Connect with Config

1> Config = [
1>   % link the process
1>   link,
1>   % register local name
1>   {name, example_client},
1>   % host and port
1>   {host, "localhost"},
1>   {port, 8000},
1>   % database, namespace to use
1>   {use, {"test", "test"}},
1>   % user, pass auth
1>   {signin, {"root", "root"}}
1> ].
% ...
2> {ok, Pid} = surreal_config:load(Config).
% ...
3> surreal:create(example_client, "example:bob",
3>  #{<<"name">> => <<"bob">>}).
% {ok, #{<<"id">> => <<"example:bob">>, <<"name">> => <<"bob">>}},

Documentation

Documentation is available at HexDocs.

Contributing

You can always report bugs and request features via GitHub Issues.

For pull requests, make sure your code is well-formatted and at least can explain itself.

License

SurrealDB Erlang is licensed under the MIT License.