Skip to content

Commit 91e3b40

Browse files
authored
Merge pull request #206 from readysettech/prep_as_query
Relax prep() to take impl AsQuery
2 parents 7a7fce5 + fd52ed2 commit 91e3b40

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

src/queryable/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub trait Queryable: Send {
135135
/// [stmt_cache_size]: crate::Opts::stmt_cache_size
136136
fn prep<'a, Q>(&'a mut self, query: Q) -> BoxFuture<'a, Statement>
137137
where
138-
Q: AsRef<str> + Sync + Send + 'a;
138+
Q: AsQuery + 'a;
139139

140140
/// Closes the given statement.
141141
///
@@ -464,9 +464,9 @@ impl Queryable for Conn {
464464

465465
fn prep<'a, Q>(&'a mut self, query: Q) -> BoxFuture<'a, Statement>
466466
where
467-
Q: AsRef<str> + Sync + Send + 'a,
467+
Q: AsQuery + 'a,
468468
{
469-
async move { self.get_statement(query.as_ref()).await }.boxed()
469+
async move { self.get_statement(query.as_query()).await }.boxed()
470470
}
471471

472472
fn close(&mut self, stmt: Statement) -> BoxFuture<'_, ()> {
@@ -533,7 +533,7 @@ impl Queryable for Transaction<'_> {
533533

534534
fn prep<'a, Q>(&'a mut self, query: Q) -> BoxFuture<'a, Statement>
535535
where
536-
Q: AsRef<str> + Sync + Send + 'a,
536+
Q: AsQuery + 'a,
537537
{
538538
self.0.prep(query)
539539
}

src/queryable/stmt.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,51 @@ impl StatementLike for Arc<str> {
101101
}
102102
}
103103

104+
impl StatementLike for Cow<'_, [u8]> {
105+
fn to_statement<'a>(self, conn: &'a mut crate::Conn) -> ToStatementResult<'a>
106+
where
107+
Self: 'a,
108+
{
109+
to_statement_move(self, conn)
110+
}
111+
}
112+
113+
impl StatementLike for &'_ [u8] {
114+
fn to_statement<'a>(self, conn: &'a mut crate::Conn) -> ToStatementResult<'a>
115+
where
116+
Self: 'a,
117+
{
118+
to_statement_move(self, conn)
119+
}
120+
}
121+
122+
impl StatementLike for Vec<u8> {
123+
fn to_statement<'a>(self, conn: &'a mut crate::Conn) -> ToStatementResult<'a>
124+
where
125+
Self: 'a,
126+
{
127+
to_statement_move(self, conn)
128+
}
129+
}
130+
131+
impl StatementLike for Box<[u8]> {
132+
fn to_statement<'a>(self, conn: &'a mut crate::Conn) -> ToStatementResult<'a>
133+
where
134+
Self: 'a,
135+
{
136+
to_statement_move(self, conn)
137+
}
138+
}
139+
140+
impl StatementLike for Arc<[u8]> {
141+
fn to_statement<'a>(self, conn: &'a mut crate::Conn) -> ToStatementResult<'a>
142+
where
143+
Self: 'a,
144+
{
145+
to_statement_move(self, conn)
146+
}
147+
}
148+
104149
impl StatementLike for Statement {
105150
fn to_statement<'a>(self, _conn: &'a mut crate::Conn) -> ToStatementResult<'static>
106151
where

0 commit comments

Comments
 (0)