Skip to content

Commit

Permalink
use the persistent query setting with the Any driver (launchbadge#3297)
Browse files Browse the repository at this point in the history
  • Loading branch information
etorreborre authored and jrasanen committed Oct 14, 2024
1 parent 4c02444 commit 762b04d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions sqlx-core/src/any/connection/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ pub trait AnyConnectionBackend: std::any::Any + Debug + Send + 'static {
fn fetch_many<'q>(
&'q mut self,
query: &'q str,
persistent: bool,
arguments: Option<AnyArguments<'q>>,
) -> BoxStream<'q, crate::Result<Either<AnyQueryResult, AnyRow>>>;

fn fetch_optional<'q>(
&'q mut self,
query: &'q str,
persistent: bool,
arguments: Option<AnyArguments<'q>>,
) -> BoxFuture<'q, crate::Result<Option<AnyRow>>>;

Expand Down
6 changes: 4 additions & 2 deletions sqlx-core/src/any/connection/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ impl<'c> Executor<'c> for &'c mut AnyConnection {
Ok(arguments) => arguments,
Err(error) => return stream::once(future::ready(Err(error))).boxed(),
};
self.backend.fetch_many(query.sql(), arguments)
self.backend
.fetch_many(query.sql(), query.persistent(), arguments)
}

fn fetch_optional<'e, 'q: 'e, E>(
Expand All @@ -38,7 +39,8 @@ impl<'c> Executor<'c> for &'c mut AnyConnection {
Ok(arguments) => arguments,
Err(error) => return future::ready(Err(error)).boxed(),
};
self.backend.fetch_optional(query.sql(), arguments)
self.backend
.fetch_optional(query.sql(), query.persistent(), arguments)
}

fn prepare_with<'e, 'q: 'e>(
Expand Down
6 changes: 4 additions & 2 deletions sqlx-mysql/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ impl AnyConnectionBackend for MySqlConnection {
fn fetch_many<'q>(
&'q mut self,
query: &'q str,
persistent: bool,
arguments: Option<AnyArguments<'q>>,
) -> BoxStream<'q, sqlx_core::Result<Either<AnyQueryResult, AnyRow>>> {
let persistent = arguments.is_some();
let persistent = persistent && arguments.is_some();
let arguments = match arguments.as_ref().map(AnyArguments::convert_to).transpose() {
Ok(arguments) => arguments,
Err(error) => {
Expand All @@ -100,9 +101,10 @@ impl AnyConnectionBackend for MySqlConnection {
fn fetch_optional<'q>(
&'q mut self,
query: &'q str,
persistent: bool,
arguments: Option<AnyArguments<'q>>,
) -> BoxFuture<'q, sqlx_core::Result<Option<AnyRow>>> {
let persistent = arguments.is_some();
let persistent = persistent && arguments.is_some();
let arguments = arguments
.as_ref()
.map(AnyArguments::convert_to)
Expand Down
6 changes: 4 additions & 2 deletions sqlx-postgres/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ impl AnyConnectionBackend for PgConnection {
fn fetch_many<'q>(
&'q mut self,
query: &'q str,
persistent: bool,
arguments: Option<AnyArguments<'q>>,
) -> BoxStream<'q, sqlx_core::Result<Either<AnyQueryResult, AnyRow>>> {
let persistent = arguments.is_some();
let persistent = persistent && arguments.is_some();
let arguments = match arguments.as_ref().map(AnyArguments::convert_to).transpose() {
Ok(arguments) => arguments,
Err(error) => {
Expand All @@ -99,9 +100,10 @@ impl AnyConnectionBackend for PgConnection {
fn fetch_optional<'q>(
&'q mut self,
query: &'q str,
persistent: bool,
arguments: Option<AnyArguments<'q>>,
) -> BoxFuture<'q, sqlx_core::Result<Option<AnyRow>>> {
let persistent = arguments.is_some();
let persistent = persistent && arguments.is_some();
let arguments = arguments
.as_ref()
.map(AnyArguments::convert_to)
Expand Down
6 changes: 4 additions & 2 deletions sqlx-sqlite/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ impl AnyConnectionBackend for SqliteConnection {
fn fetch_many<'q>(
&'q mut self,
query: &'q str,
persistent: bool,
arguments: Option<AnyArguments<'q>>,
) -> BoxStream<'q, sqlx_core::Result<Either<AnyQueryResult, AnyRow>>> {
let persistent = arguments.is_some();
let persistent = persistent && arguments.is_some();
let args = arguments.map(map_arguments);

Box::pin(
Expand All @@ -97,9 +98,10 @@ impl AnyConnectionBackend for SqliteConnection {
fn fetch_optional<'q>(
&'q mut self,
query: &'q str,
persistent: bool,
arguments: Option<AnyArguments<'q>>,
) -> BoxFuture<'q, sqlx_core::Result<Option<AnyRow>>> {
let persistent = arguments.is_some();
let persistent = persistent && arguments.is_some();
let args = arguments.map(map_arguments);

Box::pin(async move {
Expand Down

0 comments on commit 762b04d

Please sign in to comment.