Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl<DB: sqlx::Database> PoolBuilder<DB> {
/// 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<DB>
where
DB: sqlx::Database,
Expand All @@ -119,6 +119,18 @@ where
attributes: Arc<Attributes>,
}

impl<DB> Clone for Pool<DB>
where
DB: sqlx::Database,
{
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
attributes: self.attributes.clone(),
}
}
}

impl<DB> From<sqlx::Pool<DB>> for Pool<DB>
where
DB: sqlx::Database,
Expand All @@ -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.
Expand All @@ -155,7 +167,7 @@ where
})
})
}

/// Acquires a pooled connection, instrumented for tracing.
pub async fn acquire(&self) -> Result<PoolConnection<DB>, sqlx::Error> {
self.inner.acquire().await.map(|inner| PoolConnection {
Expand Down
7 changes: 7 additions & 0 deletions tests/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::time::Duration;

use sqlx::Postgres;
use sqlx_tracing::Pool;
use testcontainers::{
GenericImage, ImageExt,
core::{ContainerPort, WaitFor},
Expand Down Expand Up @@ -78,3 +79,9 @@ async fn execute() {
.await;
}
}

#[test]
fn pool_postgres_is_clone() {
fn assert_clone<T: Clone>() {}
assert_clone::<Pool<Postgres>>();
}
7 changes: 7 additions & 0 deletions tests/sqlite.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![cfg(feature = "sqlite")]

use sqlx::Sqlite;
use sqlx_tracing::Pool;

mod common;

Expand Down Expand Up @@ -31,3 +32,9 @@ async fn execute() {
.await;
}
}

#[test]
fn pool_sqlite_is_clone() {
fn assert_clone<T: Clone>() {}
assert_clone::<Pool<Sqlite>>();
}