From 40cfd5ee6601614ac7c4e0a92c7e0afd75f4093d Mon Sep 17 00:00:00 2001 From: tison Date: Thu, 26 Dec 2024 23:38:49 +0800 Subject: [PATCH 1/2] fix: executor arg of RawSql methods can have looser bound Signed-off-by: tison --- sqlx-core/src/raw_sql.rs | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/sqlx-core/src/raw_sql.rs b/sqlx-core/src/raw_sql.rs index 37627d4453..22349428ac 100644 --- a/sqlx-core/src/raw_sql.rs +++ b/sqlx-core/src/raw_sql.rs @@ -139,26 +139,26 @@ impl<'q, DB: Database> Execute<'q, DB> for RawSql<'q> { impl<'q> RawSql<'q> { /// Execute the SQL string and return the total number of rows affected. #[inline] - pub async fn execute<'e, E>( + pub async fn execute<'c, E>( self, executor: E, ) -> crate::Result<::QueryResult> where - 'q: 'e, - E: Executor<'e>, + E: Executor<'c>, { executor.execute(self).await } /// Execute the SQL string. Returns a stream which gives the number of rows affected for each statement in the string. #[inline] - pub fn execute_many<'e, E>( + pub fn execute_many<'c, 'e, E>( self, executor: E, ) -> BoxStream<'e, crate::Result<::QueryResult>> where + 'c: 'e, 'q: 'e, - E: Executor<'e>, + E: Executor<'c>, { executor.execute_many(self) } @@ -167,13 +167,14 @@ impl<'q> RawSql<'q> { /// /// If the string contains multiple statements, their results will be concatenated together. #[inline] - pub fn fetch<'e, E>( + pub fn fetch<'c, 'e, E>( self, executor: E, ) -> BoxStream<'e, Result<::Row, Error>> where + 'c: 'e, 'q: 'e, - E: Executor<'e>, + E: Executor<'c>, { executor.fetch(self) } @@ -183,7 +184,7 @@ impl<'q> RawSql<'q> { /// For each query in the stream, any generated rows are returned first, /// then the `QueryResult` with the number of rows affected. #[inline] - pub fn fetch_many<'e, E>( + pub fn fetch_many<'c, 'e, E>( self, executor: E, ) -> BoxStream< @@ -194,8 +195,9 @@ impl<'q> RawSql<'q> { >, > where + 'c: 'e, 'q: 'e, - E: Executor<'e>, + E: Executor<'c>, { executor.fetch_many(self) } @@ -208,11 +210,12 @@ impl<'q> RawSql<'q> { /// To avoid exhausting available memory, ensure the result set has a known upper bound, /// e.g. using `LIMIT`. #[inline] - pub async fn fetch_all<'e, E>( + pub async fn fetch_all<'c, 'e, E>( self, executor: E, ) -> crate::Result::Row>> where + 'c: 'e, 'q: 'e, E: Executor<'e>, { @@ -232,13 +235,14 @@ impl<'q> RawSql<'q> { /// /// Otherwise, you might want to add `LIMIT 1` to your query. #[inline] - pub async fn fetch_one<'e, E>( + pub async fn fetch_one<'c, 'e, E>( self, executor: E, ) -> crate::Result<::Row> where + 'c: 'e, 'q: 'e, - E: Executor<'e>, + E: Executor<'c>, { executor.fetch_one(self).await } @@ -256,13 +260,14 @@ impl<'q> RawSql<'q> { /// /// Otherwise, you might want to add `LIMIT 1` to your query. #[inline] - pub async fn fetch_optional<'e, E>( + pub async fn fetch_optional<'c, 'e, E>( self, executor: E, ) -> crate::Result<::Row> where + 'c: 'e, 'q: 'e, - E: Executor<'e>, + E: Executor<'c>, { executor.fetch_one(self).await } From 9e75e1c1a84d80ba0c8bf9645c685611a86b084e Mon Sep 17 00:00:00 2001 From: tison Date: Fri, 27 Dec 2024 00:26:18 +0800 Subject: [PATCH 2/2] align query series Signed-off-by: tison --- sqlx-core/src/raw_sql.rs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/sqlx-core/src/raw_sql.rs b/sqlx-core/src/raw_sql.rs index 22349428ac..b64eeec0e4 100644 --- a/sqlx-core/src/raw_sql.rs +++ b/sqlx-core/src/raw_sql.rs @@ -139,11 +139,12 @@ impl<'q, DB: Database> Execute<'q, DB> for RawSql<'q> { impl<'q> RawSql<'q> { /// Execute the SQL string and return the total number of rows affected. #[inline] - pub async fn execute<'c, E>( + pub async fn execute<'e, 'c: 'e, E>( self, executor: E, ) -> crate::Result<::QueryResult> where + 'q: 'e, E: Executor<'c>, { executor.execute(self).await @@ -151,12 +152,11 @@ impl<'q> RawSql<'q> { /// Execute the SQL string. Returns a stream which gives the number of rows affected for each statement in the string. #[inline] - pub fn execute_many<'c, 'e, E>( + pub fn execute_many<'e, 'c: 'e, E>( self, executor: E, ) -> BoxStream<'e, crate::Result<::QueryResult>> where - 'c: 'e, 'q: 'e, E: Executor<'c>, { @@ -167,12 +167,11 @@ impl<'q> RawSql<'q> { /// /// If the string contains multiple statements, their results will be concatenated together. #[inline] - pub fn fetch<'c, 'e, E>( + pub fn fetch<'e, 'c: 'e, E>( self, executor: E, ) -> BoxStream<'e, Result<::Row, Error>> where - 'c: 'e, 'q: 'e, E: Executor<'c>, { @@ -184,7 +183,7 @@ impl<'q> RawSql<'q> { /// For each query in the stream, any generated rows are returned first, /// then the `QueryResult` with the number of rows affected. #[inline] - pub fn fetch_many<'c, 'e, E>( + pub fn fetch_many<'e, 'c: 'e, E>( self, executor: E, ) -> BoxStream< @@ -195,7 +194,6 @@ impl<'q> RawSql<'q> { >, > where - 'c: 'e, 'q: 'e, E: Executor<'c>, { @@ -210,12 +208,11 @@ impl<'q> RawSql<'q> { /// To avoid exhausting available memory, ensure the result set has a known upper bound, /// e.g. using `LIMIT`. #[inline] - pub async fn fetch_all<'c, 'e, E>( + pub async fn fetch_all<'e, 'c: 'e, E>( self, executor: E, ) -> crate::Result::Row>> where - 'c: 'e, 'q: 'e, E: Executor<'e>, { @@ -235,12 +232,11 @@ impl<'q> RawSql<'q> { /// /// Otherwise, you might want to add `LIMIT 1` to your query. #[inline] - pub async fn fetch_one<'c, 'e, E>( + pub async fn fetch_one<'e, 'c: 'e, E>( self, executor: E, ) -> crate::Result<::Row> where - 'c: 'e, 'q: 'e, E: Executor<'c>, { @@ -260,12 +256,11 @@ impl<'q> RawSql<'q> { /// /// Otherwise, you might want to add `LIMIT 1` to your query. #[inline] - pub async fn fetch_optional<'c, 'e, E>( + pub async fn fetch_optional<'e, 'c: 'e, E>( self, executor: E, ) -> crate::Result<::Row> where - 'c: 'e, 'q: 'e, E: Executor<'c>, {