sparkling/repo
Types
Events emitted by the repo for observability (logging, metrics, tracing)
pub type Event {
QueryStart(sql: String)
QueryEnd(sql: String, duration_ms: Int)
QueryError(sql: String, error: String)
RetryAttempt(sql: String, attempt: Int, error: String)
}
Constructors
-
QueryStart(sql: String) -
QueryEnd(sql: String, duration_ms: Int) -
QueryError(sql: String, error: String) -
RetryAttempt(sql: String, attempt: Int, error: String)
Repository configuration and state
pub type Repo {
Repo(
base_url: String,
database: option.Option(String),
user: option.Option(String),
password: option.Option(String),
on_event: fn(Event) -> Nil,
retry_config: retry.RetryConfig,
timeout_ms: Int,
)
}
Constructors
-
Repo( base_url: String, database: option.Option(String), user: option.Option(String), password: option.Option(String), on_event: fn(Event) -> Nil, retry_config: retry.RetryConfig, timeout_ms: Int, )
Error types for repository operations
pub type RepoError {
HttpError(message: String)
ParseError(message: String)
ConnectionError(message: String)
ClickHouseError(message: String, code: option.Option(Int))
}
Constructors
-
HttpError(message: String) -
ParseError(message: String) -
ConnectionError(message: String) -
ClickHouseError(message: String, code: option.Option(Int))
Values
pub fn execute_sql(
repo: Repo,
sql: String,
) -> Result(String, RepoError)
Execute a SQL query and return the response body as a string. This is the low-level interface; higher-level functions will parse the response.
pub fn query(
repo: Repo,
sql: String,
decoder: fn(String) -> Result(a, String),
) -> Result(a, RepoError)
Execute a query and parse the response using a decoder. This is a higher-level interface that combines execute_sql with decoding.
pub fn with_credentials(
repo: Repo,
user: String,
password: String,
) -> Repo
Set authentication credentials
pub fn with_event_handler(
repo: Repo,
handler: fn(Event) -> Nil,
) -> Repo
Set event handler for observability
pub fn with_retry_config(
repo: Repo,
config: retry.RetryConfig,
) -> Repo
Set retry configuration for advanced control