diff --git a/src/lib.rs b/src/lib.rs index 3b55320..db86288 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -110,7 +110,7 @@ impl PoolBuilder { /// An asynchronous pool of SQLx database connections with tracing instrumentation. /// /// Wraps a SQLx [`Pool`] and propagates tracing attributes to all acquired connections. -#[derive(Clone, Debug)] +#[derive(Debug)] pub struct Pool where DB: sqlx::Database, @@ -119,6 +119,18 @@ where attributes: Arc, } +impl Clone for Pool +where + DB: sqlx::Database, +{ + fn clone(&self) -> Self { + Self { + inner: self.inner.clone(), + attributes: self.attributes.clone(), + } + } +} + impl From> for Pool where DB: sqlx::Database, @@ -143,7 +155,7 @@ where attributes: self.attributes.clone(), }) } - + /// Attempts to retrieve a connection and immediately begins a new transaction if successful. /// /// The returned [`Transaction`] is instrumented for tracing. @@ -155,7 +167,7 @@ where }) }) } - + /// Acquires a pooled connection, instrumented for tracing. pub async fn acquire(&self) -> Result, sqlx::Error> { self.inner.acquire().await.map(|inner| PoolConnection { diff --git a/tests/postgres.rs b/tests/postgres.rs index 0b2d0c6..7a788d7 100644 --- a/tests/postgres.rs +++ b/tests/postgres.rs @@ -3,6 +3,7 @@ use std::time::Duration; use sqlx::Postgres; +use sqlx_tracing::Pool; use testcontainers::{ GenericImage, ImageExt, core::{ContainerPort, WaitFor}, @@ -78,3 +79,9 @@ async fn execute() { .await; } } + +#[test] +fn pool_postgres_is_clone() { + fn assert_clone() {} + assert_clone::>(); +} diff --git a/tests/sqlite.rs b/tests/sqlite.rs index 921be0a..19d6e4b 100644 --- a/tests/sqlite.rs +++ b/tests/sqlite.rs @@ -1,6 +1,7 @@ #![cfg(feature = "sqlite")] use sqlx::Sqlite; +use sqlx_tracing::Pool; mod common; @@ -31,3 +32,9 @@ async fn execute() { .await; } } + +#[test] +fn pool_sqlite_is_clone() { + fn assert_clone() {} + assert_clone::>(); +}