Skip to main content

Database

Trait Database 

Source
pub trait Database: Database + Sealed {
    const SYSTEM: &'static str;
    const DEFAULT_NETWORK_PROTOCOL_NAME: Option<&'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, connect-attribute extraction, and rows_affected projection.

Implemented by this crate for sqlx::Sqlite, sqlx::Postgres, and sqlx::MySql behind their respective feature flags. The trait exists so the generic wrapper types (Pool, PoolConnection, Transaction) can resolve connection attributes once at pool construction and project rows_affected from the per-backend QueryResult types.

The trait is sealed. It is an internal generic-dispatch contract, not an extension point. Additional backends would require both an upstream sqlx::Database impl and a release of this crate.

Required Associated Constants§

Source

const SYSTEM: &'static str

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

Source

const DEFAULT_NETWORK_PROTOCOL_NAME: Option<&'static str>

Default network.protocol.name for this backend. Some("postgresql") / Some("mysql") for the network-protocol backends; None for embedded backends that do not speak a wire protocol (e.g. SQLite). Used by PoolBuilder::from to pre-populate the attribute on every span and per-operation metric; override via PoolBuilder::with_network_protocol_name.

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.

Implementations on Foreign Types§

Source§

impl Database for MySql

Available on crate feature mysql only.
Source§

impl Database for Postgres

Available on crate feature postgres only.
Source§

impl Database for Sqlite

Available on crate feature sqlite only.

Implementors§