From dfd0ac5974a37217c2f43f3b7b6b438e38cbc1e1 Mon Sep 17 00:00:00 2001 From: joeydewaal <99046430+joeydewaal@users.noreply.github.com> Date: Fri, 3 Jan 2025 09:26:09 +0100 Subject: [PATCH] feat: add Transaction type aliases (#3658) --- sqlx-mysql/src/lib.rs | 3 +++ sqlx-postgres/src/lib.rs | 3 +++ sqlx-sqlite/src/lib.rs | 3 +++ src/lib.rs | 12 +++++++++--- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/sqlx-mysql/src/lib.rs b/sqlx-mysql/src/lib.rs index c35be3c6fa..7aa14256f3 100644 --- a/sqlx-mysql/src/lib.rs +++ b/sqlx-mysql/src/lib.rs @@ -60,6 +60,9 @@ pub type MySqlPoolOptions = crate::pool::PoolOptions; pub trait MySqlExecutor<'c>: Executor<'c, Database = MySql> {} impl<'c, T: Executor<'c, Database = MySql>> MySqlExecutor<'c> for T {} +/// An alias for [`Transaction`][crate::transaction::Transaction], specialized for MySQL. +pub type MySqlTransaction<'c> = crate::transaction::Transaction<'c, MySql>; + // NOTE: required due to the lack of lazy normalization impl_into_arguments_for_arguments!(MySqlArguments); impl_acquire!(MySql, MySqlConnection); diff --git a/sqlx-postgres/src/lib.rs b/sqlx-postgres/src/lib.rs index c50f53067e..792f8bbdc0 100644 --- a/sqlx-postgres/src/lib.rs +++ b/sqlx-postgres/src/lib.rs @@ -70,6 +70,9 @@ pub type PgPoolOptions = crate::pool::PoolOptions; pub trait PgExecutor<'c>: Executor<'c, Database = Postgres> {} impl<'c, T: Executor<'c, Database = Postgres>> PgExecutor<'c> for T {} +/// An alias for [`Transaction`][crate::transaction::Transaction], specialized for Postgres. +pub type PgTransaction<'c> = crate::transaction::Transaction<'c, Postgres>; + impl_into_arguments_for_arguments!(PgArguments); impl_acquire!(Postgres, PgConnection); impl_column_index_for_row!(PgRow); diff --git a/sqlx-sqlite/src/lib.rs b/sqlx-sqlite/src/lib.rs index f8f5534879..3bcb6d148d 100644 --- a/sqlx-sqlite/src/lib.rs +++ b/sqlx-sqlite/src/lib.rs @@ -105,6 +105,9 @@ pub type SqlitePoolOptions = crate::pool::PoolOptions; pub trait SqliteExecutor<'c>: Executor<'c, Database = Sqlite> {} impl<'c, T: Executor<'c, Database = Sqlite>> SqliteExecutor<'c> for T {} +/// An alias for [`Transaction`][sqlx_core::transaction::Transaction], specialized for SQLite. +pub type SqliteTransaction<'c> = sqlx_core::transaction::Transaction<'c, Sqlite>; + // NOTE: required due to the lack of lazy normalization impl_into_arguments_for_arguments!(SqliteArguments<'q>); impl_column_index_for_row!(SqliteRow); diff --git a/src/lib.rs b/src/lib.rs index a9e90c071d..870fa703c5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,17 +37,23 @@ pub use sqlx_core::migrate; #[cfg(feature = "mysql")] #[cfg_attr(docsrs, doc(cfg(feature = "mysql")))] #[doc(inline)] -pub use sqlx_mysql::{self as mysql, MySql, MySqlConnection, MySqlExecutor, MySqlPool}; +pub use sqlx_mysql::{ + self as mysql, MySql, MySqlConnection, MySqlExecutor, MySqlPool, MySqlTransaction, +}; #[cfg(feature = "postgres")] #[cfg_attr(docsrs, doc(cfg(feature = "postgres")))] #[doc(inline)] -pub use sqlx_postgres::{self as postgres, PgConnection, PgExecutor, PgPool, Postgres}; +pub use sqlx_postgres::{ + self as postgres, PgConnection, PgExecutor, PgPool, PgTransaction, Postgres, +}; #[cfg(feature = "_sqlite")] #[cfg_attr(docsrs, doc(cfg(feature = "_sqlite")))] #[doc(inline)] -pub use sqlx_sqlite::{self as sqlite, Sqlite, SqliteConnection, SqliteExecutor, SqlitePool}; +pub use sqlx_sqlite::{ + self as sqlite, Sqlite, SqliteConnection, SqliteExecutor, SqlitePool, SqliteTransaction, +}; #[cfg(feature = "any")] #[cfg_attr(docsrs, doc(cfg(feature = "any")))]