Skip to main content

sqlx_ext/
lib.rs

1//! Implicit, poll-scoped SQLx execution.
2//!
3//! A transaction scope does not propagate into `tokio::spawn`; await child work
4//! before its enclosing [`Database::transaction`] completes.
5
6mod database;
7mod query;
8
9pub use database::{
10    ConnectionRef, Database, DatabaseHandle, DbError, Transaction, current_connection,
11    with_connection_override,
12};
13pub use query::{ScopedQuery, ScopedQueryAs, ScopedScalarQuery, ScopedStream};
14
15/// Marker trait for SQLx query objects that participate in scoped execution.
16/// Import [`prelude`] for the extension methods themselves.
17pub trait ScopedExecutor: Send {}
18
19impl<'q, DB, A> ScopedExecutor for sqlx::query::Query<'q, DB, A>
20where
21    DB: sqlx::Database,
22    A: Send,
23{
24}
25impl<'q, DB, O, A> ScopedExecutor for sqlx::query::QueryAs<'q, DB, O, A>
26where
27    DB: sqlx::Database,
28    O: Send,
29    A: Send,
30{
31}
32impl<'q, DB, O, A> ScopedExecutor for sqlx::query::QueryScalar<'q, DB, O, A>
33where
34    DB: sqlx::Database,
35    O: Send,
36    A: Send,
37{
38}
39
40/// Production-oriented import surface for scoped SQLx execution.
41pub mod prelude {
42    pub use crate::{ScopedExecutor, ScopedQuery, ScopedQueryAs, ScopedScalarQuery, ScopedStream};
43}