Skip to main content

Database

Trait Database 

Source
pub trait Database: Database {
    const SYSTEM: &'static str;

    // Required methods
    fn connection_attributes(
        pool: &Pool<Self>,
    ) -> (Option<String>, Option<u16>, Option<String>);
    fn rows_affected(result: &<Self as Database>::QueryResult) -> u64;
}
Expand description

Per-backend contract providing the database system name and a method to extract connection-level attributes from the backend’s connect options.

Each supported SQLx backend (Postgres, Sqlite, Mysql) implements this trait behind its corresponding feature flag. The trait is intentionally minimal – it exists solely to let the generic wrapper types resolve connection attributes once at pool construction time.

Required Associated Constants§

Source

const SYSTEM: &'static str

The OpenTelemetry db.system.name value for this backend (e.g. "postgresql", "sqlite", "mysql").

Required Methods§

Source

fn connection_attributes( pool: &Pool<Self>, ) -> (Option<String>, Option<u16>, Option<String>)

Extract host, port, and database namespace from the backend’s connect options.

Returns (host, port, namespace) where any component may be None if the backend does not support it (e.g. Sqlite has no host or port).

Source

fn rows_affected(result: &<Self as Database>::QueryResult) -> u64

Extract the number of rows affected from a QueryResult.

Each SQLx backend defines its own QueryResult type with an inherent rows_affected() method. This trait method provides a uniform interface for the instrumentation layer.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§