suweal_service

Types

pub type DBExecutionError {
  Timeout
  ServiceUnavailable
  QueryError
  FailedToDecode(List(decode.DecodeError))
  NotFound
}

Constructors

pub type DBMessage =
  model.DBMessage
pub type DBRequest(a) {
  DBQueryRequest(
    timeout: Int,
    namespace: String,
    query: List(node.Node),
    parameters: List(#(String, surreal_ql.SurrealQL)),
    decoder: decode.Decoder(a),
  )
}

Constructors

pub type DbOperationErrorSet {
  DbOperationErrorSet(
    timeout: offstage.TimeoutResponse,
    internal_server_error: offstage.InternalServerErrorResponse,
    service_unavailable: offstage.ServiceUnavailableResponse,
    not_found: offstage.NotFoundResponse,
  )
}

Constructors

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
pub type QueryData =
  model.QueryData
pub type SigninData =
  model.SigninData
pub type SignupData =
  model.SignupData

Values

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 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)
pub fn with_timeout(
  request: DBRequest(a),
  timeout: Int,
) -> DBRequest(a)
✨ Search Document