Skip to content

Commit cbe4fc5

Browse files
committed
Add SqlStr + remove Statement lifetime
1 parent 642d413 commit cbe4fc5

File tree

28 files changed

+97
-94
lines changed

28 files changed

+97
-94
lines changed

sqlx-core/src/any/connection/backend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub trait AnyConnectionBackend: std::any::Any + Debug + Send + 'static {
8585
&'c mut self,
8686
sql: &'q str,
8787
parameters: &[AnyTypeInfo],
88-
) -> BoxFuture<'c, crate::Result<AnyStatement<'q>>>;
88+
) -> BoxFuture<'c, crate::Result<AnyStatement>>;
8989

9090
fn describe<'q>(&'q mut self, sql: &'q str) -> BoxFuture<'q, crate::Result<Describe<Any>>>;
9191
}

sqlx-core/src/any/connection/executor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<'c> Executor<'c> for &'c mut AnyConnection {
4747
self,
4848
sql: &'q str,
4949
parameters: &[AnyTypeInfo],
50-
) -> BoxFuture<'e, Result<AnyStatement<'q>, Error>>
50+
) -> BoxFuture<'e, Result<AnyStatement, Error>>
5151
where
5252
'c: 'e,
5353
{

sqlx-core/src/any/database.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl Database for Any {
2828
type Arguments<'q> = AnyArguments<'q>;
2929
type ArgumentBuffer<'q> = AnyArgumentBuffer<'q>;
3030

31-
type Statement<'q> = AnyStatement<'q>;
31+
type Statement = AnyStatement;
3232

3333
const NAME: &'static str = "Any";
3434

sqlx-core/src/any/statement.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ use crate::column::ColumnIndex;
33
use crate::database::Database;
44
use crate::error::Error;
55
use crate::ext::ustr::UStr;
6+
use crate::sql_str::{AssertSqlSafe, SqlSafeStr, SqlStr};
67
use crate::statement::Statement;
78
use crate::HashMap;
89
use either::Either;
9-
use std::borrow::Cow;
1010
use std::sync::Arc;
1111

12-
pub struct AnyStatement<'q> {
12+
pub struct AnyStatement {
1313
#[doc(hidden)]
14-
pub sql: Cow<'q, str>,
14+
pub sql: SqlStr,
1515
#[doc(hidden)]
1616
pub parameters: Option<Either<Vec<AnyTypeInfo>, usize>>,
1717
#[doc(hidden)]
@@ -20,20 +20,20 @@ pub struct AnyStatement<'q> {
2020
pub columns: Vec<AnyColumn>,
2121
}
2222

23-
impl<'q> Statement<'q> for AnyStatement<'q> {
23+
impl Statement for AnyStatement {
2424
type Database = Any;
2525

26-
fn to_owned(&self) -> AnyStatement<'static> {
27-
AnyStatement::<'static> {
28-
sql: Cow::Owned(self.sql.clone().into_owned()),
26+
fn to_owned(&self) -> AnyStatement {
27+
AnyStatement {
28+
sql: self.sql.clone(),
2929
column_names: self.column_names.clone(),
3030
parameters: self.parameters.clone(),
3131
columns: self.columns.clone(),
3232
}
3333
}
3434

3535
fn sql(&self) -> &str {
36-
&self.sql
36+
&self.sql.as_str()
3737
}
3838

3939
fn parameters(&self) -> Option<Either<&[AnyTypeInfo], usize>> {
@@ -51,8 +51,8 @@ impl<'q> Statement<'q> for AnyStatement<'q> {
5151
impl_statement_query!(AnyArguments<'_>);
5252
}
5353

54-
impl<'i> ColumnIndex<AnyStatement<'_>> for &'i str {
55-
fn index(&self, statement: &AnyStatement<'_>) -> Result<usize, Error> {
54+
impl<'i> ColumnIndex<AnyStatement> for &'i str {
55+
fn index(&self, statement: &AnyStatement) -> Result<usize, Error> {
5656
statement
5757
.column_names
5858
.get(*self)
@@ -61,15 +61,15 @@ impl<'i> ColumnIndex<AnyStatement<'_>> for &'i str {
6161
}
6262
}
6363

64-
impl<'q> AnyStatement<'q> {
64+
impl<'q> AnyStatement {
6565
#[doc(hidden)]
6666
pub fn try_from_statement<S>(
6767
query: &'q str,
6868
statement: &S,
6969
column_names: Arc<HashMap<UStr, usize>>,
7070
) -> crate::Result<Self>
7171
where
72-
S: Statement<'q>,
72+
S: Statement,
7373
AnyTypeInfo: for<'a> TryFrom<&'a <S::Database as Database>::TypeInfo, Error = Error>,
7474
AnyColumn: for<'a> TryFrom<&'a <S::Database as Database>::Column, Error = Error>,
7575
{
@@ -91,7 +91,7 @@ impl<'q> AnyStatement<'q> {
9191
.collect::<Result<Vec<_>, _>>()?;
9292

9393
Ok(Self {
94-
sql: query.into(),
94+
sql: AssertSqlSafe(query).into_sql_str(),
9595
columns,
9696
column_names,
9797
parameters,

sqlx-core/src/column.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ macro_rules! impl_column_index_for_row {
6969
#[macro_export]
7070
macro_rules! impl_column_index_for_statement {
7171
($S:ident) => {
72-
impl $crate::column::ColumnIndex<$S<'_>> for usize {
73-
fn index(&self, statement: &$S<'_>) -> Result<usize, $crate::error::Error> {
72+
impl $crate::column::ColumnIndex<$S> for usize {
73+
fn index(&self, statement: &$S) -> Result<usize, $crate::error::Error> {
7474
let len = $crate::statement::Statement::columns(statement).len();
7575

7676
if *self >= len {

sqlx-core/src/database.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub trait Database: 'static + Sized + Send + Debug {
101101
type ArgumentBuffer<'q>;
102102

103103
/// The concrete `Statement` implementation for this database.
104-
type Statement<'q>: Statement<'q, Database = Self>;
104+
type Statement: Statement<Database = Self>;
105105

106106
/// The display name for this database driver.
107107
const NAME: &'static str;

sqlx-core/src/executor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pub trait Executor<'c>: Send + Debug + Sized {
149149
fn prepare<'e, 'q: 'e>(
150150
self,
151151
query: &'q str,
152-
) -> BoxFuture<'e, Result<<Self::Database as Database>::Statement<'q>, Error>>
152+
) -> BoxFuture<'e, Result<<Self::Database as Database>::Statement, Error>>
153153
where
154154
'c: 'e,
155155
{
@@ -165,7 +165,7 @@ pub trait Executor<'c>: Send + Debug + Sized {
165165
self,
166166
sql: &'q str,
167167
parameters: &'e [<Self::Database as Database>::TypeInfo],
168-
) -> BoxFuture<'e, Result<<Self::Database as Database>::Statement<'q>, Error>>
168+
) -> BoxFuture<'e, Result<<Self::Database as Database>::Statement, Error>>
169169
where
170170
'c: 'e;
171171

@@ -195,7 +195,7 @@ pub trait Execute<'q, DB: Database>: Send + Sized {
195195
fn sql(&self) -> &'q str;
196196

197197
/// Gets the previously cached statement, if available.
198-
fn statement(&self) -> Option<&DB::Statement<'q>>;
198+
fn statement(&self) -> Option<&DB::Statement>;
199199

200200
/// Returns the arguments to be bound against the query string.
201201
///
@@ -219,7 +219,7 @@ impl<'q, DB: Database> Execute<'q, DB> for &'q str {
219219
}
220220

221221
#[inline]
222-
fn statement(&self) -> Option<&DB::Statement<'q>> {
222+
fn statement(&self) -> Option<&DB::Statement> {
223223
None
224224
}
225225

@@ -241,7 +241,7 @@ impl<'q, DB: Database> Execute<'q, DB> for (&'q str, Option<<DB as Database>::Ar
241241
}
242242

243243
#[inline]
244-
fn statement(&self) -> Option<&DB::Statement<'q>> {
244+
fn statement(&self) -> Option<&DB::Statement> {
245245
None
246246
}
247247

sqlx-core/src/pool/executor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ where
5252
self,
5353
sql: &'q str,
5454
parameters: &'e [<Self::Database as Database>::TypeInfo],
55-
) -> BoxFuture<'e, Result<<Self::Database as Database>::Statement<'q>, Error>> {
55+
) -> BoxFuture<'e, Result<<Self::Database as Database>::Statement, Error>> {
5656
let pool = self.clone();
5757

5858
Box::pin(async move { pool.acquire().await?.prepare_with(sql, parameters).await })

sqlx-core/src/query.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::types::Type;
1515
/// A single SQL query as a prepared statement. Returned by [`query()`].
1616
#[must_use = "query must be executed to affect database"]
1717
pub struct Query<'q, DB: Database, A> {
18-
pub(crate) statement: Either<&'q str, &'q DB::Statement<'q>>,
18+
pub(crate) statement: Either<&'q str, &'q DB::Statement>,
1919
pub(crate) arguments: Option<Result<A, BoxDynError>>,
2020
pub(crate) database: PhantomData<DB>,
2121
pub(crate) persistent: bool,
@@ -51,7 +51,7 @@ where
5151
}
5252
}
5353

54-
fn statement(&self) -> Option<&DB::Statement<'q>> {
54+
fn statement(&self) -> Option<&DB::Statement> {
5555
match self.statement {
5656
Either::Right(statement) => Some(statement),
5757
Either::Left(_) => None,
@@ -308,7 +308,7 @@ where
308308
}
309309

310310
#[inline]
311-
fn statement(&self) -> Option<&DB::Statement<'q>> {
311+
fn statement(&self) -> Option<&DB::Statement> {
312312
self.inner.statement()
313313
}
314314

@@ -498,7 +498,7 @@ where
498498

499499
/// Execute a single SQL query as a prepared statement (explicitly created).
500500
pub fn query_statement<'q, DB>(
501-
statement: &'q DB::Statement<'q>,
501+
statement: &'q DB::Statement,
502502
) -> Query<'q, DB, <DB as Database>::Arguments<'_>>
503503
where
504504
DB: Database,
@@ -513,7 +513,7 @@ where
513513

514514
/// Execute a single SQL query as a prepared statement (explicitly created), with the given arguments.
515515
pub fn query_statement_with<'q, DB, A>(
516-
statement: &'q DB::Statement<'q>,
516+
statement: &'q DB::Statement,
517517
arguments: A,
518518
) -> Query<'q, DB, A>
519519
where

sqlx-core/src/query_as.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ where
3232
}
3333

3434
#[inline]
35-
fn statement(&self) -> Option<&DB::Statement<'q>> {
35+
fn statement(&self) -> Option<&DB::Statement> {
3636
self.inner.statement()
3737
}
3838

@@ -385,7 +385,7 @@ where
385385

386386
// Make a SQL query from a statement, that is mapped to a concrete type.
387387
pub fn query_statement_as<'q, DB, O>(
388-
statement: &'q DB::Statement<'q>,
388+
statement: &'q DB::Statement,
389389
) -> QueryAs<'q, DB, O, <DB as Database>::Arguments<'_>>
390390
where
391391
DB: Database,
@@ -399,7 +399,7 @@ where
399399

400400
// Make a SQL query from a statement, with the given arguments, that is mapped to a concrete type.
401401
pub fn query_statement_as_with<'q, DB, O, A>(
402-
statement: &'q DB::Statement<'q>,
402+
statement: &'q DB::Statement,
403403
arguments: A,
404404
) -> QueryAs<'q, DB, O, A>
405405
where

0 commit comments

Comments
 (0)