1
1
use crate :: database:: Database ;
2
2
use crate :: describe:: Describe ;
3
3
use crate :: error:: { BoxDynError , Error } ;
4
+ use crate :: sql_str:: { SqlSafeStr , SqlStr } ;
4
5
5
6
use either:: Either ;
6
7
use futures_core:: future:: BoxFuture ;
@@ -146,9 +147,9 @@ pub trait Executor<'c>: Send + Debug + Sized {
146
147
/// This explicit API is provided to allow access to the statement metadata available after
147
148
/// it prepared but before the first row is returned.
148
149
#[ inline]
149
- fn prepare < ' e , ' q : ' e > (
150
+ fn prepare < ' e > (
150
151
self ,
151
- query : & ' q str ,
152
+ query : impl SqlSafeStr ,
152
153
) -> BoxFuture < ' e , Result < <Self :: Database as Database >:: Statement , Error > >
153
154
where
154
155
' c : ' e ,
@@ -161,9 +162,9 @@ pub trait Executor<'c>: Send + Debug + Sized {
161
162
///
162
163
/// Only some database drivers (PostgreSQL, MSSQL) can take advantage of
163
164
/// this extra information to influence parameter type inference.
164
- fn prepare_with < ' e , ' q : ' e > (
165
+ fn prepare_with < ' e > (
165
166
self ,
166
- sql : & ' q str ,
167
+ sql : impl SqlSafeStr ,
167
168
parameters : & ' e [ <Self :: Database as Database >:: TypeInfo ] ,
168
169
) -> BoxFuture < ' e , Result < <Self :: Database as Database >:: Statement , Error > >
169
170
where
@@ -175,9 +176,9 @@ pub trait Executor<'c>: Send + Debug + Sized {
175
176
/// This is used by compile-time verification in the query macros to
176
177
/// power their type inference.
177
178
#[ doc( hidden) ]
178
- fn describe < ' e , ' q : ' e > (
179
+ fn describe < ' e > (
179
180
self ,
180
- sql : & ' q str ,
181
+ sql : impl SqlSafeStr ,
181
182
) -> BoxFuture < ' e , Result < Describe < Self :: Database > , Error > >
182
183
where
183
184
' c : ' e ;
@@ -192,7 +193,7 @@ pub trait Executor<'c>: Send + Debug + Sized {
192
193
///
193
194
pub trait Execute < ' q , DB : Database > : Send + Sized {
194
195
/// Gets the SQL that will be executed.
195
- fn sql ( & self ) -> & ' q str ;
196
+ fn sql ( self ) -> SqlStr ;
196
197
197
198
/// Gets the previously cached statement, if available.
198
199
fn statement ( & self ) -> Option < & DB :: Statement > ;
@@ -210,12 +211,13 @@ pub trait Execute<'q, DB: Database>: Send + Sized {
210
211
fn persistent ( & self ) -> bool ;
211
212
}
212
213
213
- // NOTE: `Execute` is explicitly not implemented for String and &String to make it slightly more
214
- // involved to write `conn.execute(format!("SELECT {val}"))`
215
- impl < ' q , DB : Database > Execute < ' q , DB > for & ' q str {
214
+ impl < ' q , DB : Database , T > Execute < ' q , DB > for ( T , Option < <DB as Database >:: Arguments < ' q > > )
215
+ where
216
+ T : SqlSafeStr + Send ,
217
+ {
216
218
#[ inline]
217
- fn sql ( & self ) -> & ' q str {
218
- self
219
+ fn sql ( self ) -> SqlStr {
220
+ self . 0 . into_sql_str ( )
219
221
}
220
222
221
223
#[ inline]
@@ -225,7 +227,7 @@ impl<'q, DB: Database> Execute<'q, DB> for &'q str {
225
227
226
228
#[ inline]
227
229
fn take_arguments ( & mut self ) -> Result < Option < <DB as Database >:: Arguments < ' q > > , BoxDynError > {
228
- Ok ( None )
230
+ Ok ( self . 1 . take ( ) )
229
231
}
230
232
231
233
#[ inline]
@@ -234,10 +236,13 @@ impl<'q, DB: Database> Execute<'q, DB> for &'q str {
234
236
}
235
237
}
236
238
237
- impl < ' q , DB : Database > Execute < ' q , DB > for ( & ' q str , Option < <DB as Database >:: Arguments < ' q > > ) {
239
+ impl < ' q , DB : Database , T > Execute < ' q , DB > for T
240
+ where
241
+ T : SqlSafeStr + Send ,
242
+ {
238
243
#[ inline]
239
- fn sql ( & self ) -> & ' q str {
240
- self . 0
244
+ fn sql ( self ) -> SqlStr {
245
+ self . into_sql_str ( )
241
246
}
242
247
243
248
#[ inline]
@@ -247,7 +252,7 @@ impl<'q, DB: Database> Execute<'q, DB> for (&'q str, Option<<DB as Database>::Ar
247
252
248
253
#[ inline]
249
254
fn take_arguments ( & mut self ) -> Result < Option < <DB as Database >:: Arguments < ' q > > , BoxDynError > {
250
- Ok ( self . 1 . take ( ) )
255
+ Ok ( None )
251
256
}
252
257
253
258
#[ inline]
0 commit comments