From d5e0f1b92b492b707ca8adb8ccd2e3cf1c53c1fd Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Wed, 20 Jan 2021 21:57:26 -0800 Subject: [PATCH] refactor: rename DbOutcome to DbQueryResult --- CHANGELOG.md | 4 ++-- sqlx-core/src/any/connection/executor.rs | 4 ++-- sqlx-core/src/any/database.rs | 4 ++-- sqlx-core/src/any/mod.rs | 4 ++-- sqlx-core/src/any/{outcome.rs => query_result.rs} | 8 ++++---- sqlx-core/src/database.rs | 4 ++-- sqlx-core/src/executor.rs | 6 +++--- sqlx-core/src/mssql/connection/executor.rs | 8 ++++---- sqlx-core/src/mssql/database.rs | 4 ++-- sqlx-core/src/mssql/mod.rs | 4 ++-- .../{postgres/outcome.rs => mssql/query_result.rs} | 14 +++++++------- sqlx-core/src/mysql/connection/executor.rs | 10 +++++----- sqlx-core/src/mysql/database.rs | 4 ++-- sqlx-core/src/mysql/mod.rs | 4 ++-- .../src/mysql/{outcome.rs => query_result.rs} | 14 +++++++------- sqlx-core/src/pool/executor.rs | 4 ++-- sqlx-core/src/postgres/connection/executor.rs | 8 ++++---- sqlx-core/src/postgres/database.rs | 4 ++-- sqlx-core/src/postgres/listener.rs | 4 ++-- sqlx-core/src/postgres/mod.rs | 4 ++-- .../{mssql/outcome.rs => postgres/query_result.rs} | 14 +++++++------- sqlx-core/src/query.rs | 8 ++++---- sqlx-core/src/query_as.rs | 2 +- sqlx-core/src/query_scalar.rs | 2 +- sqlx-core/src/sqlite/connection/executor.rs | 6 +++--- sqlx-core/src/sqlite/database.rs | 4 ++-- sqlx-core/src/sqlite/mod.rs | 4 ++-- .../src/sqlite/{outcome.rs => query_result.rs} | 14 +++++++------- sqlx-core/src/transaction.rs | 2 +- src/macros.rs | 2 +- 30 files changed, 89 insertions(+), 89 deletions(-) rename sqlx-core/src/any/{outcome.rs => query_result.rs} (72%) rename sqlx-core/src/{postgres/outcome.rs => mssql/query_result.rs} (55%) rename sqlx-core/src/mysql/{outcome.rs => query_result.rs} (64%) rename sqlx-core/src/{mssql/outcome.rs => postgres/query_result.rs} (56%) rename sqlx-core/src/sqlite/{outcome.rs => query_result.rs} (63%) diff --git a/CHANGELOG.md b/CHANGELOG.md index f534ef45..6e6f5a99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,10 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [[#940]] Rename the `#[sqlx(rename)]` attribute used to specify the type name on the database side to `#[sqlx(type_name)]` [[@jplatte]]. -- [[#976]] Rename the `DbDone` types to `DbOutcome`. [[@jplatte]] +- [[#976]] Rename the `DbDone` types to `DbQueryResult`. [[@jplatte]] - [[#976]] Remove the `Done` trait. The `.rows_affected()` method is now available as an inherent - method on `PgOutcome`, `MySqlOutcome` and so on. [[@jplatte]] + method on `PgQueryResult`, `MySqlQueryResult` and so on. [[@jplatte]] - [[#983]] Upgrade async runtime dependencies [[@seryl, @ant32, @jplatte]] diff --git a/sqlx-core/src/any/connection/executor.rs b/sqlx-core/src/any/connection/executor.rs index 81d09a60..04c7280c 100644 --- a/sqlx-core/src/any/connection/executor.rs +++ b/sqlx-core/src/any/connection/executor.rs @@ -1,5 +1,5 @@ use crate::any::connection::AnyConnectionKind; -use crate::any::{Any, AnyColumn, AnyConnection, AnyOutcome, AnyRow, AnyStatement, AnyTypeInfo}; +use crate::any::{Any, AnyColumn, AnyConnection, AnyQueryResult, AnyRow, AnyStatement, AnyTypeInfo}; use crate::database::Database; use crate::describe::Describe; use crate::error::Error; @@ -15,7 +15,7 @@ impl<'c> Executor<'c> for &'c mut AnyConnection { fn fetch_many<'e, 'q: 'e, E: 'q>( self, mut query: E, - ) -> BoxStream<'e, Result, Error>> + ) -> BoxStream<'e, Result, Error>> where 'c: 'e, E: Execute<'q, Self::Database>, diff --git a/sqlx-core/src/any/database.rs b/sqlx-core/src/any/database.rs index 15b06a22..fa511be0 100644 --- a/sqlx-core/src/any/database.rs +++ b/sqlx-core/src/any/database.rs @@ -1,5 +1,5 @@ use crate::any::{ - AnyArgumentBuffer, AnyArguments, AnyColumn, AnyConnection, AnyOutcome, AnyRow, AnyStatement, + AnyArgumentBuffer, AnyArguments, AnyColumn, AnyConnection, AnyQueryResult, AnyRow, AnyStatement, AnyTransactionManager, AnyTypeInfo, AnyValue, AnyValueRef, }; use crate::database::{Database, HasArguments, HasStatement, HasStatementCache, HasValueRef}; @@ -16,7 +16,7 @@ impl Database for Any { type Row = AnyRow; - type Outcome = AnyOutcome; + type QueryResult = AnyQueryResult; type Column = AnyColumn; diff --git a/sqlx-core/src/any/mod.rs b/sqlx-core/src/any/mod.rs index 1f5f8b41..be6ea90c 100644 --- a/sqlx-core/src/any/mod.rs +++ b/sqlx-core/src/any/mod.rs @@ -15,7 +15,7 @@ mod connection; mod database; mod kind; mod options; -mod outcome; +mod query_result; pub(crate) mod row; mod statement; mod transaction; @@ -34,7 +34,7 @@ pub use decode::AnyDecode; pub use encode::AnyEncode; pub use kind::AnyKind; pub use options::AnyConnectOptions; -pub use outcome::AnyOutcome; +pub use query_result::AnyQueryResult; pub use r#type::AnyType; pub use row::AnyRow; pub use statement::AnyStatement; diff --git a/sqlx-core/src/any/outcome.rs b/sqlx-core/src/any/query_result.rs similarity index 72% rename from sqlx-core/src/any/outcome.rs rename to sqlx-core/src/any/query_result.rs index 97deadd9..b101fbf8 100644 --- a/sqlx-core/src/any/outcome.rs +++ b/sqlx-core/src/any/query_result.rs @@ -1,12 +1,12 @@ use std::iter::{Extend, IntoIterator}; #[derive(Debug, Default)] -pub struct AnyOutcome { +pub struct AnyQueryResult { pub(crate) rows_affected: u64, pub(crate) last_insert_id: Option, } -impl AnyOutcome { +impl AnyQueryResult { pub fn rows_affected(&self) -> u64 { self.rows_affected } @@ -16,8 +16,8 @@ impl AnyOutcome { } } -impl Extend for AnyOutcome { - fn extend>(&mut self, iter: T) { +impl Extend for AnyQueryResult { + fn extend>(&mut self, iter: T) { for elem in iter { self.rows_affected += elem.rows_affected; self.last_insert_id = elem.last_insert_id; diff --git a/sqlx-core/src/database.rs b/sqlx-core/src/database.rs index e8625785..e1788597 100644 --- a/sqlx-core/src/database.rs +++ b/sqlx-core/src/database.rs @@ -86,8 +86,8 @@ pub trait Database: /// The concrete `Row` implementation for this database. type Row: Row; - /// The concrete `Outcome` implementation for this database. - type Outcome: 'static + Sized + Send + Sync + Default + Extend; + /// The concrete `QueryResult` implementation for this database. + type QueryResult: 'static + Sized + Send + Sync + Default + Extend; /// The concrete `Column` implementation for this database. type Column: Column; diff --git a/sqlx-core/src/executor.rs b/sqlx-core/src/executor.rs index fc907b86..2b0e27c2 100644 --- a/sqlx-core/src/executor.rs +++ b/sqlx-core/src/executor.rs @@ -29,7 +29,7 @@ pub trait Executor<'c>: Send + Debug + Sized { fn execute<'e, 'q: 'e, E: 'q>( self, query: E, - ) -> BoxFuture<'e, Result<::Outcome, Error>> + ) -> BoxFuture<'e, Result<::QueryResult, Error>> where 'c: 'e, E: Execute<'q, Self::Database>, @@ -41,7 +41,7 @@ pub trait Executor<'c>: Send + Debug + Sized { fn execute_many<'e, 'q: 'e, E: 'q>( self, query: E, - ) -> BoxStream<'e, Result<::Outcome, Error>> + ) -> BoxStream<'e, Result<::QueryResult, Error>> where 'c: 'e, E: Execute<'q, Self::Database>, @@ -83,7 +83,7 @@ pub trait Executor<'c>: Send + Debug + Sized { ) -> BoxStream< 'e, Result< - Either<::Outcome, ::Row>, + Either<::QueryResult, ::Row>, Error, >, > diff --git a/sqlx-core/src/mssql/connection/executor.rs b/sqlx-core/src/mssql/connection/executor.rs index 04213e2c..37c6f0c3 100644 --- a/sqlx-core/src/mssql/connection/executor.rs +++ b/sqlx-core/src/mssql/connection/executor.rs @@ -10,7 +10,7 @@ use crate::mssql::protocol::packet::PacketType; use crate::mssql::protocol::rpc::{OptionFlags, Procedure, RpcRequest}; use crate::mssql::protocol::sql_batch::SqlBatch; use crate::mssql::{ - Mssql, MssqlArguments, MssqlConnection, MssqlOutcome, MssqlRow, MssqlStatement, MssqlTypeInfo, + Mssql, MssqlArguments, MssqlConnection, MssqlQueryResult, MssqlRow, MssqlStatement, MssqlTypeInfo, }; use either::Either; use futures_core::future::BoxFuture; @@ -71,7 +71,7 @@ impl<'c> Executor<'c> for &'c mut MssqlConnection { fn fetch_many<'e, 'q: 'e, E: 'q>( self, mut query: E, - ) -> BoxStream<'e, Result, Error>> + ) -> BoxStream<'e, Result, Error>> where 'c: 'e, E: Execute<'q, Self::Database>, @@ -102,7 +102,7 @@ impl<'c> Executor<'c> for &'c mut MssqlConnection { } if done.status.contains(Status::DONE_COUNT) { - r#yield!(Either::Left(MssqlOutcome { + r#yield!(Either::Left(MssqlQueryResult { rows_affected: done.affected_rows, })); } @@ -114,7 +114,7 @@ impl<'c> Executor<'c> for &'c mut MssqlConnection { Message::DoneInProc(done) => { if done.status.contains(Status::DONE_COUNT) { - r#yield!(Either::Left(MssqlOutcome { + r#yield!(Either::Left(MssqlQueryResult { rows_affected: done.affected_rows, })); } diff --git a/sqlx-core/src/mssql/database.rs b/sqlx-core/src/mssql/database.rs index f85eabf4..addc4163 100644 --- a/sqlx-core/src/mssql/database.rs +++ b/sqlx-core/src/mssql/database.rs @@ -1,6 +1,6 @@ use crate::database::{Database, HasArguments, HasStatement, HasValueRef}; use crate::mssql::{ - MssqlArguments, MssqlColumn, MssqlConnection, MssqlOutcome, MssqlRow, MssqlStatement, + MssqlArguments, MssqlColumn, MssqlConnection, MssqlQueryResult, MssqlRow, MssqlStatement, MssqlTransactionManager, MssqlTypeInfo, MssqlValue, MssqlValueRef, }; @@ -15,7 +15,7 @@ impl Database for Mssql { type Row = MssqlRow; - type Outcome = MssqlOutcome; + type QueryResult = MssqlQueryResult; type Column = MssqlColumn; diff --git a/sqlx-core/src/mssql/mod.rs b/sqlx-core/src/mssql/mod.rs index 1f32a04c..186e8fee 100644 --- a/sqlx-core/src/mssql/mod.rs +++ b/sqlx-core/src/mssql/mod.rs @@ -7,7 +7,7 @@ mod database; mod error; mod io; mod options; -mod outcome; +mod query_result; mod protocol; mod row; mod statement; @@ -22,7 +22,7 @@ pub use connection::MssqlConnection; pub use database::Mssql; pub use error::MssqlDatabaseError; pub use options::MssqlConnectOptions; -pub use outcome::MssqlOutcome; +pub use query_result::MssqlQueryResult; pub use row::MssqlRow; pub use statement::MssqlStatement; pub use transaction::MssqlTransactionManager; diff --git a/sqlx-core/src/postgres/outcome.rs b/sqlx-core/src/mssql/query_result.rs similarity index 55% rename from sqlx-core/src/postgres/outcome.rs rename to sqlx-core/src/mssql/query_result.rs index c8177d5b..2e31b4a8 100644 --- a/sqlx-core/src/postgres/outcome.rs +++ b/sqlx-core/src/mssql/query_result.rs @@ -1,18 +1,18 @@ use std::iter::{Extend, IntoIterator}; #[derive(Debug, Default)] -pub struct PgOutcome { +pub struct MssqlQueryResult { pub(super) rows_affected: u64, } -impl PgOutcome { +impl MssqlQueryResult { pub fn rows_affected(&self) -> u64 { self.rows_affected } } -impl Extend for PgOutcome { - fn extend>(&mut self, iter: T) { +impl Extend for MssqlQueryResult { + fn extend>(&mut self, iter: T) { for elem in iter { self.rows_affected += elem.rows_affected; } @@ -20,9 +20,9 @@ impl Extend for PgOutcome { } #[cfg(feature = "any")] -impl From for crate::any::AnyOutcome { - fn from(done: PgOutcome) -> Self { - crate::any::AnyOutcome { +impl From for crate::any::AnyQueryResult { + fn from(done: MssqlQueryResult) -> Self { + crate::any::AnyQueryResult { rows_affected: done.rows_affected, last_insert_id: None, } diff --git a/sqlx-core/src/mysql/connection/executor.rs b/sqlx-core/src/mysql/connection/executor.rs index a981a464..b7767f6d 100644 --- a/sqlx-core/src/mysql/connection/executor.rs +++ b/sqlx-core/src/mysql/connection/executor.rs @@ -13,7 +13,7 @@ use crate::mysql::protocol::statement::{ use crate::mysql::protocol::text::{ColumnDefinition, ColumnFlags, Query, TextRow}; use crate::mysql::statement::{MySqlStatement, MySqlStatementMetadata}; use crate::mysql::{ - MySql, MySqlArguments, MySqlColumn, MySqlConnection, MySqlOutcome, MySqlRow, MySqlTypeInfo, + MySql, MySqlArguments, MySqlColumn, MySqlConnection, MySqlQueryResult, MySqlRow, MySqlTypeInfo, MySqlValueFormat, }; use crate::HashMap; @@ -88,7 +88,7 @@ impl MySqlConnection { sql: &'q str, arguments: Option, persistent: bool, - ) -> Result, Error>> + 'e, Error> { + ) -> Result, Error>> + 'e, Error> { let mut logger = QueryLogger::new(sql, self.log_settings.clone()); self.stream.wait_until_ready().await?; @@ -133,7 +133,7 @@ impl MySqlConnection { // this indicates either a successful query with no rows at all or a failed query let ok = packet.ok()?; - let done = MySqlOutcome { + let done = MySqlQueryResult { rows_affected: ok.affected_rows, last_insert_id: ok.last_insert_id, }; @@ -171,7 +171,7 @@ impl MySqlConnection { if packet[0] == 0xfe && packet.len() < 9 { let eof = packet.eof(self.stream.capabilities)?; - r#yield!(Either::Left(MySqlOutcome { + r#yield!(Either::Left(MySqlQueryResult { rows_affected: 0, last_insert_id: 0, })); @@ -213,7 +213,7 @@ impl<'c> Executor<'c> for &'c mut MySqlConnection { fn fetch_many<'e, 'q: 'e, E: 'q>( self, mut query: E, - ) -> BoxStream<'e, Result, Error>> + ) -> BoxStream<'e, Result, Error>> where 'c: 'e, E: Execute<'q, Self::Database>, diff --git a/sqlx-core/src/mysql/database.rs b/sqlx-core/src/mysql/database.rs index 30fd4dfa..8e70ce53 100644 --- a/sqlx-core/src/mysql/database.rs +++ b/sqlx-core/src/mysql/database.rs @@ -1,7 +1,7 @@ use crate::database::{Database, HasArguments, HasStatement, HasStatementCache, HasValueRef}; use crate::mysql::value::{MySqlValue, MySqlValueRef}; use crate::mysql::{ - MySqlArguments, MySqlColumn, MySqlConnection, MySqlOutcome, MySqlRow, MySqlStatement, + MySqlArguments, MySqlColumn, MySqlConnection, MySqlQueryResult, MySqlRow, MySqlStatement, MySqlTransactionManager, MySqlTypeInfo, }; @@ -16,7 +16,7 @@ impl Database for MySql { type Row = MySqlRow; - type Outcome = MySqlOutcome; + type QueryResult = MySqlQueryResult; type Column = MySqlColumn; diff --git a/sqlx-core/src/mysql/mod.rs b/sqlx-core/src/mysql/mod.rs index 9bbf5377..3f8ea4ce 100644 --- a/sqlx-core/src/mysql/mod.rs +++ b/sqlx-core/src/mysql/mod.rs @@ -8,7 +8,7 @@ mod database; mod error; mod io; mod options; -mod outcome; +mod query_result; mod protocol; mod row; mod statement; @@ -26,7 +26,7 @@ pub use connection::MySqlConnection; pub use database::MySql; pub use error::MySqlDatabaseError; pub use options::{MySqlConnectOptions, MySqlSslMode}; -pub use outcome::MySqlOutcome; +pub use query_result::MySqlQueryResult; pub use row::MySqlRow; pub use statement::MySqlStatement; pub use transaction::MySqlTransactionManager; diff --git a/sqlx-core/src/mysql/outcome.rs b/sqlx-core/src/mysql/query_result.rs similarity index 64% rename from sqlx-core/src/mysql/outcome.rs rename to sqlx-core/src/mysql/query_result.rs index 7267f98d..41dcdbc1 100644 --- a/sqlx-core/src/mysql/outcome.rs +++ b/sqlx-core/src/mysql/query_result.rs @@ -1,12 +1,12 @@ use std::iter::{Extend, IntoIterator}; #[derive(Debug, Default)] -pub struct MySqlOutcome { +pub struct MySqlQueryResult { pub(super) rows_affected: u64, pub(super) last_insert_id: u64, } -impl MySqlOutcome { +impl MySqlQueryResult { pub fn last_insert_id(&self) -> u64 { self.last_insert_id } @@ -16,8 +16,8 @@ impl MySqlOutcome { } } -impl Extend for MySqlOutcome { - fn extend>(&mut self, iter: T) { +impl Extend for MySqlQueryResult { + fn extend>(&mut self, iter: T) { for elem in iter { self.rows_affected += elem.rows_affected; self.last_insert_id = elem.last_insert_id; @@ -26,9 +26,9 @@ impl Extend for MySqlOutcome { } #[cfg(feature = "any")] -impl From for crate::any::AnyOutcome { - fn from(done: MySqlOutcome) -> Self { - crate::any::AnyOutcome { +impl From for crate::any::AnyQueryResult { + fn from(done: MySqlQueryResult) -> Self { + crate::any::AnyQueryResult { rows_affected: done.rows_affected, last_insert_id: Some(done.last_insert_id as i64), } diff --git a/sqlx-core/src/pool/executor.rs b/sqlx-core/src/pool/executor.rs index d8d47964..97c8905b 100644 --- a/sqlx-core/src/pool/executor.rs +++ b/sqlx-core/src/pool/executor.rs @@ -18,7 +18,7 @@ where fn fetch_many<'e, 'q: 'e, E: 'q>( self, query: E, - ) -> BoxStream<'e, Result, Error>> + ) -> BoxStream<'e, Result, Error>> where E: Execute<'q, Self::Database>, { @@ -83,7 +83,7 @@ macro_rules! impl_executor_for_pool_connection { ) -> futures_core::stream::BoxStream< 'e, Result< - either::Either<<$DB as crate::database::Database>::Outcome, $R>, + either::Either<<$DB as crate::database::Database>::QueryResult, $R>, crate::error::Error, >, > diff --git a/sqlx-core/src/postgres/connection/executor.rs b/sqlx-core/src/postgres/connection/executor.rs index d8e61635..0e2a01f3 100644 --- a/sqlx-core/src/postgres/connection/executor.rs +++ b/sqlx-core/src/postgres/connection/executor.rs @@ -9,7 +9,7 @@ use crate::postgres::message::{ use crate::postgres::statement::PgStatementMetadata; use crate::postgres::type_info::PgType; use crate::postgres::{ - statement::PgStatement, PgArguments, PgConnection, PgOutcome, PgRow, PgTypeInfo, PgValueFormat, + statement::PgStatement, PgArguments, PgConnection, PgQueryResult, PgRow, PgTypeInfo, PgValueFormat, Postgres, }; use either::Either; @@ -198,7 +198,7 @@ impl PgConnection { limit: u8, persistent: bool, metadata_opt: Option>, - ) -> Result, Error>> + 'e, Error> { + ) -> Result, Error>> + 'e, Error> { let mut logger = QueryLogger::new(query, self.log_settings.clone()); // before we continue, wait until we are "ready" to accept more queries @@ -274,7 +274,7 @@ impl PgConnection { // a SQL command completed normally let cc: CommandComplete = message.decode()?; - r#yield!(Either::Left(PgOutcome { + r#yield!(Either::Left(PgQueryResult { rows_affected: cc.rows_affected(), })); } @@ -336,7 +336,7 @@ impl<'c> Executor<'c> for &'c mut PgConnection { fn fetch_many<'e, 'q: 'e, E: 'q>( self, mut query: E, - ) -> BoxStream<'e, Result, Error>> + ) -> BoxStream<'e, Result, Error>> where 'c: 'e, E: Execute<'q, Self::Database>, diff --git a/sqlx-core/src/postgres/database.rs b/sqlx-core/src/postgres/database.rs index 4c4595a2..192d5a64 100644 --- a/sqlx-core/src/postgres/database.rs +++ b/sqlx-core/src/postgres/database.rs @@ -2,7 +2,7 @@ use crate::database::{Database, HasArguments, HasStatement, HasStatementCache, H use crate::postgres::arguments::PgArgumentBuffer; use crate::postgres::value::{PgValue, PgValueRef}; use crate::postgres::{ - PgArguments, PgColumn, PgConnection, PgOutcome, PgRow, PgStatement, PgTransactionManager, + PgArguments, PgColumn, PgConnection, PgQueryResult, PgRow, PgStatement, PgTransactionManager, PgTypeInfo, }; @@ -17,7 +17,7 @@ impl Database for Postgres { type Row = PgRow; - type Outcome = PgOutcome; + type QueryResult = PgQueryResult; type Column = PgColumn; diff --git a/sqlx-core/src/postgres/listener.rs b/sqlx-core/src/postgres/listener.rs index 0f719429..5e362eaf 100644 --- a/sqlx-core/src/postgres/listener.rs +++ b/sqlx-core/src/postgres/listener.rs @@ -4,7 +4,7 @@ use crate::executor::{Execute, Executor}; use crate::pool::PoolOptions; use crate::pool::{Pool, PoolConnection}; use crate::postgres::message::{MessageFormat, Notification}; -use crate::postgres::{PgConnection, PgOutcome, PgRow, PgStatement, PgTypeInfo, Postgres}; +use crate::postgres::{PgConnection, PgQueryResult, PgRow, PgStatement, PgTypeInfo, Postgres}; use either::Either; use futures_channel::mpsc; use futures_core::future::BoxFuture; @@ -263,7 +263,7 @@ impl<'c> Executor<'c> for &'c mut PgListener { fn fetch_many<'e, 'q: 'e, E: 'q>( self, query: E, - ) -> BoxStream<'e, Result, Error>> + ) -> BoxStream<'e, Result, Error>> where 'c: 'e, E: Execute<'q, Self::Database>, diff --git a/sqlx-core/src/postgres/mod.rs b/sqlx-core/src/postgres/mod.rs index a1739fec..bd72bc6e 100644 --- a/sqlx-core/src/postgres/mod.rs +++ b/sqlx-core/src/postgres/mod.rs @@ -9,7 +9,7 @@ mod io; mod listener; mod message; mod options; -mod outcome; +mod query_result; mod row; mod statement; mod transaction; @@ -28,7 +28,7 @@ pub use error::{PgDatabaseError, PgErrorPosition}; pub use listener::{PgListener, PgNotification}; pub use message::PgSeverity; pub use options::{PgConnectOptions, PgSslMode}; -pub use outcome::PgOutcome; +pub use query_result::PgQueryResult; pub use row::PgRow; pub use statement::PgStatement; pub use transaction::PgTransactionManager; diff --git a/sqlx-core/src/mssql/outcome.rs b/sqlx-core/src/postgres/query_result.rs similarity index 56% rename from sqlx-core/src/mssql/outcome.rs rename to sqlx-core/src/postgres/query_result.rs index ddb2b2cb..870c1aff 100644 --- a/sqlx-core/src/mssql/outcome.rs +++ b/sqlx-core/src/postgres/query_result.rs @@ -1,18 +1,18 @@ use std::iter::{Extend, IntoIterator}; #[derive(Debug, Default)] -pub struct MssqlOutcome { +pub struct PgQueryResult { pub(super) rows_affected: u64, } -impl MssqlOutcome { +impl PgQueryResult { pub fn rows_affected(&self) -> u64 { self.rows_affected } } -impl Extend for MssqlOutcome { - fn extend>(&mut self, iter: T) { +impl Extend for PgQueryResult { + fn extend>(&mut self, iter: T) { for elem in iter { self.rows_affected += elem.rows_affected; } @@ -20,9 +20,9 @@ impl Extend for MssqlOutcome { } #[cfg(feature = "any")] -impl From for crate::any::AnyOutcome { - fn from(done: MssqlOutcome) -> Self { - crate::any::AnyOutcome { +impl From for crate::any::AnyQueryResult { + fn from(done: PgQueryResult) -> Self { + crate::any::AnyQueryResult { rows_affected: done.rows_affected, last_insert_id: None, } diff --git a/sqlx-core/src/query.rs b/sqlx-core/src/query.rs index 3baad598..b3e30dc5 100644 --- a/sqlx-core/src/query.rs +++ b/sqlx-core/src/query.rs @@ -144,7 +144,7 @@ where /// Execute the query and return the total number of rows affected. #[inline] - pub async fn execute<'e, 'c: 'e, E>(self, executor: E) -> Result + pub async fn execute<'e, 'c: 'e, E>(self, executor: E) -> Result where 'q: 'e, A: 'e, @@ -158,7 +158,7 @@ where pub async fn execute_many<'e, 'c: 'e, E>( self, executor: E, - ) -> BoxStream<'e, Result> + ) -> BoxStream<'e, Result> where 'q: 'e, A: 'e, @@ -184,7 +184,7 @@ where pub fn fetch_many<'e, 'c: 'e, E>( self, executor: E, - ) -> BoxStream<'e, Result, Error>> + ) -> BoxStream<'e, Result, Error>> where 'q: 'e, A: 'e, @@ -322,7 +322,7 @@ where pub fn fetch_many<'e, 'c: 'e, E>( mut self, executor: E, - ) -> BoxStream<'e, Result, Error>> + ) -> BoxStream<'e, Result, Error>> where 'q: 'e, E: 'e + Executor<'c, Database = DB>, diff --git a/sqlx-core/src/query_as.rs b/sqlx-core/src/query_as.rs index 53ca67af..62406c21 100644 --- a/sqlx-core/src/query_as.rs +++ b/sqlx-core/src/query_as.rs @@ -84,7 +84,7 @@ where pub fn fetch_many<'e, 'c: 'e, E>( self, executor: E, - ) -> BoxStream<'e, Result, Error>> + ) -> BoxStream<'e, Result, Error>> where 'q: 'e, E: 'e + Executor<'c, Database = DB>, diff --git a/sqlx-core/src/query_scalar.rs b/sqlx-core/src/query_scalar.rs index 3ed04dbd..7e958a7b 100644 --- a/sqlx-core/src/query_scalar.rs +++ b/sqlx-core/src/query_scalar.rs @@ -82,7 +82,7 @@ where pub fn fetch_many<'e, 'c: 'e, E>( self, executor: E, - ) -> BoxStream<'e, Result, Error>> + ) -> BoxStream<'e, Result, Error>> where 'q: 'e, E: 'e + Executor<'c, Database = DB>, diff --git a/sqlx-core/src/sqlite/connection/executor.rs b/sqlx-core/src/sqlite/connection/executor.rs index 0eac7f4a..1194f9c4 100644 --- a/sqlx-core/src/sqlite/connection/executor.rs +++ b/sqlx-core/src/sqlite/connection/executor.rs @@ -6,7 +6,7 @@ use crate::logger::QueryLogger; use crate::sqlite::connection::describe::describe; use crate::sqlite::statement::{StatementHandle, VirtualStatement}; use crate::sqlite::{ - Sqlite, SqliteArguments, SqliteConnection, SqliteOutcome, SqliteRow, SqliteStatement, + Sqlite, SqliteArguments, SqliteConnection, SqliteQueryResult, SqliteRow, SqliteStatement, SqliteTypeInfo, }; use either::Either; @@ -65,7 +65,7 @@ impl<'c> Executor<'c> for &'c mut SqliteConnection { fn fetch_many<'e, 'q: 'e, E: 'q>( self, mut query: E, - ) -> BoxStream<'e, Result, Error>> + ) -> BoxStream<'e, Result, Error>> where 'c: 'e, E: Execute<'q, Self::Database>, @@ -109,7 +109,7 @@ impl<'c> Executor<'c> for &'c mut SqliteConnection { sqlite3_last_insert_rowid(conn.as_ptr()) }; - let done = SqliteOutcome { + let done = SqliteQueryResult { changes, last_insert_rowid, }; diff --git a/sqlx-core/src/sqlite/database.rs b/sqlx-core/src/sqlite/database.rs index 3c498a59..fe06a07b 100644 --- a/sqlx-core/src/sqlite/database.rs +++ b/sqlx-core/src/sqlite/database.rs @@ -1,6 +1,6 @@ use crate::database::{Database, HasArguments, HasStatement, HasStatementCache, HasValueRef}; use crate::sqlite::{ - SqliteArgumentValue, SqliteArguments, SqliteColumn, SqliteConnection, SqliteOutcome, SqliteRow, + SqliteArgumentValue, SqliteArguments, SqliteColumn, SqliteConnection, SqliteQueryResult, SqliteRow, SqliteStatement, SqliteTransactionManager, SqliteTypeInfo, SqliteValue, SqliteValueRef, }; @@ -15,7 +15,7 @@ impl Database for Sqlite { type Row = SqliteRow; - type Outcome = SqliteOutcome; + type QueryResult = SqliteQueryResult; type Column = SqliteColumn; diff --git a/sqlx-core/src/sqlite/mod.rs b/sqlx-core/src/sqlite/mod.rs index 82a69c16..ad2fe2c9 100644 --- a/sqlx-core/src/sqlite/mod.rs +++ b/sqlx-core/src/sqlite/mod.rs @@ -11,7 +11,7 @@ mod connection; mod database; mod error; mod options; -mod outcome; +mod query_result; mod row; mod statement; mod transaction; @@ -28,7 +28,7 @@ pub use connection::SqliteConnection; pub use database::Sqlite; pub use error::SqliteError; pub use options::{SqliteConnectOptions, SqliteJournalMode, SqliteSynchronous}; -pub use outcome::SqliteOutcome; +pub use query_result::SqliteQueryResult; pub use row::SqliteRow; pub use statement::SqliteStatement; pub use transaction::SqliteTransactionManager; diff --git a/sqlx-core/src/sqlite/outcome.rs b/sqlx-core/src/sqlite/query_result.rs similarity index 63% rename from sqlx-core/src/sqlite/outcome.rs rename to sqlx-core/src/sqlite/query_result.rs index 78001bf7..f131c74b 100644 --- a/sqlx-core/src/sqlite/outcome.rs +++ b/sqlx-core/src/sqlite/query_result.rs @@ -1,12 +1,12 @@ use std::iter::{Extend, IntoIterator}; #[derive(Debug, Default)] -pub struct SqliteOutcome { +pub struct SqliteQueryResult { pub(super) changes: u64, pub(super) last_insert_rowid: i64, } -impl SqliteOutcome { +impl SqliteQueryResult { pub fn rows_affected(&self) -> u64 { self.changes } @@ -16,8 +16,8 @@ impl SqliteOutcome { } } -impl Extend for SqliteOutcome { - fn extend>(&mut self, iter: T) { +impl Extend for SqliteQueryResult { + fn extend>(&mut self, iter: T) { for elem in iter { self.changes += elem.changes; self.last_insert_rowid = elem.last_insert_rowid; @@ -26,9 +26,9 @@ impl Extend for SqliteOutcome { } #[cfg(feature = "any")] -impl From for crate::any::AnyOutcome { - fn from(done: SqliteOutcome) -> Self { - crate::any::AnyOutcome { +impl From for crate::any::AnyQueryResult { + fn from(done: SqliteQueryResult) -> Self { + crate::any::AnyQueryResult { rows_affected: done.changes, last_insert_id: Some(done.last_insert_rowid), } diff --git a/sqlx-core/src/transaction.rs b/sqlx-core/src/transaction.rs index e2babe3e..76d5ac85 100644 --- a/sqlx-core/src/transaction.rs +++ b/sqlx-core/src/transaction.rs @@ -109,7 +109,7 @@ macro_rules! impl_executor_for_transaction { ) -> futures_core::stream::BoxStream< 'e, Result< - either::Either<<$DB as crate::database::Database>::Outcome, $Row>, + either::Either<<$DB as crate::database::Database>::QueryResult, $Row>, crate::error::Error, >, > diff --git a/src/macros.rs b/src/macros.rs index 00b478f7..7d2f7a5e 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -32,7 +32,7 @@ /// /// | Number of Rows | Method to Call* | Returns | Notes | /// |----------------| ----------------------------|-----------------------------------------------------|-------| -/// | None† | `.execute(...).await` | `sqlx::Result | For `INSERT`/`UPDATE`/`DELETE` without `RETURNING`. | +/// | None† | `.execute(...).await` | `sqlx::Result | For `INSERT`/`UPDATE`/`DELETE` without `RETURNING`. | /// | Zero or One | `.fetch_optional(...).await`| `sqlx::Result>` | Extra rows are ignored. | /// | Exactly One | `.fetch_one(...).await` | `sqlx::Result<{adhoc struct}>` | Errors if no rows were returned. Extra rows are ignored. Aggregate queries, use this. | /// | At Least One | `.fetch(...)` | `impl Stream>` | Call `.try_next().await` to get each row result. |