sqlx_clickhouse_ext/
executor.rs1use futures_core::future::BoxFuture;
2use sqlx_core::{database::Database, error::Error, executor::Executor};
3
4pub trait ExecutorExt<'c, 'q, 'async_trait, T>: Executor<'c>
5where
6 'c: 'async_trait,
7 'q: 'async_trait,
8 T: 'async_trait,
9 T: From<<Self::Database as Database>::Row>,
10 Self: Sync + 'async_trait,
11{
12 fn execute(self, sql: &'q str) -> BoxFuture<'async_trait, Result<(), Error>> {
13 Box::pin(async move { Executor::<'c>::execute(self, sql).await.map(|_| ()) })
14 }
15
16 fn fetch_all(self, sql: &'q str) -> BoxFuture<'async_trait, Result<Vec<T>, Error>> {
17 Box::pin(async move {
18 Executor::<'c>::fetch_all(self, sql)
19 .await
20 .map(|rows| rows.into_iter().map(|row| row.into()).collect())
21 })
22 }
23
24 fn fetch_one(self, sql: &'q str) -> BoxFuture<'async_trait, Result<T, Error>> {
25 Box::pin(async move {
26 Executor::<'c>::fetch_one(self, sql)
27 .await
28 .map(|row| row.into())
29 })
30 }
31
32 fn fetch_optional(self, sql: &'q str) -> BoxFuture<'async_trait, Result<Option<T>, Error>> {
33 Box::pin(async move {
34 Executor::<'c>::fetch_optional(self, sql)
35 .await
36 .map(|option_row| option_row.map(|row| row.into()))
37 })
38 }
39}