Skip to content

Commit 335eed4

Browse files
authored
Add executor trait "aliases" (#1412)
1 parent 89ee690 commit 335eed4

File tree

6 files changed

+35
-5
lines changed

6 files changed

+35
-5
lines changed

sqlx-core/src/any/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Generic database driver with the specific driver selected at runtime.
22
3+
use crate::executor::Executor;
4+
35
#[macro_use]
46
mod decode;
57

@@ -45,6 +47,10 @@ pub type AnyPool = crate::pool::Pool<Any>;
4547

4648
pub type AnyPoolOptions = crate::pool::PoolOptions<Any>;
4749

50+
/// An alias for [`Executor<'_, Database = Any>`][Executor].
51+
pub trait AnyExecutor<'c>: Executor<'c, Database = Any> {}
52+
impl<'c, T: Executor<'c, Database = Any>> AnyExecutor<'c> for T {}
53+
4854
// NOTE: required due to the lack of lazy normalization
4955
impl_into_arguments_for_arguments!(AnyArguments<'q>);
5056
impl_executor_for_pool_connection!(Any, AnyConnection, AnyRow);

sqlx-core/src/mssql/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Microsoft SQL (MSSQL) database driver.
22
3+
use crate::executor::Executor;
4+
35
mod arguments;
46
mod column;
57
mod connection;
@@ -32,6 +34,10 @@ pub use value::{MssqlValue, MssqlValueRef};
3234
/// An alias for [`Pool`][crate::pool::Pool], specialized for MSSQL.
3335
pub type MssqlPool = crate::pool::Pool<Mssql>;
3436

37+
/// An alias for [`Executor<'_, Database = Mssql>`][Executor].
38+
pub trait MssqlExecutor<'c>: Executor<'c, Database = Mssql> {}
39+
impl<'c, T: Executor<'c, Database = Mssql>> MssqlExecutor<'c> for T {}
40+
3541
// NOTE: required due to the lack of lazy normalization
3642
impl_into_arguments_for_arguments!(MssqlArguments);
3743
impl_executor_for_pool_connection!(Mssql, MssqlConnection, MssqlRow);

sqlx-core/src/mysql/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! **MySQL** database driver.
22
3+
use crate::executor::Executor;
4+
35
mod arguments;
46
mod collation;
57
mod column;
@@ -39,6 +41,10 @@ pub type MySqlPool = crate::pool::Pool<MySql>;
3941
/// An alias for [`PoolOptions`][crate::pool::PoolOptions], specialized for MySQL.
4042
pub type MySqlPoolOptions = crate::pool::PoolOptions<MySql>;
4143

44+
/// An alias for [`Executor<'_, Database = MySql>`][Executor].
45+
pub trait MySqlExecutor<'c>: Executor<'c, Database = MySql> {}
46+
impl<'c, T: Executor<'c, Database = MySql>> MySqlExecutor<'c> for T {}
47+
4248
// NOTE: required due to the lack of lazy normalization
4349
impl_into_arguments_for_arguments!(MySqlArguments);
4450
impl_executor_for_pool_connection!(MySql, MySqlConnection, MySqlRow);

sqlx-core/src/postgres/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! **PostgreSQL** database driver.
22
3+
use crate::executor::Executor;
4+
35
mod arguments;
46
mod column;
57
mod connection;
@@ -41,6 +43,10 @@ pub type PgPool = crate::pool::Pool<Postgres>;
4143
/// An alias for [`PoolOptions`][crate::pool::PoolOptions], specialized for Postgres.
4244
pub type PgPoolOptions = crate::pool::PoolOptions<Postgres>;
4345

46+
/// An alias for [`Executor<'_, Database = Postgres>`][Executor].
47+
pub trait PgExecutor<'c>: Executor<'c, Database = Postgres> {}
48+
impl<'c, T: Executor<'c, Database = Postgres>> PgExecutor<'c> for T {}
49+
4450
impl_into_arguments_for_arguments!(PgArguments);
4551
impl_executor_for_pool_connection!(Postgres, PgConnection, PgRow);
4652
impl_executor_for_transaction!(Postgres, PgRow);

sqlx-core/src/sqlite/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// invariants.
66
#![allow(unsafe_code)]
77

8+
use crate::executor::Executor;
9+
810
mod arguments;
911
mod column;
1012
mod connection;
@@ -43,6 +45,10 @@ pub type SqlitePool = crate::pool::Pool<Sqlite>;
4345
/// An alias for [`PoolOptions`][crate::pool::PoolOptions], specialized for SQLite.
4446
pub type SqlitePoolOptions = crate::pool::PoolOptions<Sqlite>;
4547

48+
/// An alias for [`Executor<'_, Database = Sqlite>`][Executor].
49+
pub trait SqliteExecutor<'c>: Executor<'c, Database = Sqlite> {}
50+
impl<'c, T: Executor<'c, Database = Sqlite>> SqliteExecutor<'c> for T {}
51+
4652
// NOTE: required due to the lack of lazy normalization
4753
impl_into_arguments_for_arguments!(SqliteArguments<'q>);
4854
impl_executor_for_pool_connection!(Sqlite, SqliteConnection, SqliteRow);

src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,23 @@ pub use sqlx_core::migrate;
4646
),
4747
feature = "any"
4848
))]
49-
pub use sqlx_core::any::{self, Any, AnyConnection, AnyPool};
49+
pub use sqlx_core::any::{self, Any, AnyConnection, AnyExecutor, AnyPool};
5050

5151
#[cfg(feature = "mysql")]
5252
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
53-
pub use sqlx_core::mysql::{self, MySql, MySqlConnection, MySqlPool};
53+
pub use sqlx_core::mysql::{self, MySql, MySqlConnection, MySqlExecutor, MySqlPool};
5454

5555
#[cfg(feature = "mssql")]
5656
#[cfg_attr(docsrs, doc(cfg(feature = "mssql")))]
57-
pub use sqlx_core::mssql::{self, Mssql, MssqlConnection, MssqlPool};
57+
pub use sqlx_core::mssql::{self, Mssql, MssqlConnection, MssqlExecutor, MssqlPool};
5858

5959
#[cfg(feature = "postgres")]
6060
#[cfg_attr(docsrs, doc(cfg(feature = "postgres")))]
61-
pub use sqlx_core::postgres::{self, PgConnection, PgPool, Postgres};
61+
pub use sqlx_core::postgres::{self, PgConnection, PgExecutor, PgPool, Postgres};
6262

6363
#[cfg(feature = "sqlite")]
6464
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
65-
pub use sqlx_core::sqlite::{self, Sqlite, SqliteConnection, SqlitePool};
65+
pub use sqlx_core::sqlite::{self, Sqlite, SqliteConnection, SqliteExecutor, SqlitePool};
6666

6767
#[cfg(feature = "macros")]
6868
#[doc(hidden)]

0 commit comments

Comments
 (0)