suweal
Types
A connection to a SurrealDB instance.
pub type Connection {
Connection(
endpoint: String,
namespace: String,
database: String,
authorization: String,
)
}
Constructors
-
Connection( endpoint: String, namespace: String, database: String, authorization: String, )
The error type for decoding the Basic authorization header of a connection.
pub type DecodeCredentialsError {
InvalidBase64
InvalidFormat
}
Constructors
-
InvalidBase64 -
InvalidFormat
pub type SurrealError {
InvalidUrl
HttpError(httpc.HttpError)
ErrorResponse(
code: Int,
details: String,
description: String,
information: String,
)
FailedToDecode(json.DecodeError)
NoResponse
}
Constructors
-
InvalidUrl -
HttpError(httpc.HttpError) -
ErrorResponse( code: Int, details: String, description: String, information: String, ) -
FailedToDecode(json.DecodeError) -
NoResponse
pub type SurrealResponse(a) {
SurrealResponse(
time: String,
type_: option.Option(String),
result: option.Option(a),
)
SurrealErrorResponse(
kind: String,
type_: option.Option(String),
time: String,
details: dynamic.Dynamic,
result: String,
)
}
Constructors
-
SurrealResponse( time: String, type_: option.Option(String), result: option.Option(a), ) -
SurrealErrorResponse( kind: String, type_: option.Option(String), time: String, details: dynamic.Dynamic, result: String, )
Values
pub fn auth_result_decoder() -> decode.Decoder(
Result(String, SurrealError),
)
pub fn connection(
endpoint endpoint: String,
namespace namespace: String,
database database: String,
username username: String,
password password: String,
) -> Connection
Create a new connection to a SurrealDB instance with the given endpoint, namespace, database, username and password. The username and password will be used to generate a Basic Authorization header for the connection.
pub fn decode_credentials(
connection: Connection,
) -> Result(#(String, String), DecodeCredentialsError)
Decode the Basic authorization header of a connection into a tuple of username and password.
pub fn expect_single_result(
response: Result(List(SurrealResponse(List(a))), SurrealError),
msg: String,
) -> a
pub fn result_decoder(
decoder: decode.Decoder(a),
) -> decode.Decoder(
Result(List(SurrealResponse(a)), SurrealError),
)
pub fn should_be_error(response: SurrealResponse(a)) -> Nil
pub fn should_be_success(
response: SurrealResponse(a),
) -> option.Option(a)
pub fn status(connection: Connection) -> Bool
pub fn surreal_error_decoder() -> decode.Decoder(SurrealError)
pub fn surreal_response_decoder(
decoder: decode.Decoder(a),
) -> decode.Decoder(SurrealResponse(a))
pub fn with_database(
connection: Connection,
database: String,
) -> Connection
Replace the database of a connection with a new database. This is useful for switching between different databases in the same SurrealDB instance.
pub fn with_namespace(
connection: Connection,
namespace: String,
) -> Connection
Replace the namespace of a connection with a new namespace. This is useful for switching between different namespaces in the same SurrealDB instance.