suweal_service
Types
pub type DBExecutionError {
Timeout
ServiceUnavailable
QueryError
FailedToDecode(List(decode.DecodeError))
NotFound
}
Constructors
-
Timeout -
ServiceUnavailable -
QueryError -
FailedToDecode(List(decode.DecodeError)) -
NotFound
pub type DBRequest(a) {
DBQueryRequest(
timeout: Int,
namespace: String,
query: List(node.Node),
parameters: List(#(String, surreal_ql.SurrealQL)),
decoder: decode.Decoder(a),
)
}
Constructors
-
DBQueryRequest( timeout: Int, namespace: String, query: List(node.Node), parameters: List(#(String, surreal_ql.SurrealQL)), decoder: decode.Decoder(a), )
pub type DbOperationErrorSet {
DbOperationErrorSet(
timeout: offstage.TimeoutResponse,
internal_server_error: offstage.InternalServerErrorResponse,
service_unavailable: offstage.ServiceUnavailableResponse,
not_found: offstage.NotFoundResponse,
)
}
Constructors
-
DbOperationErrorSet( timeout: offstage.TimeoutResponse, internal_server_error: offstage.InternalServerErrorResponse, service_unavailable: offstage.ServiceUnavailableResponse, not_found: offstage.NotFoundResponse, )
The type of database operation being performed, used for generating context-specific error messages in responses.
pub type OperationType {
Create
Read
Update
Delete
}
Constructors
-
Create -
Read -
Update -
Delete
Values
pub fn db_operation_response(
spec: offstage_core.RouteSpecBuilder,
next: fn(
offstage_core.RouteSpecBuilder,
offstage_core.RouteCapability(DbOperationErrorSet, object),
) -> offstage_core.RouteSpec,
) -> offstage_core.RouteSpec
pub fn dispatcher(
name: process.Name(hive.DispatcherMessage(model.DBMessage)),
connection: suweal.Connection,
) -> supervision.ChildSpecification(static_supervisor.Supervisor)
pub fn empty_if_none(
result: Result(option.Option(List(a)), DBExecutionError),
) -> Result(List(a), DBExecutionError)
Transform a None value into an empty list
pub fn not_empty(
result: Result(option.Option(List(a)), DBExecutionError),
) -> Result(List(a), DBExecutionError)
Require the result to be a non-empty list otherwise return [NotFound].
pub fn optional_single(
result: Result(option.Option(List(a)), DBExecutionError),
) -> Result(option.Option(a), DBExecutionError)
Pick the first value of the optional list or return None
pub fn query(
namespace: String,
query: List(node.Node),
serializer: serialize.Serializer(a),
) -> DBRequest(a)
pub fn run(
request: DBRequest(a),
name: process.Name(hive.DispatcherMessage(model.DBMessage)),
) -> Result(option.Option(a), DBExecutionError)
pub fn signin(
timeout: Int,
namespace: String,
name: process.Name(hive.DispatcherMessage(model.DBMessage)),
collection: String,
fields: List(#(String, surreal_ql.SurrealQL)),
) -> Result(String, DBExecutionError)
pub fn signup(
timeout: Int,
namespace: String,
name: process.Name(hive.DispatcherMessage(model.DBMessage)),
collection: String,
fields: List(#(String, surreal_ql.SurrealQL)),
) -> Result(String, DBExecutionError)
pub fn single(
result: Result(option.Option(List(a)), DBExecutionError),
) -> Result(a, DBExecutionError)
Expect a single result from a database query, returning an error response if there are no results. If there are multiple, the first result is returned and the rest are discarded.
pub fn to_response(
result: Result(a, DBExecutionError),
operation: OperationType,
name: String,
response: DbOperationErrorSet,
) -> Result(a, response.Response(wisp.Body))
Convert the result’s error into a WispResponse with a descriptive message based on the [operation] and the given [name] (resource name).
pub fn with_param(
request: DBRequest(a),
name: String,
value: surreal_ql.SurrealQL,
) -> DBRequest(a)
pub fn with_params(
request: DBRequest(a),
parameters: List(#(String, surreal_ql.SurrealQL)),
) -> DBRequest(a)