SurrealEx.Socket (surrealdb_ex v0.0.2)
Summary
Functions
Authenticates the current connection with a JWT token.
Modifies all records in a table, or a specific record, in the database.
Creates a record in the database.
Deletes all records in a table, or a specific record, from the database.
Retreive info about the current Surreal instance.
Invalidates the authentication for the current connection.
Kill a specific query.
Switch to a specific namespace and database.
Get a live status from a specific table or row.
Applies JSON Patch changes to all records, or a specific record, in the database.
Ping SurrealDB instance
Runs a set of SurrealQL statements against the database.
Selects all records in a table, or a specific record, from the database.
Signs in to a specific authentication scope.
Signs up to a specific authentication scope.
Updates all records in a table, or a specific record, in the database.
Switch to a specific namespace and database.
Types
Functions
@spec authenticate(process_identifier(), String) :: socket_response()
Authenticates the current connection with a JWT token.
iex> {:ok, pid} = SurrealEx.start_link() # Include your connection options
iex> {:ok, result} = SurrealEx.authenticate(pid, "[YOUR JWT TOKEN HERE]")
# SUCCESS CASE:
{:ok, %{"id" => "1915", "result" => nil}}
# ERROR CASE:
{:error,
%{
"error" => %{
"code" => -32000,
"message" => "There was a problem with authentication"
},
"id" => "1492"
}
}
@spec authenticate(process_identifier(), String, Task, SurrealEx.Domain.TaskOpts) ::
socket_response()
@spec change(process_identifier(), String, payload_type()) :: socket_response()
Modifies all records in a table, or a specific record, in the database.
iex> {:ok, pid} = SurrealEx.start_link() # Include your connection options
iex> {:ok, result} = SurrealEx.change(pid, "users:tobie", %{admin: true})
# SUCCESS CASE:
{:ok, %{"id" => "303", "result" => [%{"admin" => true, "id" => "users:tobie"}]}}
# ERROR CASE:
{:error,
%{
"error" => %{
"code" => -32000,
"message" => "[...]"
},
"id" => "6432"
}
}
@spec change( process_identifier(), String, payload_type(), Task, SurrealEx.Domain.TaskOpts ) :: socket_response()
@spec create(process_identifier(), String, payload_type()) :: socket_response()
Creates a record in the database.
iex> {:ok, pid} = SurrealEx.start_link() # Include your connection options
iex> {:ok, result} = SurrealEx.create(pid, "users", %{name: "John Doe", age: 30})
# SUCCESS CASE:
{:ok,
%{
"id" => "9802",
"result" => [
%{"age" => 30, "id" => "users:agboh28f2vvy18d91q04", "name" => "John Doe"}
]
}
}
# ERROR CASE:
{:error,
%{
"error" => %{
"code" => -32000,
"message" => "[...]"
},
"id" => "2578"
}
}
@spec create( process_identifier(), String, payload_type(), Task, SurrealEx.Domain.TaskOpts ) :: socket_response()
@spec delete(process_identifier(), String) :: socket_response()
Deletes all records in a table, or a specific record, from the database.
iex> {:ok, pid} = SurrealEx.start_link() # Include your connection options
iex> {:ok, result} = SurrealEx.delete(pid, "users:jeremy")
# SUCCESS CASE:
{:ok, %{"id" => "4054", "result" => []}}
# ERROR CASE:
{:error,
%{
"error" => %{
"code" => -32000,
"message" => "[...]"
},
"id" => "2578"
}
}
@spec delete(process_identifier(), String, Task, SurrealEx.Domain.TaskOpts) ::
socket_response()
@spec info(process_identifier()) :: socket_response()
Retreive info about the current Surreal instance.
iex> {:ok, pid} = SurrealEx.start_link() # Include your connection options
iex> {:ok, result} = SurrealEx.info(pid)
# SUCCESS CASE:
{:ok, %{"id" => "9250", "result" => nil}}
# ERROR CASE:
{:error,
%{
"error" => %{
"code" => -32000,
"message" => "[...]"
},
"id" => "2578"
}
}
@spec info(process_identifier(), Task, SurrealEx.Domain.TaskOpts) :: socket_response()
@spec invalidate(process_identifier()) :: socket_response()
Invalidates the authentication for the current connection.
iex> {:ok, pid} = SurrealEx.start_link() # Include your connection options
iex> {:ok, result} = SurrealEx.invalidate(pid)
# SUCCESS CASE:
{:ok, %{"id" => "9250", "result" => nil}}
# ERROR CASE:
{:error,
%{
"error" => %{
"code" => -32000,
"message" => "[...]"
},
"id" => "2578"
}
}
@spec invalidate(process_identifier(), Task, SurrealEx.Domain.TaskOpts) ::
socket_response()
@spec kill(process_identifier(), String) :: socket_response()
Kill a specific query.
iex> {:ok, pid} = SurrealEx.start_link() # Include your connection options
iex> {:ok, result} = SurrealEx.kill(pid)
# SUCCESS CASE:
{:ok, %{"id" => "9250", "result" => nil}}
# ERROR CASE:
{:error,
%{
"error" => %{
"code" => -32000,
"message" => "[...]"
},
"id" => "2578"
}
}
@spec kill(process_identifier(), binary(), Task, SurrealEx.Domain.TaskOpts) :: socket_response()
@spec let(process_identifier(), String, String) :: socket_response()
Switch to a specific namespace and database.
iex> {:ok, pid} = SurrealEx.start_link() # Include your connection options
iex> {:ok, result} = SurrealEx.use(pid, "test", "test")
# SUCCESS CASE:
{:ok, %{"id" => "9250", "result" => nil}}
# ERROR CASE:
{:error,
%{
"error" => %{
"code" => -32000,
"message" => "[...]"
},
"id" => "2578"
}
}
@spec live(process_identifier(), String) :: socket_response()
Get a live status from a specific table or row.
iex> {:ok, pid} = SurrealEx.start_link() # Include your connection options
iex> {:ok, result} = SurrealEx.live(pid, "users")
# SUCCESS CASE:
{:ok, %{"id" => "8913", "result" => "8354534f-5e42-4bb7-8bae-6cf41d38236a"}}
# ERROR CASE:
{:error,
%{
"error" => %{
"code" => -32000,
"message" => "[...]"
},
"id" => "2578"
}
}
@spec live(process_identifier(), binary(), Task, SurrealEx.Domain.TaskOpts) :: socket_response()
@spec modify(process_identifier(), String, [payload_type()]) :: socket_response()
Applies JSON Patch changes to all records, or a specific record, in the database.
iex> {:ok, pid} = SurrealEx.start_link() # Include your connection options
iex> {:ok, result} = SurrealEx.modify(pid, "users", %{"name" => "John Doe"})
# SUCCESS CASE:
{:ok, %{"id" => "8044", "result" => []}}
# ERROR CASE:
{:error,
%{
"error" => %{
"code" => -32000,
"message" => "[...]"
},
"id" => "2578"
}
}
@spec modify( process_identifier(), String, [payload_type()], Task, SurrealEx.Domain.TaskOpts ) :: socket_response()
@spec ping(process_identifier()) :: socket_response()
Ping SurrealDB instance
iex> {:ok, pid} = SurrealEx.start_link() # Include your connection options
iex> {:ok, result} = SurrealEx.ping(pid)
# SUCCESS CASE:
{:ok, %{"id" => "4562", "result" => true}}
# ERROR CASE:
{:error,
%{
"error" => %{
"code" => -32000,
"message" => "[...]"
},
"id" => "2578"
}
}
@spec ping(process_identifier(), Task, SurrealEx.Domain.TaskOpts) :: socket_response()
@spec query(process_identifier(), String, payload_type()) :: socket_response()
Runs a set of SurrealQL statements against the database.
iex> {:ok, pid} = SurrealEx.start_link() # Include your connection options
iex> {:ok, result} = SurrealEx.query(pid, "SELECT * FROM type::table($table) WHERE admin = true;", %{table: "users"})
# SUCCESS CASE:
{:ok,
%{
"id" => "6042",
"result" => [
%{
"result" => [
%{
"admin" => true,
"age" => 29,
"id" => "users:5ypb5ifhfo7tnj31pajl",
"name" => "John Doe"
},
%{
"admin" => true,
"age" => 32,
"id" => "users:zb71vk0kh9d33bucozr7",
"name" => "Mary Jane"
}
],
"status" => "OK",
"time" => "80.164µs"
}
]
}
}
# ERROR CASE:
{:error,
%{
"error" => %{
"code" => -32000,
"message" => "There was a problem with the database: Parse error on line 1 at character 0 when parsing [...]"
},
"id" => "1120"
}
}
@spec query( process_identifier(), binary(), payload_type(), Task, SurrealEx.Domain.TaskOpts ) :: socket_response()
@spec select(process_identifier(), String) :: socket_response()
Selects all records in a table, or a specific record, from the database.
iex> {:ok, pid} = SurrealEx.start_link() # Include your connection options
iex> {:ok, result} = SurrealEx.select(pid, "SELECT * FROM users;")
# SUCCESS CASE:
{:ok, %{"id" => "948", "result" => []}}
# ERROR CASE:
{:error,
%{
"error" => %{
"code" => -32000,
"message" => "[...]"
},
"id" => "2578"
}
}
@spec select(process_identifier(), String, Task, SurrealEx.Domain.TaskOpts) ::
socket_response()
Signs in to a specific authentication scope.
iex> {:ok, pid} = SurrealEx.start_link() # Include your connection options
iex> {:ok, result} = SurrealEx.signin(pid, %{user: "root", pass: "root"})
# SUCCESS CASE:
{:ok, %{"id" => "6420", "result" => ""}}
# ERROR CASE:
{:error,
%{
"error" => %{
"code" => -32000,
"message" => "There was a problem with authentication"
},
"id" => "7335"
}}
@spec signin(
process_identifier(),
SurrealEx.Domain.SignInPayload,
Task,
SurrealEx.Domain.TaskOpts
) ::
socket_response()
@spec signin(process_identifier(), payload_type(), Task, SurrealEx.Domain.TaskOpts) :: socket_response()
@spec signup(process_identifier(), payload_type()) :: socket_response()
Signs up to a specific authentication scope.
iex> {:ok, pid} = SurrealEx.start_link() # Include your connection options
iex> {:ok, result} = SurrealEx.signup(pid, %{user: "root", pass: "root", SC: "allusers", DB: "test", NS: "test"})
# SUCCESS CASE:
{:ok,
%{
"id" => "9267",
"result" => "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE2ODA2NjE5NDksIm5iZiI6MTY4MDY2MTk0OSwiZXhwIjoxNjgxODcxNTQ5LCJpc3MiOiJTdXJyZWFsREIiLCJOUyI6InRlc3QiLCJEQiI6InRlc3QiLCJTQyI6ImFsbHVzZXJzIiwiSUQiOiJ1c2VyOjdqN2hubnloMGFseTV0cHlnb3JrIn0.7IZ7QL6BMgNv9xW_QHu-JrZdfDdX9ngGV5xlxNPHHIkPzgi9OW2iHdUt2wt8x4_5vRo9rijQge04Nvbl3aTV9A"
}
}
# ERROR CASE:
{:error,
%{
"error" => %{
"code" => -32000,
"message" => "There was a problem with authentication"
},
"id" => "3694"
}
}
@spec signup(process_identifier(), payload_type(), Task, SurrealEx.Domain.TaskOpts) :: socket_response()
@spec start_link(SurrealEx.Domain.SocketOpts.t()) :: GenServer.on_start()
@spec stop(pid()) :: :ok
@spec update(process_identifier(), String, payload_type()) :: socket_response()
Updates all records in a table, or a specific record, in the database.
iex> {:ok, pid} = SurrealEx.start_link() # Include your connection options
iex> {:ok, result} = SurrealEx.update(pid, "users:jeremy", %{admin: true})
# SUCCESS CASE:
{:ok, %{"id" => "6427", "result" => []}}
# ERROR CASE:
{:error,
%{
"error" => %{
"code" => -32000,
"message" => "There was a problem with authentication"
},
"id" => "3694"
}
}
@spec update( process_identifier(), String, payload_type(), Task, SurrealEx.Domain.TaskOpts ) :: socket_response()
@spec use(process_identifier(), String, String) :: socket_response()
Switch to a specific namespace and database.
iex> {:ok, pid} = SurrealEx.start_link() # Include your connection options
iex> {:ok, result} = SurrealEx.use(pid, "default", "default")
# SUCCESS CASE:
{:ok, %{"id" => "1915", "result" => nil}}
# ERROR CASE:
{:error,
%{
"error" => %{
"code" => -32000,
"message" => "There was a problem with the database: [...]"
},
"id" => "1120"
}
}