feat(core): add (minimal) Executor

This commit is contained in:
Ryan Leckey 2021-01-26 01:13:29 -08:00
parent 66ceff37b7
commit 76dd78f639
No known key found for this signature in database
GPG Key ID: F8AA68C235AB08C9
4 changed files with 42 additions and 0 deletions

View File

@ -7,8 +7,10 @@ mod close;
mod connect;
mod connection;
mod options;
mod executor;
pub(crate) mod runtime;
pub use executor::Executor;
pub use acquire::Acquire;
pub use close::Close;
pub use connect::Connect;

View File

@ -0,0 +1,13 @@
use crate::Database;
use super::Runtime;
pub trait Executor<Rt: Runtime>: crate::Executor<Rt>
where
Self::Database: Database<Rt>,
{
fn execute<'x, 'e, 'q>(&'e mut self, sql: &'q str) -> crate::Result<()>
where
'e: 'x,
'q: 'x;
}

25
sqlx-core/src/executor.rs Normal file
View File

@ -0,0 +1,25 @@
#[cfg(feature = "async")]
use futures_core::future::BoxFuture;
use crate::{Database, Result, Runtime};
/// Describes a type that can execute SQL queries on a self-provided database connection.
///
/// No guarantees are provided that successive queries run on the same physical
/// database connection.
///
/// A [`Connection`] is an `Executor` that guarantees that successive queries are ran on the
/// same physical database connection.
///
pub trait Executor<Rt: Runtime> {
type Database: Database<Rt>;
/// Execute the SQL query and return information about the result, including
/// the number of rows affected, if any.
#[cfg(feature = "async")]
fn execute<'x, 'e, 'q>(&'e mut self, sql: &'q str) -> BoxFuture<'x, Result<()>>
where
Rt: crate::Async,
'e: 'x,
'q: 'x;
}

View File

@ -24,6 +24,7 @@ mod connect;
mod connection;
mod database;
mod error;
mod executor;
mod options;
mod pool;
mod runtime;
@ -49,6 +50,7 @@ pub use connect::Connect;
pub use connection::Connection;
pub use database::{Database, HasOutput};
pub use error::{DatabaseError, Error, Result};
pub use executor::Executor;
pub use options::ConnectOptions;
pub use pool::Pool;
#[cfg(feature = "actix")]