diff --git a/Cargo.lock b/Cargo.lock index f541f035b..5d3b9da86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1126,6 +1126,7 @@ dependencies = [ "bytes", "bytestring", "conquer-once", + "either", "futures-executor", "futures-io", "futures-util", diff --git a/sqlx-core/src/query_result.rs b/sqlx-core/src/query_result.rs index 2a487a555..2f1ed6291 100644 --- a/sqlx-core/src/query_result.rs +++ b/sqlx-core/src/query_result.rs @@ -4,7 +4,7 @@ use std::fmt::Debug; /// /// Returned from [`execute()`][crate::Executor::execute]. /// -pub trait QueryResult: 'static + Sized + Debug + Extend { +pub trait QueryResult: 'static + Sized + Debug + Clone + Default + Extend { /// Returns the number of rows changed, deleted, or inserted by the statement /// if it was an `UPDATE`, `DELETE` or `INSERT`. For `SELECT` statements, returns /// the number of rows returned. diff --git a/sqlx-mysql/src/protocol/info.rs b/sqlx-mysql/src/protocol/info.rs index 28d2f3507..75b8f7431 100644 --- a/sqlx-mysql/src/protocol/info.rs +++ b/sqlx-mysql/src/protocol/info.rs @@ -1,7 +1,7 @@ // https://dev.mysql.com/doc/c-api/8.0/en/mysql-info.html // https://mariadb.com/kb/en/mysql_info/ -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone, Copy)] pub(crate) struct Info { pub(crate) records: u64, pub(crate) duplicates: u64, diff --git a/sqlx-mysql/src/query_result.rs b/sqlx-mysql/src/query_result.rs index 2df67d331..8a0ed4c8a 100644 --- a/sqlx-mysql/src/query_result.rs +++ b/sqlx-mysql/src/query_result.rs @@ -4,7 +4,7 @@ use sqlx_core::QueryResult; use crate::protocol::{Info, OkPacket, Status}; -/// Represents the execution result of an operation in MySQL. +/// Represents the execution result of an operation on the database server. /// /// Returned from [`execute()`][sqlx_core::Executor::execute]. /// @@ -110,6 +110,18 @@ impl Debug for MySqlQueryResult { } } +impl Default for MySqlQueryResult { + fn default() -> Self { + Self(OkPacket { + affected_rows: 0, + last_insert_id: 0, + status: Status::empty(), + warnings: 0, + info: Info::default(), + }) + } +} + impl From for MySqlQueryResult { fn from(ok: OkPacket) -> Self { Self(ok) diff --git a/sqlx-postgres/src/query_result.rs b/sqlx-postgres/src/query_result.rs index 90b7837a9..0cd4b4c7c 100644 --- a/sqlx-postgres/src/query_result.rs +++ b/sqlx-postgres/src/query_result.rs @@ -14,7 +14,7 @@ use sqlx_core::QueryResult; /// Returned from [`execute()`][sqlx_core::Executor::execute]. /// #[allow(clippy::module_name_repetitions)] -#[derive(Clone)] +#[derive(Clone, Default)] pub struct PgQueryResult { command: ByteString, rows_affected: u64, @@ -38,6 +38,7 @@ impl PgQueryResult { /// /// This is usually a single word that identifies which SQL command /// was completed (e.g.,`INSERT`, `UPDATE`, or `MOVE`). + /// #[must_use] pub fn command(&self) -> &str { &self.command