Skip to content

Commit

Permalink
Rename DbDone to DbOutcome
Browse files Browse the repository at this point in the history
  • Loading branch information
jplatte committed Jan 12, 2021
1 parent 1213e46 commit ee93882
Show file tree
Hide file tree
Showing 29 changed files with 85 additions and 83 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +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]] Remove the `Done` trait. The `.rows_affected()` method is now available as an inherent
method on `PgDone`, `MySqlDone` and so on.
method on `PgOutcome`, `MySqlOutcome` and so on. [[@jplatte]]

## 0.4.2 - 2020-12-19

Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/any/database.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -16,7 +16,7 @@ impl Database for Any {

type Row = AnyRow;

type Done = AnyDone;
type Outcome = AnyOutcome;

type Column = AnyColumn;

Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/any/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions sqlx-core/src/any/done.rs → sqlx-core/src/any/outcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use crate::any::Any;
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<i64>,
}

impl AnyDone {
impl AnyOutcome {
pub fn rows_affected(&self) -> u64 {
self.rows_affected
}
Expand All @@ -17,8 +17,8 @@ impl AnyDone {
}
}

impl Extend<AnyDone> for AnyDone {
fn extend<T: IntoIterator<Item = AnyDone>>(&mut self, iter: T) {
impl Extend<AnyOutcome> for AnyOutcome {
fn extend<T: IntoIterator<Item = AnyOutcome>>(&mut self, iter: T) {
for elem in iter {
self.rows_affected += elem.rows_affected;
self.last_insert_id = elem.last_insert_id;
Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ pub trait Database:
/// The concrete `Row` implementation for this database.
type Row: Row<Database = Self>;

/// The concrete `Done` implementation for this database.
type Done;
/// The concrete `Outcome` implementation for this database.
type Outcome;

/// The concrete `Column` implementation for this database.
type Column: Column<Database = Self>;
Expand Down
6 changes: 3 additions & 3 deletions sqlx-core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub trait Executor<'c>: Send + Debug + Sized {
fn execute<'e, 'q: 'e, E: 'q>(
self,
query: E,
) -> BoxFuture<'e, Result<<Self::Database as Database>::Done, Error>>
) -> BoxFuture<'e, Result<<Self::Database as Database>::Outcome, Error>>
where
'c: 'e,
E: Execute<'q, Self::Database>,
Expand All @@ -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<<Self::Database as Database>::Done, Error>>
) -> BoxStream<'e, Result<<Self::Database as Database>::Outcome, Error>>
where
'c: 'e,
E: Execute<'q, Self::Database>,
Expand Down Expand Up @@ -83,7 +83,7 @@ pub trait Executor<'c>: Send + Debug + Sized {
) -> BoxStream<
'e,
Result<
Either<<Self::Database as Database>::Done, <Self::Database as Database>::Row>,
Either<<Self::Database as Database>::Outcome, <Self::Database as Database>::Row>,
Error,
>,
>
Expand Down
8 changes: 4 additions & 4 deletions sqlx-core/src/mssql/connection/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Either<MssqlDone, MssqlRow>, Error>>
) -> BoxStream<'e, Result<Either<MssqlOutcome, MssqlRow>, Error>>
where
'c: 'e,
E: Execute<'q, Self::Database>,
Expand Down Expand Up @@ -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,
}));
}
Expand All @@ -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,
}));
}
Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/mssql/database.rs
Original file line number Diff line number Diff line change
@@ -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,
};

Expand All @@ -15,7 +15,7 @@ impl Database for Mssql {

type Row = MssqlRow;

type Done = MssqlDone;
type Outcome = MssqlOutcome;

type Column = MssqlColumn;

Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/mssql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,7 +20,7 @@ pub use arguments::MssqlArguments;
pub use column::MssqlColumn;
pub use connection::MssqlConnection;
pub use database::Mssql;
pub use done::MssqlDone;
pub use done::MssqlOutcome;
pub use error::MssqlDatabaseError;
pub use options::MssqlConnectOptions;
pub use row::MssqlRow;
Expand Down
12 changes: 6 additions & 6 deletions sqlx-core/src/mssql/done.rs → sqlx-core/src/mssql/outcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ use crate::mssql::Mssql;
use std::iter::{Extend, IntoIterator};

#[derive(Debug, Default)]
pub struct MssqlDone {
pub struct MssqlOutcome {
pub(super) rows_affected: u64,
}

impl MssqlDone {
impl MssqlOutcome {
pub fn rows_affected(&self) -> u64 {
self.rows_affected
}
}

impl Extend<MssqlDone> for MssqlDone {
fn extend<T: IntoIterator<Item = MssqlDone>>(&mut self, iter: T) {
impl Extend<MssqlOutcome> for MssqlOutcome {
fn extend<T: IntoIterator<Item = MssqlOutcome>>(&mut self, iter: T) {
for elem in iter {
self.rows_affected += elem.rows_affected;
}
}
}

#[cfg(feature = "any")]
impl From<MssqlDone> for crate::any::AnyDone {
fn from(done: MssqlDone) -> Self {
impl From<MssqlOutcome> for crate::any::AnyDone {
fn from(done: MssqlOutcome) -> Self {
crate::any::AnyDone {
rows_affected: done.rows_affected,
last_insert_id: None,
Expand Down
10 changes: 5 additions & 5 deletions sqlx-core/src/mysql/connection/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,7 +88,7 @@ impl MySqlConnection {
sql: &'q str,
arguments: Option<MySqlArguments>,
persistent: bool,
) -> Result<impl Stream<Item = Result<Either<MySqlDone, MySqlRow>, Error>> + 'e, Error> {
) -> Result<impl Stream<Item = Result<Either<MySqlOutcome, MySqlRow>, Error>> + 'e, Error> {
let mut logger = QueryLogger::new(sql, self.log_settings.clone());

self.stream.wait_until_ready().await?;
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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,
}));
Expand Down Expand Up @@ -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<Either<MySqlDone, MySqlRow>, Error>>
) -> BoxStream<'e, Result<Either<MySqlOutcome, MySqlRow>, Error>>
where
'c: 'e,
E: Execute<'q, Self::Database>,
Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/mysql/database.rs
Original file line number Diff line number Diff line change
@@ -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,
};

Expand All @@ -16,7 +16,7 @@ impl Database for MySql {

type Row = MySqlRow;

type Done = MySqlDone;
type Outcome = MySqlOutcome;

type Column = MySqlColumn;

Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/mysql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions sqlx-core/src/mysql/done.rs → sqlx-core/src/mysql/outcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ 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
}
Expand All @@ -17,8 +17,8 @@ impl MySqlDone {
}
}

impl Extend<MySqlDone> for MySqlDone {
fn extend<T: IntoIterator<Item = MySqlDone>>(&mut self, iter: T) {
impl Extend<MySqlOutcome> for MySqlOutcome {
fn extend<T: IntoIterator<Item = MySqlOutcome>>(&mut self, iter: T) {
for elem in iter {
self.rows_affected += elem.rows_affected;
self.last_insert_id = elem.last_insert_id;
Expand All @@ -27,8 +27,8 @@ impl Extend<MySqlDone> for MySqlDone {
}

#[cfg(feature = "any")]
impl From<MySqlDone> for crate::any::AnyDone {
fn from(done: MySqlDone) -> Self {
impl From<MySqlOutcome> for crate::any::AnyDone {
fn from(done: MySqlOutcome) -> Self {
crate::any::AnyDone {
rows_affected: done.rows_affected,
last_insert_id: Some(done.last_insert_id as i64),
Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/pool/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ where
fn fetch_many<'e, 'q: 'e, E: 'q>(
self,
query: E,
) -> BoxStream<'e, Result<Either<DB::Done, DB::Row>, Error>>
) -> BoxStream<'e, Result<Either<DB::Outcome, DB::Row>, Error>>
where
E: Execute<'q, Self::Database>,
{
Expand Down Expand Up @@ -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,
>,
>
Expand Down
8 changes: 4 additions & 4 deletions sqlx-core/src/postgres/connection/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -198,7 +198,7 @@ impl PgConnection {
limit: u8,
persistent: bool,
metadata_opt: Option<Arc<PgStatementMetadata>>,
) -> Result<impl Stream<Item = Result<Either<PgDone, PgRow>, Error>> + 'e, Error> {
) -> Result<impl Stream<Item = Result<Either<PgOutcome, PgRow>, 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
Expand Down Expand Up @@ -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(),
}));
}
Expand Down Expand Up @@ -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<Either<PgDone, PgRow>, Error>>
) -> BoxStream<'e, Result<Either<PgOutcome, PgRow>, Error>>
where
'c: 'e,
E: Execute<'q, Self::Database>,
Expand Down
Loading

0 comments on commit ee93882

Please sign in to comment.