diff --git a/sqlx-core/src/blocking/executor.rs b/sqlx-core/src/blocking/executor.rs index 823ab795..a2c50357 100644 --- a/sqlx-core/src/blocking/executor.rs +++ b/sqlx-core/src/blocking/executor.rs @@ -5,27 +5,89 @@ pub trait Executor: crate::Executor where Self::Database: Database, { - fn execute<'x, 'e, 'q>( + /// Execute the SQL query and return information about the result, including + /// the number of rows affected, if any. + fn execute<'x, 'e, 'q, 'a, E>( &'e mut self, - sql: &'q str, + query: E, ) -> crate::Result<::QueryResult> where + E: 'x + crate::Execute<'q, 'a, Self::Database>, 'e: 'x, - 'q: 'x; + 'q: 'x, + 'a: 'x; - fn fetch_all<'x, 'e, 'q>( + fn fetch_all<'x, 'e, 'q, 'a, E>( &'e mut self, - sql: &'q str, + query: E, ) -> crate::Result::Row>> where + E: 'x + crate::Execute<'q, 'a, Self::Database>, 'e: 'x, - 'q: 'x; + 'q: 'x, + 'a: 'x; - fn fetch_optional<'x, 'e, 'q>( + fn fetch_optional<'x, 'e, 'q, 'a, E>( &'e mut self, - sql: &'q str, + query: E, ) -> crate::Result::Row>> where + E: 'x + crate::Execute<'q, 'a, Self::Database>, 'e: 'x, - 'q: 'x; + 'q: 'x, + 'a: 'x; + + fn fetch_one<'x, 'e, 'q, 'a, E>( + &'e mut self, + query: E, + ) -> crate::Result<::Row> + where + E: 'x + crate::Execute<'q, 'a, Self::Database>, + 'e: 'x, + 'q: 'x, + 'a: 'x, + { + Executor::fetch_optional(self, query)?.ok_or(crate::Error::RowNotFound) + } +} + +impl> Executor for &'_ mut X { + fn execute<'x, 'e, 'q, 'a, E>( + &'e mut self, + query: E, + ) -> crate::Result<::QueryResult> + where + E: 'x + crate::Execute<'q, 'a, Self::Database>, + 'e: 'x, + 'q: 'x, + 'a: 'x, + { + Executor::execute(&mut **self, query) + } + + fn fetch_all<'x, 'e, 'q, 'a, E>( + &'e mut self, + query: E, + ) -> crate::Result::Row>> + where + E: 'x + crate::Execute<'q, 'a, Self::Database>, + 'e: 'x, + 'q: 'x, + 'a: 'x, + { + Executor::fetch_all(&mut **self, query) + } + + fn fetch_optional<'x, 'e, 'q, 'a, E>( + &'e mut self, + query: E, + ) -> crate::Result::Row>> + where + E: 'x + crate::Execute<'q, 'a, Self::Database>, + 'e: 'x, + 'q: 'x, + 'a: 'x, + { + Executor::fetch_optional(&mut **self, query) + } }