diff --git a/CHANGELOG.md b/CHANGELOG.md index 794efefb3..f534ef459 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,11 @@ 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]] Remove the `Done` trait. The `.rows_affected()` method is now available as an inherent + method on `PgOutcome`, `MySqlOutcome` and so on. [[@jplatte]] + - [[#983]] Upgrade async runtime dependencies [[@seryl, @ant32, @jplatte]] - tokio 1.0 diff --git a/examples/mysql/todos/src/main.rs b/examples/mysql/todos/src/main.rs index 5ffc48795..6415ffccf 100644 --- a/examples/mysql/todos/src/main.rs +++ b/examples/mysql/todos/src/main.rs @@ -1,5 +1,4 @@ use sqlx::mysql::MySqlPool; -use sqlx::Done; use std::env; use structopt::StructOpt; diff --git a/examples/postgres/mockable-todos/src/main.rs b/examples/postgres/mockable-todos/src/main.rs index 340faf80c..7f9081c81 100644 --- a/examples/postgres/mockable-todos/src/main.rs +++ b/examples/postgres/mockable-todos/src/main.rs @@ -1,7 +1,6 @@ use async_trait::async_trait; use dotenv; use sqlx::postgres::PgPool; -use sqlx::Done; use std::{env, io::Write, sync::Arc}; use structopt::StructOpt; diff --git a/examples/postgres/todos/src/main.rs b/examples/postgres/todos/src/main.rs index 1fb38c5fc..a33209c4d 100644 --- a/examples/postgres/todos/src/main.rs +++ b/examples/postgres/todos/src/main.rs @@ -1,5 +1,4 @@ use sqlx::postgres::PgPool; -use sqlx::Done; use std::env; use structopt::StructOpt; diff --git a/examples/sqlite/todos/src/main.rs b/examples/sqlite/todos/src/main.rs index d55d566fe..b3372a4d1 100644 --- a/examples/sqlite/todos/src/main.rs +++ b/examples/sqlite/todos/src/main.rs @@ -1,5 +1,4 @@ use sqlx::sqlite::SqlitePool; -use sqlx::Done; use std::env; use structopt::StructOpt; diff --git a/sqlx-core/src/any/connection/executor.rs b/sqlx-core/src/any/connection/executor.rs index 1aae7dab8..81d09a609 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, AnyDone, AnyRow, AnyStatement, AnyTypeInfo}; +use crate::any::{Any, AnyColumn, AnyConnection, AnyOutcome, 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 dce948b11..15b06a227 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, AnyDone, AnyRow, AnyStatement, + AnyArgumentBuffer, AnyArguments, AnyColumn, AnyConnection, AnyOutcome, 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 Done = AnyDone; + type Outcome = AnyOutcome; type Column = AnyColumn; diff --git a/sqlx-core/src/any/mod.rs b/sqlx-core/src/any/mod.rs index 5acc023fa..1f5f8b410 100644 --- a/sqlx-core/src/any/mod.rs +++ b/sqlx-core/src/any/mod.rs @@ -13,9 +13,9 @@ mod arguments; pub(crate) mod column; mod connection; mod database; -mod done; mod kind; mod options; +mod outcome; pub(crate) mod row; mod statement; mod transaction; @@ -31,10 +31,10 @@ pub use column::{AnyColumn, AnyColumnIndex}; pub use connection::AnyConnection; pub use database::Any; pub use decode::AnyDecode; -pub use done::AnyDone; pub use encode::AnyEncode; pub use kind::AnyKind; pub use options::AnyConnectOptions; +pub use outcome::AnyOutcome; pub use r#type::AnyType; pub use row::AnyRow; pub use statement::AnyStatement; diff --git a/sqlx-core/src/any/done.rs b/sqlx-core/src/any/outcome.rs similarity index 60% rename from sqlx-core/src/any/done.rs rename to sqlx-core/src/any/outcome.rs index d91e77339..97deadd99 100644 --- a/sqlx-core/src/any/done.rs +++ b/sqlx-core/src/any/outcome.rs @@ -1,29 +1,23 @@ -use crate::any::Any; -use crate::done::Done; use std::iter::{Extend, IntoIterator}; #[derive(Debug, Default)] -pub struct AnyDone { +pub struct AnyOutcome { pub(crate) rows_affected: u64, pub(crate) last_insert_id: Option, } -impl AnyDone { +impl AnyOutcome { + pub fn rows_affected(&self) -> u64 { + self.rows_affected + } + pub fn last_insert_id(&self) -> Option { self.last_insert_id } } -impl Done for AnyDone { - type Database = Any; - - fn rows_affected(&self) -> u64 { - self.rows_affected - } -} - -impl Extend for AnyDone { - fn extend>(&mut self, iter: T) { +impl Extend for AnyOutcome { + 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 870898327..e8625785a 100644 --- a/sqlx-core/src/database.rs +++ b/sqlx-core/src/database.rs @@ -58,7 +58,6 @@ use std::fmt::Debug; use crate::arguments::Arguments; use crate::column::Column; use crate::connection::Connection; -use crate::done::Done; use crate::row::Row; use crate::statement::Statement; use crate::transaction::TransactionManager; @@ -87,8 +86,8 @@ pub trait Database: /// The concrete `Row` implementation for this database. type Row: Row; - /// The concrete `Done` implementation for this database. - type Done: Done; + /// The concrete `Outcome` implementation for this database. + type Outcome: 'static + Sized + Send + Sync + Default + Extend; /// The concrete `Column` implementation for this database. type Column: Column; diff --git a/sqlx-core/src/done.rs b/sqlx-core/src/done.rs deleted file mode 100644 index c3d0ea507..000000000 --- a/sqlx-core/src/done.rs +++ /dev/null @@ -1,9 +0,0 @@ -use crate::database::Database; -use std::iter::Extend; - -pub trait Done: 'static + Sized + Send + Sync + Default + Extend { - type Database: Database; - - /// Returns the number of rows affected by an `UPDATE`, `INSERT`, or `DELETE`. - fn rows_affected(&self) -> u64; -} diff --git a/sqlx-core/src/executor.rs b/sqlx-core/src/executor.rs index 4ef86cbf6..fc907b86c 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<::Done, Error>> + ) -> BoxFuture<'e, Result<::Outcome, 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<::Done, Error>> + ) -> BoxStream<'e, Result<::Outcome, Error>> where 'c: 'e, E: Execute<'q, Self::Database>, @@ -83,7 +83,7 @@ pub trait Executor<'c>: Send + Debug + Sized { ) -> BoxStream< 'e, Result< - Either<::Done, ::Row>, + Either<::Outcome, ::Row>, Error, >, > diff --git a/sqlx-core/src/lib.rs b/sqlx-core/src/lib.rs index 6e18f16fc..505181f82 100644 --- a/sqlx-core/src/lib.rs +++ b/sqlx-core/src/lib.rs @@ -58,7 +58,6 @@ pub mod statement; mod common; pub mod database; pub mod describe; -pub mod done; pub mod executor; pub mod from_row; mod io; diff --git a/sqlx-core/src/mssql/connection/executor.rs b/sqlx-core/src/mssql/connection/executor.rs index 3a53c4db3..04213e2c3 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, MssqlDone, MssqlRow, MssqlStatement, MssqlTypeInfo, + Mssql, MssqlArguments, MssqlConnection, MssqlOutcome, 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(MssqlDone { + r#yield!(Either::Left(MssqlOutcome { 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(MssqlDone { + r#yield!(Either::Left(MssqlOutcome { rows_affected: done.affected_rows, })); } diff --git a/sqlx-core/src/mssql/database.rs b/sqlx-core/src/mssql/database.rs index 4831d89bc..f85eabf43 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, MssqlDone, MssqlRow, MssqlStatement, + MssqlArguments, MssqlColumn, MssqlConnection, MssqlOutcome, MssqlRow, MssqlStatement, MssqlTransactionManager, MssqlTypeInfo, MssqlValue, MssqlValueRef, }; @@ -15,7 +15,7 @@ impl Database for Mssql { type Row = MssqlRow; - type Done = MssqlDone; + type Outcome = MssqlOutcome; type Column = MssqlColumn; diff --git a/sqlx-core/src/mssql/done.rs b/sqlx-core/src/mssql/done.rs deleted file mode 100644 index dfe308db2..000000000 --- a/sqlx-core/src/mssql/done.rs +++ /dev/null @@ -1,34 +0,0 @@ -use crate::done::Done; -use crate::mssql::Mssql; -use std::iter::{Extend, IntoIterator}; - -#[derive(Debug, Default)] -pub struct MssqlDone { - pub(super) rows_affected: u64, -} - -impl Done for MssqlDone { - type Database = Mssql; - - fn rows_affected(&self) -> u64 { - self.rows_affected - } -} - -impl Extend for MssqlDone { - fn extend>(&mut self, iter: T) { - for elem in iter { - self.rows_affected += elem.rows_affected; - } - } -} - -#[cfg(feature = "any")] -impl From for crate::any::AnyDone { - fn from(done: MssqlDone) -> Self { - crate::any::AnyDone { - rows_affected: done.rows_affected, - last_insert_id: None, - } - } -} diff --git a/sqlx-core/src/mssql/mod.rs b/sqlx-core/src/mssql/mod.rs index 3c1182161..1f32a04cb 100644 --- a/sqlx-core/src/mssql/mod.rs +++ b/sqlx-core/src/mssql/mod.rs @@ -4,10 +4,10 @@ mod arguments; mod column; mod connection; mod database; -mod done; mod error; mod io; mod options; +mod outcome; mod protocol; mod row; mod statement; @@ -20,9 +20,9 @@ pub use arguments::MssqlArguments; pub use column::MssqlColumn; pub use connection::MssqlConnection; pub use database::Mssql; -pub use done::MssqlDone; pub use error::MssqlDatabaseError; pub use options::MssqlConnectOptions; +pub use outcome::MssqlOutcome; pub use row::MssqlRow; pub use statement::MssqlStatement; pub use transaction::MssqlTransactionManager; diff --git a/sqlx-core/src/mssql/outcome.rs b/sqlx-core/src/mssql/outcome.rs new file mode 100644 index 000000000..ddb2b2cb6 --- /dev/null +++ b/sqlx-core/src/mssql/outcome.rs @@ -0,0 +1,30 @@ +use std::iter::{Extend, IntoIterator}; + +#[derive(Debug, Default)] +pub struct MssqlOutcome { + pub(super) rows_affected: u64, +} + +impl MssqlOutcome { + pub fn rows_affected(&self) -> u64 { + self.rows_affected + } +} + +impl Extend for MssqlOutcome { + fn extend>(&mut self, iter: T) { + for elem in iter { + self.rows_affected += elem.rows_affected; + } + } +} + +#[cfg(feature = "any")] +impl From for crate::any::AnyOutcome { + fn from(done: MssqlOutcome) -> Self { + crate::any::AnyOutcome { + 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 bedf1f8cb..a981a4646 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, MySqlDone, MySqlRow, MySqlTypeInfo, + MySql, MySqlArguments, MySqlColumn, MySqlConnection, MySqlOutcome, 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 = MySqlDone { + let done = MySqlOutcome { 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(MySqlDone { + r#yield!(Either::Left(MySqlOutcome { 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 fe6a4cf60..30fd4dfa7 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, MySqlDone, MySqlRow, MySqlStatement, + MySqlArguments, MySqlColumn, MySqlConnection, MySqlOutcome, MySqlRow, MySqlStatement, MySqlTransactionManager, MySqlTypeInfo, }; @@ -16,7 +16,7 @@ impl Database for MySql { type Row = MySqlRow; - type Done = MySqlDone; + type Outcome = MySqlOutcome; type Column = MySqlColumn; diff --git a/sqlx-core/src/mysql/mod.rs b/sqlx-core/src/mysql/mod.rs index 023e95def..9bbf53771 100644 --- a/sqlx-core/src/mysql/mod.rs +++ b/sqlx-core/src/mysql/mod.rs @@ -5,10 +5,10 @@ mod collation; mod column; mod connection; mod database; -mod done; mod error; mod io; mod options; +mod outcome; mod protocol; mod row; mod statement; @@ -24,9 +24,9 @@ pub use arguments::MySqlArguments; pub use column::MySqlColumn; pub use connection::MySqlConnection; pub use database::MySql; -pub use done::MySqlDone; pub use error::MySqlDatabaseError; pub use options::{MySqlConnectOptions, MySqlSslMode}; +pub use outcome::MySqlOutcome; pub use row::MySqlRow; pub use statement::MySqlStatement; pub use transaction::MySqlTransactionManager; diff --git a/sqlx-core/src/mysql/done.rs b/sqlx-core/src/mysql/outcome.rs similarity index 57% rename from sqlx-core/src/mysql/done.rs rename to sqlx-core/src/mysql/outcome.rs index 45e3a6f23..7267f98d6 100644 --- a/sqlx-core/src/mysql/done.rs +++ b/sqlx-core/src/mysql/outcome.rs @@ -1,29 +1,23 @@ -use crate::done::Done; -use crate::mysql::MySql; use std::iter::{Extend, IntoIterator}; #[derive(Debug, Default)] -pub struct MySqlDone { +pub struct MySqlOutcome { pub(super) rows_affected: u64, pub(super) last_insert_id: u64, } -impl MySqlDone { +impl MySqlOutcome { pub fn last_insert_id(&self) -> u64 { self.last_insert_id } -} -impl Done for MySqlDone { - type Database = MySql; - - fn rows_affected(&self) -> u64 { + pub fn rows_affected(&self) -> u64 { self.rows_affected } } -impl Extend for MySqlDone { - fn extend>(&mut self, iter: T) { +impl Extend for MySqlOutcome { + fn extend>(&mut self, iter: T) { for elem in iter { self.rows_affected += elem.rows_affected; self.last_insert_id = elem.last_insert_id; @@ -32,9 +26,9 @@ impl Extend for MySqlDone { } #[cfg(feature = "any")] -impl From for crate::any::AnyDone { - fn from(done: MySqlDone) -> Self { - crate::any::AnyDone { +impl From for crate::any::AnyOutcome { + fn from(done: MySqlOutcome) -> Self { + crate::any::AnyOutcome { 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 26f1dcfb0..d8d479642 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>::Done, $R>, + either::Either<<$DB as crate::database::Database>::Outcome, $R>, crate::error::Error, >, > diff --git a/sqlx-core/src/postgres/connection/executor.rs b/sqlx-core/src/postgres/connection/executor.rs index 3b5ab3ef2..d8e616354 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, PgDone, PgRow, PgTypeInfo, PgValueFormat, + statement::PgStatement, PgArguments, PgConnection, PgOutcome, 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(PgDone { + r#yield!(Either::Left(PgOutcome { 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 f3041dd4c..4c4595a23 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, PgDone, PgRow, PgStatement, PgTransactionManager, + PgArguments, PgColumn, PgConnection, PgOutcome, PgRow, PgStatement, PgTransactionManager, PgTypeInfo, }; @@ -17,7 +17,7 @@ impl Database for Postgres { type Row = PgRow; - type Done = PgDone; + type Outcome = PgOutcome; type Column = PgColumn; diff --git a/sqlx-core/src/postgres/done.rs b/sqlx-core/src/postgres/done.rs deleted file mode 100644 index 05be76e2f..000000000 --- a/sqlx-core/src/postgres/done.rs +++ /dev/null @@ -1,34 +0,0 @@ -use crate::done::Done; -use crate::postgres::Postgres; -use std::iter::{Extend, IntoIterator}; - -#[derive(Debug, Default)] -pub struct PgDone { - pub(super) rows_affected: u64, -} - -impl Done for PgDone { - type Database = Postgres; - - fn rows_affected(&self) -> u64 { - self.rows_affected - } -} - -impl Extend for PgDone { - fn extend>(&mut self, iter: T) { - for elem in iter { - self.rows_affected += elem.rows_affected; - } - } -} - -#[cfg(feature = "any")] -impl From for crate::any::AnyDone { - fn from(done: PgDone) -> Self { - crate::any::AnyDone { - rows_affected: done.rows_affected, - last_insert_id: None, - } - } -} diff --git a/sqlx-core/src/postgres/listener.rs b/sqlx-core/src/postgres/listener.rs index ea62fde7f..0f719429e 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, PgDone, PgRow, PgStatement, PgTypeInfo, Postgres}; +use crate::postgres::{PgConnection, PgOutcome, 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 59cbf7ad6..a1739fecd 100644 --- a/sqlx-core/src/postgres/mod.rs +++ b/sqlx-core/src/postgres/mod.rs @@ -4,12 +4,12 @@ mod arguments; mod column; mod connection; mod database; -mod done; mod error; mod io; mod listener; mod message; mod options; +mod outcome; mod row; mod statement; mod transaction; @@ -24,11 +24,11 @@ pub use arguments::{PgArgumentBuffer, PgArguments}; pub use column::PgColumn; pub use connection::PgConnection; pub use database::Postgres; -pub use done::PgDone; 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 row::PgRow; pub use statement::PgStatement; pub use transaction::PgTransactionManager; diff --git a/sqlx-core/src/postgres/outcome.rs b/sqlx-core/src/postgres/outcome.rs new file mode 100644 index 000000000..c8177d5ba --- /dev/null +++ b/sqlx-core/src/postgres/outcome.rs @@ -0,0 +1,30 @@ +use std::iter::{Extend, IntoIterator}; + +#[derive(Debug, Default)] +pub struct PgOutcome { + pub(super) rows_affected: u64, +} + +impl PgOutcome { + pub fn rows_affected(&self) -> u64 { + self.rows_affected + } +} + +impl Extend for PgOutcome { + fn extend>(&mut self, iter: T) { + for elem in iter { + self.rows_affected += elem.rows_affected; + } + } +} + +#[cfg(feature = "any")] +impl From for crate::any::AnyOutcome { + fn from(done: PgOutcome) -> Self { + crate::any::AnyOutcome { + rows_affected: done.rows_affected, + last_insert_id: None, + } + } +} diff --git a/sqlx-core/src/query.rs b/sqlx-core/src/query.rs index 11c504961..3baad5986 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 efc8b800d..53ca67af6 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 d19fc7ed2..3ed04dbd4 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 baae49a73..0eac7f4ac 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, SqliteDone, SqliteRow, SqliteStatement, + Sqlite, SqliteArguments, SqliteConnection, SqliteOutcome, 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 = SqliteDone { + let done = SqliteOutcome { changes, last_insert_rowid, }; diff --git a/sqlx-core/src/sqlite/database.rs b/sqlx-core/src/sqlite/database.rs index 065e5abf8..3c498a593 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, SqliteDone, SqliteRow, + SqliteArgumentValue, SqliteArguments, SqliteColumn, SqliteConnection, SqliteOutcome, SqliteRow, SqliteStatement, SqliteTransactionManager, SqliteTypeInfo, SqliteValue, SqliteValueRef, }; @@ -15,7 +15,7 @@ impl Database for Sqlite { type Row = SqliteRow; - type Done = SqliteDone; + type Outcome = SqliteOutcome; type Column = SqliteColumn; diff --git a/sqlx-core/src/sqlite/mod.rs b/sqlx-core/src/sqlite/mod.rs index 4aae7bc4f..82a69c163 100644 --- a/sqlx-core/src/sqlite/mod.rs +++ b/sqlx-core/src/sqlite/mod.rs @@ -9,9 +9,9 @@ mod arguments; mod column; mod connection; mod database; -mod done; mod error; mod options; +mod outcome; mod row; mod statement; mod transaction; @@ -26,9 +26,9 @@ pub use arguments::{SqliteArgumentValue, SqliteArguments}; pub use column::SqliteColumn; pub use connection::SqliteConnection; pub use database::Sqlite; -pub use done::SqliteDone; pub use error::SqliteError; pub use options::{SqliteConnectOptions, SqliteJournalMode, SqliteSynchronous}; +pub use outcome::SqliteOutcome; pub use row::SqliteRow; pub use statement::SqliteStatement; pub use transaction::SqliteTransactionManager; diff --git a/sqlx-core/src/sqlite/done.rs b/sqlx-core/src/sqlite/outcome.rs similarity index 56% rename from sqlx-core/src/sqlite/done.rs rename to sqlx-core/src/sqlite/outcome.rs index 55c68d7de..78001bf77 100644 --- a/sqlx-core/src/sqlite/done.rs +++ b/sqlx-core/src/sqlite/outcome.rs @@ -1,29 +1,23 @@ -use crate::done::Done; -use crate::sqlite::Sqlite; use std::iter::{Extend, IntoIterator}; #[derive(Debug, Default)] -pub struct SqliteDone { +pub struct SqliteOutcome { pub(super) changes: u64, pub(super) last_insert_rowid: i64, } -impl SqliteDone { +impl SqliteOutcome { + pub fn rows_affected(&self) -> u64 { + self.changes + } + pub fn last_insert_rowid(&self) -> i64 { self.last_insert_rowid } } -impl Done for SqliteDone { - type Database = Sqlite; - - fn rows_affected(&self) -> u64 { - self.changes - } -} - -impl Extend for SqliteDone { - fn extend>(&mut self, iter: T) { +impl Extend for SqliteOutcome { + fn extend>(&mut self, iter: T) { for elem in iter { self.changes += elem.changes; self.last_insert_rowid = elem.last_insert_rowid; @@ -32,9 +26,9 @@ impl Extend for SqliteDone { } #[cfg(feature = "any")] -impl From for crate::any::AnyDone { - fn from(done: SqliteDone) -> Self { - crate::any::AnyDone { +impl From for crate::any::AnyOutcome { + fn from(done: SqliteOutcome) -> Self { + crate::any::AnyOutcome { 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 e5ce787cf..e2babe3e2 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>::Done, $Row>, + either::Either<<$DB as crate::database::Database>::Outcome, $Row>, crate::error::Error, >, > diff --git a/src/lib.rs b/src/lib.rs index ff63e89d9..73df9ece7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,7 +18,6 @@ pub use sqlx_core::column::ColumnIndex; pub use sqlx_core::connection::{ConnectOptions, Connection}; pub use sqlx_core::database::{self, Database}; pub use sqlx_core::describe::Describe; -pub use sqlx_core::done::Done; pub use sqlx_core::executor::{Execute, Executor}; pub use sqlx_core::from_row::FromRow; pub use sqlx_core::pool::{self, Pool}; @@ -140,7 +139,6 @@ pub mod prelude { pub use super::ConnectOptions; pub use super::Connection; pub use super::Decode; - pub use super::Done; pub use super::Encode; pub use super::Executor; pub use super::FromRow; diff --git a/src/macros.rs b/src/macros.rs index a13537170..00b478f71 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -32,12 +32,12 @@ /// /// | Number of Rows | Method to Call* | Returns | Notes | /// |----------------| ----------------------------|-----------------------------------------------------|-------| -/// | None† | `.execute(...).await` | `sqlx::Result` | For `INSERT`/`UPDATE`/`DELETE` without `RETURNING`. See [`crate::Done`]. | +/// | 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. | /// -/// \* All methods accept one of `&mut {connection type}`, `&mut Transaction` or `&Pool`. +/// \* All methods accept one of `&mut {connection type}`, `&mut Transaction` or `&Pool`. /// † Only callable if the query returns no columns; otherwise it's assumed the query *may* return at least one row. /// ## Requirements /// * The `DATABASE_URL` environment variable must be set at build-time to point to a database diff --git a/tests/mssql/mssql.rs b/tests/mssql/mssql.rs index 1fb8e59ff..a5c81810a 100644 --- a/tests/mssql/mssql.rs +++ b/tests/mssql/mssql.rs @@ -1,6 +1,6 @@ use futures::TryStreamExt; use sqlx::mssql::Mssql; -use sqlx::{Column, Connection, Done, Executor, MssqlConnection, Row, Statement, TypeInfo}; +use sqlx::{Column, Connection, Executor, MssqlConnection, Row, Statement, TypeInfo}; use sqlx_core::mssql::MssqlRow; use sqlx_test::new; diff --git a/tests/mysql/mysql.rs b/tests/mysql/mysql.rs index 52d1f9436..baeaf9923 100644 --- a/tests/mysql/mysql.rs +++ b/tests/mysql/mysql.rs @@ -1,6 +1,6 @@ use futures::TryStreamExt; use sqlx::mysql::{MySql, MySqlConnection, MySqlPool, MySqlPoolOptions, MySqlRow}; -use sqlx::{Column, Connection, Done, Executor, Row, Statement, TypeInfo}; +use sqlx::{Column, Connection, Executor, Row, Statement, TypeInfo}; use sqlx_test::{new, setup_if_needed}; use std::env; diff --git a/tests/postgres/postgres.rs b/tests/postgres/postgres.rs index 6aef6ad80..df6fc795a 100644 --- a/tests/postgres/postgres.rs +++ b/tests/postgres/postgres.rs @@ -3,7 +3,7 @@ use sqlx::postgres::{ PgConnectOptions, PgConnection, PgDatabaseError, PgErrorPosition, PgSeverity, }; use sqlx::postgres::{PgPoolOptions, PgRow, Postgres}; -use sqlx::{Column, Connection, Done, Executor, Row, Statement, TypeInfo}; +use sqlx::{Column, Connection, Executor, Row, Statement, TypeInfo}; use sqlx_test::{new, setup_if_needed}; use std::env; use std::thread; diff --git a/tests/sqlite/sqlite.rs b/tests/sqlite/sqlite.rs index 1761fdc3e..b8fd42325 100644 --- a/tests/sqlite/sqlite.rs +++ b/tests/sqlite/sqlite.rs @@ -1,8 +1,8 @@ use futures::TryStreamExt; use sqlx::sqlite::SqlitePoolOptions; use sqlx::{ - query, sqlite::Sqlite, sqlite::SqliteRow, Column, Connection, Done, Executor, Row, - SqliteConnection, SqlitePool, Statement, TypeInfo, + query, sqlite::Sqlite, sqlite::SqliteRow, Column, Connection, Executor, Row, SqliteConnection, + SqlitePool, Statement, TypeInfo, }; use sqlx_test::new;