Skip to main content

DbClient

Enum DbClient 

Source
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§

§

Postgres(Client)

PostgreSQL connection.

Implementations§

Source§

impl DbClient

Source

pub fn with_postgres(client: Client) -> Self

Wrap an existing PostgreSQL client.

Source

pub fn dialect_kind(&self) -> DialectKind

Identify which dialect this connection is for.

Source

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.

Source

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.

Source

pub async fn check_connection(&self) -> Result<()>

Verify the database connection is still alive with a minimal round-trip.

Source

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).

Source

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.

Source

pub async fn release_lock(&self, table_name: &str) -> Result<()>

Release the advisory lock acquired via Self::acquire_lock.

Source

pub async fn current_user(&self) -> Result<String>

Get the current database user/account.

Source

pub async fn current_database(&self) -> Result<String>

Get the current database name.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V