pub struct LoggingConnection<C> { /* private fields */ }Expand description
A Connection wrapper that logs every SQL operation.
Uses the log crate at DEBUG level for successful operations and
WARN level for errors. Enable logging in your application with any
log-compatible backend (e.g. env_logger, tracing).
§Example
// use oxisql_core::middleware::LoggingConnection;
// let conn = LoggingConnection::new(backend_conn);
// conn.execute("INSERT INTO t VALUES ($1)", &[&42i64]).await?;
// Logs: [execute] INSERT INTO t VALUES ($1) — 123µsImplementations§
Source§impl<C: Connection> LoggingConnection<C>
impl<C: Connection> LoggingConnection<C>
Sourcepub fn with_prefix(inner: C, prefix: impl Into<String>) -> Self
pub fn with_prefix(inner: C, prefix: impl Into<String>) -> Self
Wrap inner with a label prepended to log lines.
Sourcepub fn into_inner(self) -> C
pub fn into_inner(self) -> C
Consume the wrapper and return the inner connection.
Trait Implementations§
Source§impl<C: Connection + Send + Sync> Connection for LoggingConnection<C>
impl<C: Connection + Send + Sync> Connection for LoggingConnection<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,
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,
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 moreSource§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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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>
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>>
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 moreAuto Trait Implementations§
impl<C> Freeze for LoggingConnection<C>where
C: Freeze,
impl<C> RefUnwindSafe for LoggingConnection<C>where
C: RefUnwindSafe,
impl<C> Send for LoggingConnection<C>where
C: Send,
impl<C> Sync for LoggingConnection<C>where
C: Sync,
impl<C> Unpin for LoggingConnection<C>where
C: Unpin,
impl<C> UnsafeUnpin for LoggingConnection<C>where
C: UnsafeUnpin,
impl<C> UnwindSafe for LoggingConnection<C>where
C: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more