Skip to content

Commit 15a1448

Browse files
Add persistent setter (#1503)
1 parent d25ab07 commit 15a1448

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

sqlx-core/src/query_as.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use futures_core::stream::BoxStream;
55
use futures_util::{StreamExt, TryStreamExt};
66

77
use crate::arguments::IntoArguments;
8-
use crate::database::{Database, HasArguments, HasStatement};
8+
use crate::database::{Database, HasArguments, HasStatement, HasStatementCache};
99
use crate::encode::Encode;
1010
use crate::error::Error;
1111
use crate::executor::{Execute, Executor};
@@ -57,6 +57,24 @@ impl<'q, DB: Database, O> QueryAs<'q, DB, O, <DB as HasArguments<'q>>::Arguments
5757
}
5858
}
5959

60+
impl<'q, DB, O, A> QueryAs<'q, DB, O, A>
61+
where
62+
DB: Database + HasStatementCache,
63+
{
64+
/// If `true`, the statement will get prepared once and cached to the
65+
/// connection's statement cache.
66+
///
67+
/// If queried once with the flag set to `true`, all subsequent queries
68+
/// matching the one with the flag will use the cached statement until the
69+
/// cache is cleared.
70+
///
71+
/// Default: `true`.
72+
pub fn persistent(mut self, value: bool) -> Self {
73+
self.inner = self.inner.persistent(value);
74+
self
75+
}
76+
}
77+
6078
// FIXME: This is very close, nearly 1:1 with `Map`
6179
// noinspection DuplicatedCode
6280
impl<'q, DB, O, A> QueryAs<'q, DB, O, A>

sqlx-core/src/query_scalar.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use futures_core::stream::BoxStream;
33
use futures_util::{StreamExt, TryFutureExt, TryStreamExt};
44

55
use crate::arguments::IntoArguments;
6-
use crate::database::{Database, HasArguments, HasStatement};
6+
use crate::database::{Database, HasArguments, HasStatement, HasStatementCache};
77
use crate::encode::Encode;
88
use crate::error::Error;
99
use crate::executor::{Execute, Executor};
@@ -54,6 +54,24 @@ impl<'q, DB: Database, O> QueryScalar<'q, DB, O, <DB as HasArguments<'q>>::Argum
5454
}
5555
}
5656

57+
impl<'q, DB, O, A> QueryScalar<'q, DB, O, A>
58+
where
59+
DB: Database + HasStatementCache,
60+
{
61+
/// If `true`, the statement will get prepared once and cached to the
62+
/// connection's statement cache.
63+
///
64+
/// If queried once with the flag set to `true`, all subsequent queries
65+
/// matching the one with the flag will use the cached statement until the
66+
/// cache is cleared.
67+
///
68+
/// Default: `true`.
69+
pub fn persistent(mut self, value: bool) -> Self {
70+
self.inner = self.inner.persistent(value);
71+
self
72+
}
73+
}
74+
5775
// FIXME: This is very close, nearly 1:1 with `Map`
5876
// noinspection DuplicatedCode
5977
impl<'q, DB, O, A> QueryScalar<'q, DB, O, A>

0 commit comments

Comments
 (0)