Skip to content

Commit

Permalink
Add executor trait "aliases" (launchbadge#1412)
Browse files Browse the repository at this point in the history
  • Loading branch information
jplatte authored Sep 1, 2021
1 parent 89ee690 commit 335eed4
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
6 changes: 6 additions & 0 deletions sqlx-core/src/any/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Generic database driver with the specific driver selected at runtime.

use crate::executor::Executor;

#[macro_use]
mod decode;

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

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

/// An alias for [`Executor<'_, Database = Any>`][Executor].
pub trait AnyExecutor<'c>: Executor<'c, Database = Any> {}
impl<'c, T: Executor<'c, Database = Any>> AnyExecutor<'c> for T {}

// NOTE: required due to the lack of lazy normalization
impl_into_arguments_for_arguments!(AnyArguments<'q>);
impl_executor_for_pool_connection!(Any, AnyConnection, AnyRow);
Expand Down
6 changes: 6 additions & 0 deletions sqlx-core/src/mssql/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Microsoft SQL (MSSQL) database driver.

use crate::executor::Executor;

mod arguments;
mod column;
mod connection;
Expand Down Expand Up @@ -32,6 +34,10 @@ pub use value::{MssqlValue, MssqlValueRef};
/// An alias for [`Pool`][crate::pool::Pool], specialized for MSSQL.
pub type MssqlPool = crate::pool::Pool<Mssql>;

/// An alias for [`Executor<'_, Database = Mssql>`][Executor].
pub trait MssqlExecutor<'c>: Executor<'c, Database = Mssql> {}
impl<'c, T: Executor<'c, Database = Mssql>> MssqlExecutor<'c> for T {}

// NOTE: required due to the lack of lazy normalization
impl_into_arguments_for_arguments!(MssqlArguments);
impl_executor_for_pool_connection!(Mssql, MssqlConnection, MssqlRow);
Expand Down
6 changes: 6 additions & 0 deletions sqlx-core/src/mysql/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! **MySQL** database driver.

use crate::executor::Executor;

mod arguments;
mod collation;
mod column;
Expand Down Expand Up @@ -39,6 +41,10 @@ pub type MySqlPool = crate::pool::Pool<MySql>;
/// An alias for [`PoolOptions`][crate::pool::PoolOptions], specialized for MySQL.
pub type MySqlPoolOptions = crate::pool::PoolOptions<MySql>;

/// An alias for [`Executor<'_, Database = MySql>`][Executor].
pub trait MySqlExecutor<'c>: Executor<'c, Database = MySql> {}
impl<'c, T: Executor<'c, Database = MySql>> MySqlExecutor<'c> for T {}

// NOTE: required due to the lack of lazy normalization
impl_into_arguments_for_arguments!(MySqlArguments);
impl_executor_for_pool_connection!(MySql, MySqlConnection, MySqlRow);
Expand Down
6 changes: 6 additions & 0 deletions sqlx-core/src/postgres/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! **PostgreSQL** database driver.

use crate::executor::Executor;

mod arguments;
mod column;
mod connection;
Expand Down Expand Up @@ -41,6 +43,10 @@ pub type PgPool = crate::pool::Pool<Postgres>;
/// An alias for [`PoolOptions`][crate::pool::PoolOptions], specialized for Postgres.
pub type PgPoolOptions = crate::pool::PoolOptions<Postgres>;

/// An alias for [`Executor<'_, Database = Postgres>`][Executor].
pub trait PgExecutor<'c>: Executor<'c, Database = Postgres> {}
impl<'c, T: Executor<'c, Database = Postgres>> PgExecutor<'c> for T {}

impl_into_arguments_for_arguments!(PgArguments);
impl_executor_for_pool_connection!(Postgres, PgConnection, PgRow);
impl_executor_for_transaction!(Postgres, PgRow);
Expand Down
6 changes: 6 additions & 0 deletions sqlx-core/src/sqlite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// invariants.
#![allow(unsafe_code)]

use crate::executor::Executor;

mod arguments;
mod column;
mod connection;
Expand Down Expand Up @@ -43,6 +45,10 @@ pub type SqlitePool = crate::pool::Pool<Sqlite>;
/// An alias for [`PoolOptions`][crate::pool::PoolOptions], specialized for SQLite.
pub type SqlitePoolOptions = crate::pool::PoolOptions<Sqlite>;

/// An alias for [`Executor<'_, Database = Sqlite>`][Executor].
pub trait SqliteExecutor<'c>: Executor<'c, Database = Sqlite> {}
impl<'c, T: Executor<'c, Database = Sqlite>> SqliteExecutor<'c> for T {}

// NOTE: required due to the lack of lazy normalization
impl_into_arguments_for_arguments!(SqliteArguments<'q>);
impl_executor_for_pool_connection!(Sqlite, SqliteConnection, SqliteRow);
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,23 @@ pub use sqlx_core::migrate;
),
feature = "any"
))]
pub use sqlx_core::any::{self, Any, AnyConnection, AnyPool};
pub use sqlx_core::any::{self, Any, AnyConnection, AnyExecutor, AnyPool};

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

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

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

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

#[cfg(feature = "macros")]
#[doc(hidden)]
Expand Down

0 comments on commit 335eed4

Please sign in to comment.