Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the Done trait, rename DbDone to DbOutcome #976

Merged
merged 2 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]]

## 0.4.2 - 2020-12-19

- [[#908]] Fix `whoami` crash on FreeBSD platform [[@fundon]] [[@AldaronLau]]
Expand Down
1 change: 0 additions & 1 deletion examples/mysql/todos/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use sqlx::mysql::MySqlPool;
use sqlx::Done;
use std::env;
use structopt::StructOpt;

Expand Down
1 change: 0 additions & 1 deletion examples/postgres/mockable-todos/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
1 change: 0 additions & 1 deletion examples/postgres/todos/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use sqlx::postgres::PgPool;
use sqlx::Done;
use std::env;
use structopt::StructOpt;

Expand Down
1 change: 0 additions & 1 deletion examples/sqlite/todos/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use sqlx::sqlite::SqlitePool;
use sqlx::Done;
use std::env;
use structopt::StructOpt;

Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/any/connection/executor.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Either<AnyDone, AnyRow>, Error>>
) -> BoxStream<'e, Result<Either<AnyOutcome, AnyRow>, Error>>
where
'c: 'e,
E: Execute<'q, Self::Database>,
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
22 changes: 8 additions & 14 deletions sqlx-core/src/any/done.rs → sqlx-core/src/any/outcome.rs
Original file line number Diff line number Diff line change
@@ -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<i64>,
}

impl AnyDone {
pub fn last_insert_id(&self) -> Option<i64> {
self.last_insert_id
impl AnyOutcome {
pub fn rows_affected(&self) -> u64 {
self.rows_affected
}
}

impl Done for AnyDone {
type Database = Any;

fn rows_affected(&self) -> u64 {
self.rows_affected
pub fn last_insert_id(&self) -> Option<i64> {
self.last_insert_id
}
}

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
5 changes: 2 additions & 3 deletions sqlx-core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,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: Done<Database = Self>;
/// The concrete `Outcome` implementation for this database.
type Outcome: 'static + Sized + Send + Sync + Default + Extend<Self::Outcome>;

/// The concrete `Column` implementation for this database.
type Column: Column<Database = Self>;
Expand Down
9 changes: 0 additions & 9 deletions sqlx-core/src/done.rs

This file was deleted.

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
1 change: 0 additions & 1 deletion sqlx-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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
34 changes: 0 additions & 34 deletions sqlx-core/src/mssql/done.rs

This file was deleted.

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,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;
Expand Down
30 changes: 30 additions & 0 deletions sqlx-core/src/mssql/outcome.rs
Original file line number Diff line number Diff line change
@@ -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<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<MssqlOutcome> for crate::any::AnyOutcome {
fn from(done: MssqlOutcome) -> Self {
crate::any::AnyOutcome {
rows_affected: done.rows_affected,
last_insert_id: None,
}
}
}
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
Loading