Skip to main content

MetricsConnection

Struct MetricsConnection 

Source
pub struct MetricsConnection<C> { /* private fields */ }
Expand description

A Connection wrapper that counts operations and measures latency.

Access metrics through MetricsConnection::metrics. The metrics counters are AtomicU64 so they are safe to read concurrently.

§Example

// use oxisql_core::middleware::MetricsConnection;
// use std::sync::Arc;
// let metrics = Arc::new(oxisql_core::middleware::ConnectionMetrics::default());
// let conn = MetricsConnection::new(backend_conn, Arc::clone(&metrics));
// conn.execute("INSERT INTO t VALUES ($1)", &[&42i64]).await?;
// println!("{:?}", metrics.snapshot());

Implementations§

Source§

impl<C: Connection> MetricsConnection<C>

Source

pub fn new(inner: C, metrics: Arc<ConnectionMetrics>) -> Self

Wrap inner with the given shared metrics store.

Source

pub fn metrics(&self) -> &Arc<ConnectionMetrics>

Return a reference to the shared metrics.

Source

pub fn into_inner(self) -> C

Consume the wrapper and return the inner connection.

Trait Implementations§

Source§

impl<C: Connection + Send + Sync> Connection for MetricsConnection<C>

Source§

fn execute<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, sql: &'life1 str, params: &'life2 [&'life3 dyn ToSqlValue], ) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Execute a DML/DDL statement and return the number of rows affected. Read more
Source§

fn query<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, sql: &'life1 str, params: &'life2 [&'life3 dyn ToSqlValue], ) -> Pin<Box<dyn Future<Output = Result<Vec<Row>, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Execute a SELECT statement and return the result rows. Read more
Source§

fn transaction<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Transaction + '_>, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Begin a transaction, returning a handle that can be committed or rolled back.
Source§

fn execute_batch<'life0, 'life1, 'async_trait>( &'life0 self, sql: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute multiple semicolon-separated SQL statements in a single call. Read more
Source§

fn ping<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Lightweight connectivity check. Read more
Source§

fn prepare<'life0, 'life1, 'async_trait>( &'life0 self, sql: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn PreparedStatement + '_>, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Compile a SQL statement for repeated execution with different parameters. Read more
Source§

fn tables<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<TableInfo>, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List all tables visible to the current connection. Read more
Source§

fn columns<'life0, 'life1, 'async_trait>( &'life0 self, table: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<ColumnInfo>, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

List all columns of the named table. Read more
Source§

fn indexes<'life0, 'life1, 'async_trait>( &'life0 self, table: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<IndexInfo>, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

List all indexes defined on the named table. Read more
Source§

fn foreign_keys<'life0, 'life1, 'async_trait>( &'life0 self, table: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<ForeignKeyInfo>, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

List all foreign-key constraints on the named table. Read more
Source§

fn execute_named<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, sql: &'life1 str, params: &'life2 [(&'life3 str, &'life4 dyn ToSqlValue)], ) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Execute a SQL statement with named parameters. Read more
Source§

fn query_named<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, sql: &'life1 str, params: &'life2 [(&'life3 str, &'life4 dyn ToSqlValue)], ) -> Pin<Box<dyn Future<Output = Result<Vec<Row>, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Execute a SQL query with named parameters and return the result rows. Read more
Source§

fn last_warnings(&self) -> Vec<SqlWarning>

Return any SQL warnings generated by the most recently executed statement. Read more
Source§

fn query_stream<'a>( &'a self, sql: &'a str, params: &'a [&'a dyn ToSqlValue], ) -> Pin<Box<dyn Stream<Item = Result<Row, OxiSqlError>> + Send + 'a>>

Execute a SELECT and return rows as an async stream. Read more

Auto Trait Implementations§

§

impl<C> Freeze for MetricsConnection<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for MetricsConnection<C>
where C: RefUnwindSafe,

§

impl<C> Send for MetricsConnection<C>
where C: Send,

§

impl<C> Sync for MetricsConnection<C>
where C: Sync,

§

impl<C> Unpin for MetricsConnection<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for MetricsConnection<C>
where C: UnsafeUnpin,

§

impl<C> UnwindSafe for MetricsConnection<C>
where C: UnwindSafe,

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