implement facade crate so macros can be used from same namespace

This commit is contained in:
Austin Bonander
2019-11-22 10:30:16 +00:00
parent fecd367e8d
commit fc07830639
122 changed files with 197 additions and 146 deletions

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

@@ -0,0 +1,58 @@
use crate::{backend::Backend, error::Error, query::IntoQueryParameters, row::FromSqlRow};
use futures_core::{future::BoxFuture, stream::BoxStream};
use futures_util::TryStreamExt;
pub trait Executor: Send {
type Backend: Backend;
fn execute<'c, 'q: 'c, A: 'c>(
&'c mut self,
query: &'q str,
params: A,
) -> BoxFuture<'c, Result<u64, Error>>
where
A: IntoQueryParameters<Self::Backend> + Send;
fn fetch<'c, 'q: 'c, T: 'c, A: 'c>(
&'c mut self,
query: &'q str,
params: A,
) -> BoxStream<'c, Result<T, Error>>
where
A: IntoQueryParameters<Self::Backend> + Send,
T: FromSqlRow<Self::Backend> + Send + Unpin;
fn fetch_all<'c, 'q: 'c, T: 'c, A: 'c>(
&'c mut self,
query: &'q str,
params: A,
) -> BoxFuture<'c, Result<Vec<T>, Error>>
where
A: IntoQueryParameters<Self::Backend> + Send,
T: FromSqlRow<Self::Backend> + Send + Unpin,
{
Box::pin(self.fetch(query, params).try_collect())
}
fn fetch_optional<'c, 'q: 'c, T: 'c, A: 'c>(
&'c mut self,
query: &'q str,
params: A,
) -> BoxFuture<'c, Result<Option<T>, Error>>
where
A: IntoQueryParameters<Self::Backend> + Send,
T: FromSqlRow<Self::Backend> + Send;
fn fetch_one<'c, 'q: 'c, T: 'c, A: 'c>(
&'c mut self,
query: &'q str,
params: A,
) -> BoxFuture<'c, Result<T, Error>>
where
A: IntoQueryParameters<Self::Backend> + Send,
T: FromSqlRow<Self::Backend> + Send,
{
let fut = self.fetch_optional(query, params);
Box::pin(async move { fut.await?.ok_or(Error::NotFound) })
}
}