suweal_service/query
Types
Represents a database query with its associated metadata and transformation logic.
resourcespecifies the resource being queried.operation_typeindicates the type of database operation.queryis the list of SurrealDB nodes forming the query.serializeris used to serialize the query parameters.parametersis the list of query parameters.transformis 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
-
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), )
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.
queryis the query to be executed.namespacespecifies the database namespace.serviceis the process handling the database messages.operation_responseis the handler for processing the operation response. Returns aResultcontaining 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.