From 7edaeaa3dc728143700387aa38f31a6bb2c373b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Fourniez?= <10551899+Theo-Fourniez@users.noreply.github.com> Date: Wed, 11 Feb 2026 16:25:08 +0000 Subject: [PATCH] feat(pool): Add try_begin method --- src/lib.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index ee99dbc..3b55320 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -143,7 +143,19 @@ 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. + pub async fn try_begin<'c>(&'c self) -> Result>, sqlx::Error> { + self.inner.try_begin().await.map(|t| { + t.map(|inner| Transaction { + inner, + attributes: self.attributes.clone(), + }) + }) + } + /// Acquires a pooled connection, instrumented for tracing. pub async fn acquire(&self) -> Result, sqlx::Error> { self.inner.acquire().await.map(|inner| PoolConnection {