Skip to content

Commit 8be655f

Browse files
Add persistent setter (launchbadge#1503)
1 parent 466d3f3 commit 8be655f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

sqlx-core/src/query_as.rs

+18
Original file line numberDiff line numberDiff line change
@@ -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.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

+18
Original file line numberDiff line numberDiff line change
@@ -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.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)