suweal_service/query

Types

Represents a database query with its associated metadata and transformation logic.

  • resource specifies the resource being queried.
  • operation_type indicates the type of database operation.
  • query is the list of SurrealDB nodes forming the query.
  • serializer is used to serialize the query parameters.
  • parameters is the list of query parameters.
  • transform is a function to transform the query result.
pub type Query(a, b) {
  Query(
    resource: String,
    operation_type: suweal_service.OperationType,
    query: List(node.Node),
    serializer: serialize.Serializer(a),
    parameters: List(#(String, surreal_ql.SurrealQL)),
    transform: fn(
      Result(option.Option(a), suweal_service.DBExecutionError),
    ) -> Result(b, suweal_service.DBExecutionError),
  )
}

Constructors

Values

pub fn empty_if_none(
  query: Query(a, option.Option(List(b))),
) -> Query(a, List(b))

Transforms a query that returns an optional list into a query that returns an empty list if the result is None.

pub fn not_empty(
  query: Query(a, option.Option(List(b))),
) -> Query(a, List(b))

Transforms a query that returns an optional list into a query that ensures the list is not empty.

pub fn optional_single(
  query: Query(a, option.Option(List(b))),
) -> Query(a, option.Option(b))

Transforms a query that returns an optional list into a query that returns an optional single element.

pub fn query(
  resource resource: String,
  operation_type operation_type: suweal_service.OperationType,
  query query: List(node.Node),
  serializer serializer: serialize.Serializer(a),
  parameters parameters: List(#(String, surreal_ql.SurrealQL)),
) -> Query(a, option.Option(a))

Creates a new query with the specified resource, operation type, query nodes, serializer, and parameters.

pub fn run(
  query: Query(a, b),
  in namespace: String,
  service service: process.Name(
    hive.DispatcherMessage(model.DBMessage),
  ),
  response operation_response: suweal_service.DbOperationErrorSet,
) -> Result(b, response.Response(wisp.Body))

Executes the given query against the specified namespace and service, and processes the response using the provided operation response handler.

  • query is the query to be executed.
  • namespace specifies the database namespace.
  • service is the process handling the database messages.
  • operation_response is the handler for processing the operation response. Returns a Result containing the query result or an error response.
pub fn single(
  query: Query(a, option.Option(List(b))),
) -> Query(a, b)

Transforms a query that returns a list into a query that returns a single element.

pub fn some(query: Query(a, option.Option(b))) -> Query(a, b)

Transforms a query that returns an optional value into a query that returns the value directly.

✨ Search Document