mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-25 11:30:23 +00:00
* refactor: introduce `SqlSafeStr` API * rebase main * Add SqlStr + remove Statement lifetime * Update the definition of Executor and AnyConnectionBackend + update Postgres driver * Update MySql driver * Update Sqlite driver * remove debug clone count * Reduce the amount of SqlStr clones * improve QueryBuilder error message * cargo fmt * fix clippy warnings * fix doc test * Avoid panic in `QueryBuilder::reset` * Use `QueryBuilder` when removing all test db's * Add comment to `SqlStr` Co-authored-by: Austin Bonander <austin.bonander@gmail.com> * Update sqlx-core/src/query_builder.rs Co-authored-by: Austin Bonander <austin.bonander@gmail.com> * Add `Clone` as supertrait to `Statement` * Move `Connection`, `AnyConnectionBackend` and `TransactionManager` to `SqlStr` * Replace `sql_cloned` with `sql` in `Statement` * Update `Executor` trait * Update unit tests + QueryBuilder changes * Remove code in comments * Update comment in `QueryBuilder` * Fix clippy warnings * Update `Migrate` comment * Small changes * Move `Migration` to `SqlStr` --------- Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
144 lines
3.6 KiB
Rust
144 lines
3.6 KiB
Rust
use either::Either;
|
|
use futures_core::future::BoxFuture;
|
|
use futures_core::stream::BoxStream;
|
|
use futures_util::TryStreamExt;
|
|
|
|
use crate::database::Database;
|
|
use crate::describe::Describe;
|
|
use crate::error::Error;
|
|
use crate::executor::{Execute, Executor};
|
|
use crate::pool::Pool;
|
|
use crate::sql_str::SqlStr;
|
|
|
|
impl<'p, DB: Database> Executor<'p> for &'_ Pool<DB>
|
|
where
|
|
for<'c> &'c mut DB::Connection: Executor<'c, Database = DB>,
|
|
{
|
|
type Database = DB;
|
|
|
|
fn fetch_many<'e, 'q: 'e, E>(
|
|
self,
|
|
query: E,
|
|
) -> BoxStream<'e, Result<Either<DB::QueryResult, DB::Row>, Error>>
|
|
where
|
|
E: 'q + Execute<'q, Self::Database>,
|
|
{
|
|
let pool = self.clone();
|
|
|
|
Box::pin(try_stream! {
|
|
let mut conn = pool.acquire().await?;
|
|
let mut s = conn.fetch_many(query);
|
|
|
|
while let Some(v) = s.try_next().await? {
|
|
r#yield!(v);
|
|
}
|
|
|
|
Ok(())
|
|
})
|
|
}
|
|
|
|
fn fetch_optional<'e, 'q: 'e, E>(
|
|
self,
|
|
query: E,
|
|
) -> BoxFuture<'e, Result<Option<DB::Row>, Error>>
|
|
where
|
|
E: 'q + Execute<'q, Self::Database>,
|
|
{
|
|
let pool = self.clone();
|
|
|
|
Box::pin(async move { pool.acquire().await?.fetch_optional(query).await })
|
|
}
|
|
|
|
fn prepare_with<'e>(
|
|
self,
|
|
sql: SqlStr,
|
|
parameters: &'e [<Self::Database as Database>::TypeInfo],
|
|
) -> BoxFuture<'e, Result<<Self::Database as Database>::Statement, Error>>
|
|
where
|
|
'p: 'e,
|
|
{
|
|
let pool = self.clone();
|
|
|
|
Box::pin(async move { pool.acquire().await?.prepare_with(sql, parameters).await })
|
|
}
|
|
|
|
#[doc(hidden)]
|
|
fn describe<'e>(self, sql: SqlStr) -> BoxFuture<'e, Result<Describe<Self::Database>, Error>> {
|
|
let pool = self.clone();
|
|
|
|
Box::pin(async move { pool.acquire().await?.describe(sql).await })
|
|
}
|
|
}
|
|
|
|
// Causes an overflow when evaluating `&mut DB::Connection: Executor`.
|
|
//
|
|
//
|
|
// impl<'c, DB: Database> crate::executor::Executor<'c> for &'c mut crate::pool::PoolConnection<DB>
|
|
// where
|
|
// &'c mut DB::Connection: Executor<'c, Database = DB>,
|
|
// {
|
|
// type Database = DB;
|
|
//
|
|
//
|
|
//
|
|
// #[inline]
|
|
// fn fetch_many<'e, 'q: 'e, E: 'q>(
|
|
// self,
|
|
// query: E,
|
|
// ) -> futures_core::stream::BoxStream<
|
|
// 'e,
|
|
// Result<
|
|
// either::Either<<DB as crate::database::Database>::QueryResult, DB::Row>,
|
|
// crate::error::Error,
|
|
// >,
|
|
// >
|
|
// where
|
|
// 'c: 'e,
|
|
// E: crate::executor::Execute<'q, DB>,
|
|
// {
|
|
// (**self).fetch_many(query)
|
|
// }
|
|
//
|
|
// #[inline]
|
|
// fn fetch_optional<'e, 'q: 'e, E: 'q>(
|
|
// self,
|
|
// query: E,
|
|
// ) -> futures_core::future::BoxFuture<'e, Result<Option<DB::Row>, crate::error::Error>>
|
|
// where
|
|
// 'c: 'e,
|
|
// E: crate::executor::Execute<'q, DB>,
|
|
// {
|
|
// (**self).fetch_optional(query)
|
|
// }
|
|
//
|
|
// #[inline]
|
|
// fn prepare_with<'e, 'q: 'e>(
|
|
// self,
|
|
// sql: &'q str,
|
|
// parameters: &'e [<DB as crate::database::Database>::TypeInfo],
|
|
// ) -> futures_core::future::BoxFuture<
|
|
// 'e,
|
|
// Result<<DB as crate::database::Database>::Statement<'q>, crate::error::Error>,
|
|
// >
|
|
// where
|
|
// 'c: 'e,
|
|
// {
|
|
// (**self).prepare_with(sql, parameters)
|
|
// }
|
|
//
|
|
// #[doc(hidden)]
|
|
// #[inline]
|
|
// fn describe<'e, 'q: 'e>(
|
|
// self,
|
|
// sql: &'q str,
|
|
// ) -> futures_core::future::BoxFuture<
|
|
// 'e,
|
|
// Result<crate::describe::Describe<DB>, crate::error::Error>,
|
|
// >
|
|
// where
|
|
// 'c: 'e,
|
|
// {
|
|
// (**self).describe(sql)
|
|
// }
|
|
// }
|