pub enum DbClient {
Postgres(Client),
}Expand description
Engine-specific database connection wrapper.
Constructed by Waypoint::new (which auto-detects
the engine from the connection URL) or by DbClient::with_postgres /
[DbClient::with_mysql] for callers that already have a connection.
Most internal command code currently still operates on a raw
tokio_postgres::Client obtained via Self::as_postgres. As MySQL support
rolls out command-by-command, those call sites move to dialect-aware code.
Variants§
Implementations§
Source§impl DbClient
impl DbClient
Sourcepub fn with_postgres(client: Client) -> Self
pub fn with_postgres(client: Client) -> Self
Wrap an existing PostgreSQL client.
Sourcepub fn dialect_kind(&self) -> DialectKind
pub fn dialect_kind(&self) -> DialectKind
Identify which dialect this connection is for.
Sourcepub fn dialect(&self) -> &'static dyn DatabaseDialect
pub fn dialect(&self) -> &'static dyn DatabaseDialect
Borrow the dialect helper for this connection.
Both PostgresDialect and MysqlDialect are zero-sized, so this returns
a static reference rather than allocating a new Box per call.
Sourcepub fn as_postgres(&self) -> Result<&Client>
pub fn as_postgres(&self) -> Result<&Client>
Borrow the inner PostgreSQL client. Returns an error if this DbClient is not a PostgreSQL connection — used as a transitional bridge for command code that hasn’t been ported to dialect-aware operation yet.
Sourcepub async fn check_connection(&self) -> Result<()>
pub async fn check_connection(&self) -> Result<()>
Verify the database connection is still alive with a minimal round-trip.
Sourcepub async fn acquire_lock(&self, table_name: &str) -> Result<()>
pub async fn acquire_lock(&self, table_name: &str) -> Result<()>
Acquire a session-scoped advisory lock keyed by the history-table name.
PostgreSQL: pg_advisory_lock(<i64>) derived from a CRC32 of the table name.
MySQL: GET_LOCK('waypoint_<table>', -1) (named, indefinite-wait).
Sourcepub async fn acquire_lock_with_timeout(
&self,
table_name: &str,
timeout_secs: u32,
) -> Result<()>
pub async fn acquire_lock_with_timeout( &self, table_name: &str, timeout_secs: u32, ) -> Result<()>
Try to acquire the advisory lock, polling until acquired or timeout expires.
Sourcepub async fn release_lock(&self, table_name: &str) -> Result<()>
pub async fn release_lock(&self, table_name: &str) -> Result<()>
Release the advisory lock acquired via Self::acquire_lock.
Sourcepub async fn current_user(&self) -> Result<String>
pub async fn current_user(&self) -> Result<String>
Get the current database user/account.
Sourcepub async fn current_database(&self) -> Result<String>
pub async fn current_database(&self) -> Result<String>
Get the current database name.
Sourcepub async fn resolve_schema(&self, configured: &str) -> Result<String>
pub async fn resolve_schema(&self, configured: &str) -> Result<String>
Resolve the schema/database name to use for the history table.
On PostgreSQL the configured value is used as-is. On MySQL there is no
schema concept distinct from the database; if the configured value is
the PG-default "public", we fall back to the connection’s current
database so a PG-shaped config keeps working when pointed at MySQL.
Sourcepub async fn execute_raw(&self, sql: &str) -> Result<i32>
pub async fn execute_raw(&self, sql: &str) -> Result<i32>
Run one or more ;-separated SQL statements without an explicit transaction.
On PostgreSQL this is a single batch_execute call. On MySQL it splits
the batch into individual statements via
crate::sql_parser::split_mysql_statements (mysql_async’s underlying
protocol doesn’t accept multiple statements unless the connection is
built with CLIENT_MULTI_STATEMENTS, which we deliberately avoid).
Returns elapsed time in milliseconds.
Sourcepub async fn execute_in_transaction(&self, sql: &str) -> Result<i32>
pub async fn execute_in_transaction(&self, sql: &str) -> Result<i32>
Run SQL inside a transaction where the engine supports DDL rollback.
On PostgreSQL this issues BEGIN / COMMIT (with ROLLBACK on failure)
around batch_execute. On MySQL most DDL implicitly commits, so a
transaction wrapper provides no rollback guarantee for DDL — we issue
the statements without a wrapper and surface failures as they arise.
Callers needing strict batch atomicity should consult
DatabaseDialect::supports_transactional_ddl before invoking.