TracedConnection

Struct TracedConnection 

Source
pub struct TracedConnection { /* private fields */ }
Expand description

A traced wrapper around SeaORM’s DatabaseConnection.

This wrapper implements ConnectionTrait, StreamTrait, and TransactionTrait, making it a drop-in replacement for DatabaseConnection. All database operations are automatically instrumented with tracing spans.

§Span Nesting

Spans created by TracedConnection automatically become children of the current tracing span context. This means if you’re using tracing middleware in your web framework (e.g., tower-http’s TraceLayer), database spans will appear nested under HTTP request spans in your traces.

§Example

use sea_orm::Database;
use sea_orm_tracing::TracedConnection;

let db = Database::connect("postgres://localhost/mydb").await?;
let traced = TracedConnection::from(db);

// All queries are now traced
let users = Users::find().all(&traced).await?;

Implementations§

Source§

impl TracedConnection

Source

pub fn new(connection: DatabaseConnection, config: TracingConfig) -> Self

Create a new traced connection with the given configuration.

Source

pub fn wrap(connection: DatabaseConnection) -> Self

Create a new traced connection with default configuration.

Source

pub fn inner(&self) -> &DatabaseConnection

Get a reference to the underlying DatabaseConnection.

Source

pub fn config(&self) -> &TracingConfig

Get the tracing configuration.

Source

pub fn into_inner(self) -> DatabaseConnection

Consume the wrapper and return the inner DatabaseConnection.

Trait Implementations§

Source§

impl AsRef<DatabaseConnection> for TracedConnection

Source§

fn as_ref(&self) -> &DatabaseConnection

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for TracedConnection

Source§

fn clone(&self) -> TracedConnection

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ConnectionTrait for TracedConnection

Source§

fn get_database_backend(&self) -> DbBackend

Fetch the database backend as specified in DbBackend. This depends on feature flags enabled.
Source§

fn execute<'life0, 'async_trait>( &'life0 self, stmt: Statement, ) -> Pin<Box<dyn Future<Output = Result<ExecResult, DbErr>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute a Statement
Source§

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

Execute a unprepared Statement
Source§

fn query_one<'life0, 'async_trait>( &'life0 self, stmt: Statement, ) -> Pin<Box<dyn Future<Output = Result<Option<QueryResult>, DbErr>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute a Statement and return a query
Source§

fn query_all<'life0, 'async_trait>( &'life0 self, stmt: Statement, ) -> Pin<Box<dyn Future<Output = Result<Vec<QueryResult>, DbErr>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute a Statement and return a collection Vec<QueryResult> on success
Source§

fn support_returning(&self) -> bool

Check if the connection supports RETURNING syntax on insert and update
Source§

fn is_mock_connection(&self) -> bool

Check if the connection is a test connection for the Mock database
Source§

impl Debug for TracedConnection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<DatabaseConnection> for TracedConnection

Source§

fn from(connection: DatabaseConnection) -> Self

Converts to this type from the input type.
Source§

impl StreamTrait for TracedConnection

Source§

type Stream<'a> = <DatabaseConnection as StreamTrait>::Stream<'a>

Create a stream for the QueryResult
Source§

fn stream<'a>( &'a self, stmt: Statement, ) -> Pin<Box<dyn Future<Output = Result<Self::Stream<'a>, DbErr>> + Send + 'a>>

Execute a Statement and return a stream of results
Source§

impl TransactionTrait for TracedConnection

Source§

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

Execute SQL BEGIN transaction. Returns a Transaction that can be committed or rolled back
Source§

fn begin_with_config<'life0, 'async_trait>( &'life0 self, isolation_level: Option<IsolationLevel>, access_mode: Option<AccessMode>, ) -> Pin<Box<dyn Future<Output = Result<DatabaseTransaction, DbErr>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute SQL BEGIN transaction with isolation level and/or access mode. Returns a Transaction that can be committed or rolled back
Source§

fn transaction<'life0, 'async_trait, F, T, E>( &'life0 self, callback: F, ) -> Pin<Box<dyn Future<Output = Result<T, TransactionError<E>>> + Send + 'async_trait>>
where F: for<'c> FnOnce(&'c DatabaseTransaction) -> Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'c>> + Send + 'async_trait, T: Send + 'async_trait, E: Display + Debug + Send + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Execute the function inside a transaction. If the function returns an error, the transaction will be rolled back. If it does not return an error, the transaction will be committed.
Source§

fn transaction_with_config<'life0, 'async_trait, F, T, E>( &'life0 self, callback: F, isolation_level: Option<IsolationLevel>, access_mode: Option<AccessMode>, ) -> Pin<Box<dyn Future<Output = Result<T, TransactionError<E>>> + Send + 'async_trait>>
where F: for<'c> FnOnce(&'c DatabaseTransaction) -> Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'c>> + Send + 'async_trait, T: Send + 'async_trait, E: Display + Debug + Send + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Execute the function inside a transaction with isolation level and/or access mode. If the function returns an error, the transaction will be rolled back. If it does not return an error, the transaction will be committed.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more