Skip to main content

easy_sql/traits/
easy_executor.rs

1use easy_macros::always_context;
2
3use crate::Driver;
4
5use super::DriverConnection;
6
7#[always_context]
8/// Abstraction over [`sqlx::Executor`](https://docs.rs/sqlx/latest/sqlx/trait.Executor.html) used by the query macros.
9///
10/// Implemented for easy_sql and sqlx connections/pools; most users only need to pass a compatible
11/// connection to [`query!`](crate::query) or [`query_lazy!`](crate::query_lazy).
12///
13/// Will contain sql query watch functions in the future (gated by a feature)
14pub trait EasyExecutor<D: Driver> {
15    type InternalExecutor<'b>: sqlx::Executor<'b, Database = D::InternalDriver>
16    where
17        Self: 'b;
18    type IntoInternalExecutor<'b>: sqlx::Executor<'b, Database = D::InternalDriver>
19    where
20        Self: 'b;
21
22    async fn query_setup<O: SetupSql<D> + Send + Sync>(
23        &mut self,
24        sql: O,
25    ) -> anyhow::Result<O::Output>
26    where
27        DriverConnection<D>: Send + Sync;
28
29    fn executor<'a>(&'a mut self) -> Self::InternalExecutor<'a>;
30
31    fn into_executor<'a>(self) -> Self::IntoInternalExecutor<'a>
32    where
33        Self: 'a;
34}
35
36#[always_context]
37/// Gives information about the SQL query to execute, and how to execute it with the provided executor. Used by setup structures.
38pub trait SetupSql<D: Driver> {
39    type Output;
40
41    async fn query(self, exec: &mut impl EasyExecutor<D>) -> anyhow::Result<Self::Output>;
42}