suweal_service/model

Types

Represents the different messages that can be sent to the service dispatcher.

  • ExecuteQuery executes a database query.
  • ExecuteSignin executes a sign-in operation.
  • ExecuteSignup executes a sign-up operation.
  • WSSResponse handles a response from the WebSocket server.
pub type DBMessage {
  ExecuteQuery(
    namespace: String,
    query: String,
    reply_to: process.Subject(
      Result(option.Option(dynamic.Dynamic), String),
    ),
  )
  ExecuteSignin(SigninData)
  ExecuteSignup(SignupData)
  WSSResponse(surreal_wss.SurrealWssResponse(dynamic.Dynamic))
}

Constructors

Represents the callback to log a message.

pub type LogCallback =
  fn(
    String,
    LogLevel,
    timestamp.Timestamp,
    String,
    String,
    value.Value,
  ) -> Nil

Represents the severity level of a log message.

pub type LogLevel {
  LogLevelInfo
  LogLevelWarning
  LogLevelError
  LogLevelDebug
}

Constructors

  • LogLevelInfo
  • LogLevelWarning
  • LogLevelError
  • LogLevelDebug

Represents the name of a process that handles DB messages.

pub type ProcessName =
  process.Name(hive.DispatcherMessage(DBMessage))

Represents the data required to execute a query against the database.

  • namespace specifies the database namespace.
  • query is the SurrealQL query string.
  • receiver is the process that will receive the result of the query.
pub type QueryData {
  QueryData(
    namespace: String,
    query: String,
    receiver: process.Subject(
      Result(List(dynamic.Dynamic), String),
    ),
  )
}

Constructors

Represents the data required to sign in a user.

  • namespace specifies the database namespace.
  • collection is the database collection.
  • fields is a list of field names and their corresponding SurrealQL values.
  • receiver is the process that will receive the result of the sign-in operation.
pub type SigninData {
  SigninData(
    namespace: String,
    collection: String,
    fields: List(#(String, surreal_ql.SurrealQL)),
    receiver: process.Subject(Result(String, String)),
  )
}

Constructors

Represents the data required to sign up a user.

  • namespace specifies the database namespace.
  • collection is the database collection.
  • fields is a list of field names and their corresponding SurrealQL values.
  • receiver is the process that will receive the result of the sign-up operation.
pub type SignupData {
  SignupData(
    namespace: String,
    collection: String,
    fields: List(#(String, surreal_ql.SurrealQL)),
    receiver: process.Subject(Result(String, String)),
  )
}

Constructors

The configuration for the Suweal service.

  • name is the name of the process handling the service.
  • connection is the connection to the SurrealDB instance.
  • log_callback is an optional callback for logging messages.
  • queue is an optional queue builder for managing query execution.
pub type SuwealServiceConfig {
  SuwealServiceConfig(
    name: process.Name(hive.DispatcherMessage(DBMessage)),
    connection: suweal.Connection,
    wss_connector: fn(suweal.Connection) -> Result(
      surreal_wss.SurrealWssConnection,
      String,
    ),
    log_callback: option.Option(
      fn(
        String,
        LogLevel,
        timestamp.Timestamp,
        String,
        String,
        value.Value,
      ) -> Nil,
    ),
    queue: option.Option(queue.Builder),
    strategy: hive.Strategy,
    close_after: duration.Duration,
  )
}

Constructors

pub type WSSConnector =
  fn(suweal.Connection) -> Result(
    surreal_wss.SurrealWssConnection,
    String,
  )

Represents the different messages that a worker process can handle.

pub type WorkerMessage {
  ProcessQueue(queue: List(QueryData))
  ProcessSignin(SigninData)
  ProcessSignup(SignupData)
  Response(surreal_wss.SurrealWssResponse(dynamic.Dynamic))
  Ready
}

Constructors

Values

pub fn default_config(
  name: process.Name(hive.DispatcherMessage(DBMessage)),
  connection: suweal.Connection,
) -> SuwealServiceConfig

Returns the default configuration for the Suweal service with the given process name and connection.

pub fn default_queue() -> queue.Builder

Returns the default queue builder with pre-configured settings.

pub fn default_wss_connector(
  connection: suweal.Connection,
) -> Result(surreal_wss.SurrealWssConnection, String)
pub fn with_close_after(
  config: SuwealServiceConfig,
  close_after: duration.Duration,
) -> SuwealServiceConfig
pub fn with_log_callback(
  config: SuwealServiceConfig,
  log_callback: fn(
    String,
    LogLevel,
    timestamp.Timestamp,
    String,
    String,
    value.Value,
  ) -> Nil,
) -> SuwealServiceConfig

Returns a new configuration with the specified log callback.

pub fn with_queue(
  config: SuwealServiceConfig,
  queue: queue.Builder,
) -> SuwealServiceConfig

Returns a new configuration with the specified queue builder.

pub fn with_strategy(
  config: SuwealServiceConfig,
  strategy: hive.Strategy,
) -> SuwealServiceConfig

Returns a new configuration with the specified Hive strategy.

pub fn with_wss_connector(
  config: SuwealServiceConfig,
  wss_connector: fn(suweal.Connection) -> Result(
    surreal_wss.SurrealWssConnection,
    String,
  ),
) -> SuwealServiceConfig
pub fn without_queue(
  config: SuwealServiceConfig,
) -> SuwealServiceConfig

Returns a new configuration without a queue.

✨ Search Document