From a1d562f04b14f3217766e4dd38af865ae42b24d0 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 12 Jan 2021 13:17:13 +0100 Subject: [PATCH 01/18] Remove the Done trait --- CHANGELOG.md | 3 +++ examples/mysql/todos/src/main.rs | 1 - examples/postgres/mockable-todos/src/main.rs | 1 - examples/postgres/todos/src/main.rs | 1 - examples/sqlite/todos/src/main.rs | 1 - sqlx-core/src/any/done.rs | 14 ++++---------- sqlx-core/src/database.rs | 3 +-- sqlx-core/src/done.rs | 9 --------- sqlx-core/src/lib.rs | 1 - sqlx-core/src/mssql/done.rs | 8 ++------ sqlx-core/src/mysql/done.rs | 8 +------- sqlx-core/src/postgres/done.rs | 8 ++------ sqlx-core/src/sqlite/done.rs | 14 ++++---------- src/lib.rs | 2 -- src/macros.rs | 2 +- tests/mssql/mssql.rs | 2 +- tests/mysql/mysql.rs | 2 +- tests/postgres/postgres.rs | 2 +- tests/sqlite/sqlite.rs | 4 ++-- 19 files changed, 23 insertions(+), 63 deletions(-) delete mode 100644 sqlx-core/src/done.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 52b3fd5d1..41b33b31a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,9 @@ 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]] Remove the `Done` trait. The `.rows_affected()` method is now available as an inherent + method on `PgDone`, `MySqlDone` and so on. + ## 0.4.2 - 2020-12-19 - [[#908]] Fix `whoami` crash on FreeBSD platform [[@fundon]] [[@AldaronLau]] 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/done.rs b/sqlx-core/src/any/done.rs index d91e77339..fb5957429 100644 --- a/sqlx-core/src/any/done.rs +++ b/sqlx-core/src/any/done.rs @@ -1,5 +1,3 @@ -use crate::any::Any; -use crate::done::Done; use std::iter::{Extend, IntoIterator}; #[derive(Debug, Default)] @@ -9,19 +7,15 @@ pub struct AnyDone { } impl AnyDone { + 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) { for elem in iter { diff --git a/sqlx-core/src/database.rs b/sqlx-core/src/database.rs index 870898327..5ace6d87a 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; @@ -88,7 +87,7 @@ pub trait Database: type Row: Row; /// The concrete `Done` implementation for this database. - type Done: Done; + type Done: '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/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/done.rs b/sqlx-core/src/mssql/done.rs index dfe308db2..11b78fb67 100644 --- a/sqlx-core/src/mssql/done.rs +++ b/sqlx-core/src/mssql/done.rs @@ -1,5 +1,3 @@ -use crate::done::Done; -use crate::mssql::Mssql; use std::iter::{Extend, IntoIterator}; #[derive(Debug, Default)] @@ -7,10 +5,8 @@ pub struct MssqlDone { pub(super) rows_affected: u64, } -impl Done for MssqlDone { - type Database = Mssql; - - fn rows_affected(&self) -> u64 { +impl MssqlDone { + pub fn rows_affected(&self) -> u64 { self.rows_affected } } diff --git a/sqlx-core/src/mysql/done.rs b/sqlx-core/src/mysql/done.rs index 45e3a6f23..c39be3940 100644 --- a/sqlx-core/src/mysql/done.rs +++ b/sqlx-core/src/mysql/done.rs @@ -1,5 +1,3 @@ -use crate::done::Done; -use crate::mysql::MySql; use std::iter::{Extend, IntoIterator}; #[derive(Debug, Default)] @@ -12,12 +10,8 @@ impl MySqlDone { 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 } } diff --git a/sqlx-core/src/postgres/done.rs b/sqlx-core/src/postgres/done.rs index 05be76e2f..c47060906 100644 --- a/sqlx-core/src/postgres/done.rs +++ b/sqlx-core/src/postgres/done.rs @@ -1,5 +1,3 @@ -use crate::done::Done; -use crate::postgres::Postgres; use std::iter::{Extend, IntoIterator}; #[derive(Debug, Default)] @@ -7,10 +5,8 @@ pub struct PgDone { pub(super) rows_affected: u64, } -impl Done for PgDone { - type Database = Postgres; - - fn rows_affected(&self) -> u64 { +impl PgDone { + pub fn rows_affected(&self) -> u64 { self.rows_affected } } diff --git a/sqlx-core/src/sqlite/done.rs b/sqlx-core/src/sqlite/done.rs index 55c68d7de..cdbe9450e 100644 --- a/sqlx-core/src/sqlite/done.rs +++ b/sqlx-core/src/sqlite/done.rs @@ -1,5 +1,3 @@ -use crate::done::Done; -use crate::sqlite::Sqlite; use std::iter::{Extend, IntoIterator}; #[derive(Debug, Default)] @@ -9,19 +7,15 @@ pub struct SqliteDone { } impl SqliteDone { + 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) { for elem in iter { 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..98b34abdc 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`. 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. | 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 1cbf9e6c9..0e8c8bf39 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; From 08a76f45ae06faaced3316232d8d66488a7324ba Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 12 Jan 2021 13:44:03 +0100 Subject: [PATCH 02/18] Rename DbDone to DbOutcome --- 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/{done.rs => outcome.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 ++-- .../src/{postgres/done.rs => mssql/outcome.rs} | 14 +++++++------- sqlx-core/src/mysql/connection/executor.rs | 10 +++++----- sqlx-core/src/mysql/database.rs | 4 ++-- sqlx-core/src/mysql/mod.rs | 4 ++-- sqlx-core/src/mysql/{done.rs => outcome.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 ++-- .../src/{mssql/done.rs => postgres/outcome.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 ++-- sqlx-core/src/sqlite/{done.rs => outcome.rs} | 14 +++++++------- sqlx-core/src/transaction.rs | 2 +- src/macros.rs | 4 ++-- 30 files changed, 91 insertions(+), 89 deletions(-) rename sqlx-core/src/any/{done.rs => outcome.rs} (74%) rename sqlx-core/src/{postgres/done.rs => mssql/outcome.rs} (57%) rename sqlx-core/src/mysql/{done.rs => outcome.rs} (67%) rename sqlx-core/src/{mssql/done.rs => postgres/outcome.rs} (60%) rename sqlx-core/src/sqlite/{done.rs => outcome.rs} (65%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41b33b31a..e73b805f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 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 74% rename from sqlx-core/src/any/done.rs rename to sqlx-core/src/any/outcome.rs index fb5957429..97deadd99 100644 --- a/sqlx-core/src/any/done.rs +++ b/sqlx-core/src/any/outcome.rs @@ -1,12 +1,12 @@ 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 } @@ -16,8 +16,8 @@ impl AnyDone { } } -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 5ace6d87a..e8625785a 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 `Done` implementation for this database. - type Done: 'static + Sized + Send + Sync + Default + Extend; + /// 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/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/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/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/postgres/done.rs b/sqlx-core/src/mssql/outcome.rs similarity index 57% rename from sqlx-core/src/postgres/done.rs rename to sqlx-core/src/mssql/outcome.rs index c47060906..ddb2b2cb6 100644 --- a/sqlx-core/src/postgres/done.rs +++ b/sqlx-core/src/mssql/outcome.rs @@ -1,18 +1,18 @@ use std::iter::{Extend, IntoIterator}; #[derive(Debug, Default)] -pub struct PgDone { +pub struct MssqlOutcome { pub(super) rows_affected: u64, } -impl PgDone { +impl MssqlOutcome { pub fn rows_affected(&self) -> u64 { self.rows_affected } } -impl Extend for PgDone { - fn extend>(&mut self, iter: T) { +impl Extend for MssqlOutcome { + fn extend>(&mut self, iter: T) { for elem in iter { self.rows_affected += elem.rows_affected; } @@ -20,9 +20,9 @@ impl Extend for PgDone { } #[cfg(feature = "any")] -impl From for crate::any::AnyDone { - fn from(done: PgDone) -> Self { - crate::any::AnyDone { +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 67% rename from sqlx-core/src/mysql/done.rs rename to sqlx-core/src/mysql/outcome.rs index c39be3940..7267f98d6 100644 --- a/sqlx-core/src/mysql/done.rs +++ b/sqlx-core/src/mysql/outcome.rs @@ -1,12 +1,12 @@ 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 } @@ -16,8 +16,8 @@ impl MySqlDone { } } -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; @@ -26,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/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/mssql/done.rs b/sqlx-core/src/postgres/outcome.rs similarity index 60% rename from sqlx-core/src/mssql/done.rs rename to sqlx-core/src/postgres/outcome.rs index 11b78fb67..c8177d5ba 100644 --- a/sqlx-core/src/mssql/done.rs +++ b/sqlx-core/src/postgres/outcome.rs @@ -1,18 +1,18 @@ use std::iter::{Extend, IntoIterator}; #[derive(Debug, Default)] -pub struct MssqlDone { +pub struct PgOutcome { pub(super) rows_affected: u64, } -impl MssqlDone { +impl PgOutcome { pub fn rows_affected(&self) -> u64 { self.rows_affected } } -impl Extend for MssqlDone { - fn extend>(&mut self, iter: T) { +impl Extend for PgOutcome { + fn extend>(&mut self, iter: T) { for elem in iter { self.rows_affected += elem.rows_affected; } @@ -20,9 +20,9 @@ impl Extend for MssqlDone { } #[cfg(feature = "any")] -impl From for crate::any::AnyDone { - fn from(done: MssqlDone) -> Self { - crate::any::AnyDone { +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 65% rename from sqlx-core/src/sqlite/done.rs rename to sqlx-core/src/sqlite/outcome.rs index cdbe9450e..78001bf77 100644 --- a/sqlx-core/src/sqlite/done.rs +++ b/sqlx-core/src/sqlite/outcome.rs @@ -1,12 +1,12 @@ 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 } @@ -16,8 +16,8 @@ impl SqliteDone { } } -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; @@ -26,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/macros.rs b/src/macros.rs index 98b34abdc..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`. | +/// | 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 From a6aef7817b4be38fb5acf5ebd57054c092223092 Mon Sep 17 00:00:00 2001 From: Takeru Ohta Date: Wed, 13 Jan 2021 21:18:10 +0900 Subject: [PATCH 03/18] fix to read just 20 bytes for AuthSwitchRequest data --- sqlx-core/src/mysql/protocol/connect/auth_switch.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sqlx-core/src/mysql/protocol/connect/auth_switch.rs b/sqlx-core/src/mysql/protocol/connect/auth_switch.rs index da0cc5506..757411f56 100644 --- a/sqlx-core/src/mysql/protocol/connect/auth_switch.rs +++ b/sqlx-core/src/mysql/protocol/connect/auth_switch.rs @@ -25,7 +25,16 @@ impl Decode<'_> for AuthSwitchRequest { } let plugin = buf.get_str_nul()?.parse()?; - let data = buf.get_bytes(buf.len()); + + // See: https://github.com/mysql/mysql-server/blob/ea7d2e2d16ac03afdd9cb72a972a95981107bf51/sql/auth/sha2_password.cc#L942 + if buf.len() != 21 { + return Err(err_protocol!( + "expected 21 bytes but found {} bytes", + buf.len() + )); + } + let data = buf.get_bytes(20); + buf.advance(1); // NUL-terminator Ok(Self { plugin, data }) } From 1966bd5aebbb0a18c2225cdac927980e227d38af Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 29 Dec 2020 19:46:10 +0100 Subject: [PATCH 04/18] Clean up some import grouping / ordering --- sqlx-macros/src/query/data.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sqlx-macros/src/query/data.rs b/sqlx-macros/src/query/data.rs index 9af35a485..33055816f 100644 --- a/sqlx-macros/src/query/data.rs +++ b/sqlx-macros/src/query/data.rs @@ -36,15 +36,15 @@ impl QueryData { #[cfg(feature = "offline")] pub mod offline { use super::QueryData; - use std::fs::File; + use crate::database::DatabaseExt; use std::fmt::{self, Formatter}; + use std::fs::File; + use std::path::Path; - use crate::database::DatabaseExt; use proc_macro2::Span; use serde::de::{Deserializer, IgnoredAny, MapAccess, Visitor}; use sqlx_core::describe::Describe; - use std::path::Path; #[derive(serde::Deserialize)] pub struct DynQueryData { From 1e71237c040bf3a134c47d2073fcd7430cac24ed Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 29 Dec 2020 19:48:42 +0100 Subject: [PATCH 05/18] [offline] Use buffering for JSON file reading / writing --- sqlx-cli/src/prepare.rs | 5 ++++- sqlx-macros/src/query/data.rs | 11 +++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/sqlx-cli/src/prepare.rs b/sqlx-cli/src/prepare.rs index 95df2c546..fa166f68b 100644 --- a/sqlx-cli/src/prepare.rs +++ b/sqlx-cli/src/prepare.rs @@ -5,6 +5,7 @@ use remove_dir_all::remove_dir_all; use sqlx::any::{AnyConnectOptions, AnyKind}; use std::collections::BTreeMap; use std::fs::File; +use std::io::BufWriter; use std::process::Command; use std::str::FromStr; use std::time::SystemTime; @@ -32,7 +33,9 @@ pub fn run(url: &str, merge: bool, cargo_args: Vec) -> anyhow::Result<() } serde_json::to_writer_pretty( - File::create("sqlx-data.json").context("failed to create/open `sqlx-data.json`")?, + BufWriter::new( + File::create("sqlx-data.json").context("failed to create/open `sqlx-data.json`")?, + ), &DataFile { db: db_kind, data }, ) .context("failed to write to `sqlx-data.json`")?; diff --git a/sqlx-macros/src/query/data.rs b/sqlx-macros/src/query/data.rs index 33055816f..ee123b503 100644 --- a/sqlx-macros/src/query/data.rs +++ b/sqlx-macros/src/query/data.rs @@ -40,6 +40,7 @@ pub mod offline { use std::fmt::{self, Formatter}; use std::fs::File; + use std::io::{BufReader, BufWriter}; use std::path::Path; use proc_macro2::Span; @@ -60,11 +61,11 @@ pub mod offline { /// Find and deserialize the data table for this query from a shared `sqlx-data.json` /// file. The expected structure is a JSON map keyed by the SHA-256 hash of queries in hex. pub fn from_data_file(path: impl AsRef, query: &str) -> crate::Result { - serde_json::Deserializer::from_reader( + serde_json::Deserializer::from_reader(BufReader::new( File::open(path.as_ref()).map_err(|e| { format!("failed to open path {}: {}", path.as_ref().display(), e) })?, - ) + )) .deserialize_map(DataFileVisitor { query, hash: hash_string(query), @@ -107,8 +108,10 @@ pub mod offline { )); serde_json::to_writer_pretty( - File::create(&path) - .map_err(|e| format!("failed to open path {}: {}", path.display(), e))?, + BufWriter::new( + File::create(&path) + .map_err(|e| format!("failed to open path {}: {}", path.display(), e))?, + ), self, ) .map_err(Into::into) From e6af514df693887be527e034593420272a9194df Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 30 Dec 2020 14:07:11 +0100 Subject: [PATCH 06/18] [offline] Don't read sqlx-data.json into a String before parsing --- sqlx-cli/src/prepare.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sqlx-cli/src/prepare.rs b/sqlx-cli/src/prepare.rs index fa166f68b..2eba3084d 100644 --- a/sqlx-cli/src/prepare.rs +++ b/sqlx-cli/src/prepare.rs @@ -5,7 +5,7 @@ use remove_dir_all::remove_dir_all; use sqlx::any::{AnyConnectOptions, AnyKind}; use std::collections::BTreeMap; use std::fs::File; -use std::io::BufWriter; +use std::io::{BufReader, BufWriter}; use std::process::Command; use std::str::FromStr; use std::time::SystemTime; @@ -52,11 +52,11 @@ pub fn check(url: &str, merge: bool, cargo_args: Vec) -> anyhow::Result< let db_kind = get_db_kind(url)?; let data = run_prepare_step(merge, cargo_args)?; - let data_file = fs::read("sqlx-data.json").context( + let data_file = File::open("sqlx-data.json").context( "failed to open `sqlx-data.json`; you may need to run `cargo sqlx prepare` first", )?; - let mut saved_data: QueryData = serde_json::from_slice(&data_file)?; + let mut saved_data: QueryData = serde_json::from_reader(BufReader::new(data_file))?; let expected_db = saved_data .remove("db") From a1e9ce638b61d440ff668ff70d00ed875c7bf022 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 30 Dec 2020 14:16:25 +0100 Subject: [PATCH 07/18] Clean up imports in sqlx_macros::query --- sqlx-macros/src/query/mod.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/sqlx-macros/src/query/mod.rs b/sqlx-macros/src/query/mod.rs index be7e37d0d..4f3b5c4e3 100644 --- a/sqlx-macros/src/query/mod.rs +++ b/sqlx-macros/src/query/mod.rs @@ -1,5 +1,6 @@ +use std::borrow::Cow; use std::env; -use std::{borrow::Cow, path::PathBuf}; +use std::path::{Path, PathBuf}; use proc_macro2::{Span, TokenStream}; use syn::Type; @@ -45,7 +46,7 @@ pub fn expand_input(input: QueryMacroInput) -> crate::Result { // If a .env file exists at CARGO_MANIFEST_DIR, load environment variables from this, // otherwise fallback to default dotenv behaviour. - let env_path = std::path::Path::new(&manifest_dir).join(".env"); + let env_path = Path::new(&manifest_dir).join(".env"); if env_path.exists() { dotenv::from_path(&env_path) .map_err(|e| format!("failed to load environment from {:?}, {}", env_path, e))? @@ -62,7 +63,7 @@ pub fn expand_input(input: QueryMacroInput) -> crate::Result { #[cfg(feature = "offline")] _ => { - let data_file_path = std::path::Path::new(&manifest_dir).join("sqlx-data.json"); + let data_file_path = Path::new(&manifest_dir).join("sqlx-data.json"); let workspace_data_file_path = CRATE_ROOT.join("sqlx-data.json"); @@ -153,10 +154,7 @@ fn expand_from_db(input: QueryMacroInput, db_url: &str) -> crate::Result crate::Result { +pub fn expand_from_file(input: QueryMacroInput, file: PathBuf) -> crate::Result { use data::offline::DynQueryData; let query_data = DynQueryData::from_data_file(file, &input.src)?; @@ -309,9 +307,8 @@ where // If the build is offline, the cache is our input so it's pointless to also write data for it. #[cfg(feature = "offline")] if !offline { - let mut save_dir = std::path::PathBuf::from( - env::var("CARGO_TARGET_DIR").unwrap_or_else(|_| "target/".into()), - ); + let mut save_dir = + PathBuf::from(env::var("CARGO_TARGET_DIR").unwrap_or_else(|_| "target/".into())); save_dir.push("sqlx"); From 686b227ac117cda3c70a7fe9dd4f866bf518bef0 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 30 Dec 2020 14:18:08 +0100 Subject: [PATCH 08/18] Add recommended merge behaviour settings for VSCode + rust-analyzer --- contrib/ide/vscode/settings.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 contrib/ide/vscode/settings.json diff --git a/contrib/ide/vscode/settings.json b/contrib/ide/vscode/settings.json new file mode 100644 index 000000000..3d1cbfd8a --- /dev/null +++ b/contrib/ide/vscode/settings.json @@ -0,0 +1,3 @@ +{ + "rust-analyzer.assist.importMergeBehaviour": "last" +} From 890f289f2f22a4242f7e52d6ad95235c673043d3 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 30 Dec 2020 15:19:06 +0100 Subject: [PATCH 09/18] Fix docs for cargo sqlx prepare --- sqlx-cli/src/opt.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sqlx-cli/src/opt.rs b/sqlx-cli/src/opt.rs index 839b33b87..594981ef7 100644 --- a/sqlx-cli/src/opt.rs +++ b/sqlx-cli/src/opt.rs @@ -20,8 +20,8 @@ pub enum Command { /// in the current directory, overwriting if needed. /// /// During project compilation, the absence of the `DATABASE_URL` environment variable or - /// the presence of `SQLX_OFFLINE` will constrain the compile-time verification to only - /// read from the cached query metadata. + /// the presence of `SQLX_OFFLINE` (with a value of `true` or `1`) will constrain the + /// compile-time verification to only read from the cached query metadata. #[clap(alias = "prep")] Prepare { /// Run in 'check' mode. Exits with 0 if the query metadata is up-to-date. Exits with From e8c367db6ec011d44b4a9f9163baffa41d0520d9 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 11 Jan 2021 21:08:40 +0100 Subject: [PATCH 10/18] sqlx-macros: Replace lazy_static by once_cell --- Cargo.lock | 2 +- sqlx-macros/Cargo.toml | 2 +- sqlx-macros/src/query/mod.rs | 21 +++++++++------------ 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 90564d147..a617219c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2666,7 +2666,7 @@ dependencies = [ "futures", "heck", "hex", - "lazy_static", + "once_cell", "proc-macro2", "quote", "serde", diff --git a/sqlx-macros/Cargo.toml b/sqlx-macros/Cargo.toml index 420779666..9437065f5 100644 --- a/sqlx-macros/Cargo.toml +++ b/sqlx-macros/Cargo.toml @@ -59,7 +59,7 @@ futures = { version = "0.3.4", default-features = false, features = [ "executor" hex = { version = "0.4.2", optional = true } heck = "0.3.1" either = "1.5.3" -lazy_static = "1.4.0" +once_cell = "1.5.2" proc-macro2 = { version = "1.0.9", default-features = false } sqlx-core = { version = "0.4.2", default-features = false, path = "../sqlx-core" } sqlx-rt = { version = "0.2.0", default-features = false, path = "../sqlx-rt" } diff --git a/sqlx-macros/src/query/mod.rs b/sqlx-macros/src/query/mod.rs index 4f3b5c4e3..11514fcfd 100644 --- a/sqlx-macros/src/query/mod.rs +++ b/sqlx-macros/src/query/mod.rs @@ -17,7 +17,7 @@ use crate::database::DatabaseExt; use crate::query::data::QueryData; use crate::query::input::RecordType; use either::Either; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; mod args; mod data; @@ -26,19 +26,16 @@ mod output; // If we are in a workspace, lookup `workspace_root` since `CARGO_MANIFEST_DIR` won't // reflect the workspace dir: https://github.com/rust-lang/cargo/issues/3946 -lazy_static! { - static ref CRATE_ROOT: PathBuf = { - let manifest_dir = - env::var("CARGO_MANIFEST_DIR").expect("`CARGO_MANIFEST_DIR` must be set"); +static CRATE_ROOT: Lazy = Lazy::new(|| { + let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("`CARGO_MANIFEST_DIR` must be set"); - let metadata = cargo_metadata::MetadataCommand::new() - .current_dir(manifest_dir) - .exec() - .expect("Could not fetch metadata"); + let metadata = cargo_metadata::MetadataCommand::new() + .current_dir(manifest_dir) + .exec() + .expect("Could not fetch metadata"); - metadata.workspace_root - }; -} + metadata.workspace_root +}); pub fn expand_input(input: QueryMacroInput) -> crate::Result { let manifest_dir = From 8d0a1e9146ecf8be34f836f38a3fcffa861e6b48 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 11 Jan 2021 21:27:42 +0100 Subject: [PATCH 11/18] Remove cargo_metadata dependency It was not pulling its weight. Just look at that Cargo.lock diff! --- Cargo.lock | 203 ++++------------------------------- sqlx-cli/Cargo.toml | 3 +- sqlx-cli/src/prepare.rs | 19 +++- sqlx-macros/Cargo.toml | 9 +- sqlx-macros/src/query/mod.rs | 17 ++- 5 files changed, 53 insertions(+), 198 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a617219c7..1c78ec74b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -341,34 +341,13 @@ dependencies = [ "wyz", ] -[[package]] -name = "block-buffer" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" -dependencies = [ - "block-padding", - "byte-tools", - "byteorder", - "generic-array 0.12.3", -] - [[package]] name = "block-buffer" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "generic-array 0.14.4", -] - -[[package]] -name = "block-padding" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" -dependencies = [ - "byte-tools", + "generic-array", ] [[package]] @@ -409,12 +388,6 @@ version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" -[[package]] -name = "byte-tools" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" - [[package]] name = "byteorder" version = "1.3.4" @@ -433,30 +406,6 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" -[[package]] -name = "cargo_metadata" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8de60b887edf6d74370fc8eb177040da4847d971d6234c7b13a6da324ef0caf" -dependencies = [ - "semver 0.9.0", - "serde", - "serde_derive", - "serde_json", -] - -[[package]] -name = "cargo_metadata" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83f95cf4bf0dda0ac2e65371ae7215d0dce3c187613a9dbf23aaa9374186f97a" -dependencies = [ - "semver 0.11.0", - "semver-parser 0.10.0", - "serde", - "serde_json", -] - [[package]] name = "cast" version = "0.2.3" @@ -730,7 +679,7 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4857fd85a0c34b3c3297875b747c1e02e06b6a0ea32dd892d8192b9ce0813ea6" dependencies = [ - "generic-array 0.14.4", + "generic-array", "subtle", ] @@ -785,22 +734,13 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" -[[package]] -name = "digest" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" -dependencies = [ - "generic-array 0.12.3", -] - [[package]] name = "digest" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array 0.14.4", + "generic-array", ] [[package]] @@ -864,12 +804,6 @@ version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" -[[package]] -name = "fake-simd" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" - [[package]] name = "fastrand" version = "1.4.0" @@ -1057,15 +991,6 @@ dependencies = [ "slab", ] -[[package]] -name = "generic-array" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" -dependencies = [ - "typenum", -] - [[package]] name = "generic-array" version = "0.14.4" @@ -1185,7 +1110,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15" dependencies = [ "crypto-mac", - "digest 0.9.0", + "digest", ] [[package]] @@ -1414,9 +1339,9 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b5a279bb9607f9f53c22d496eade00d138d1bdcccd07d74650387cf94942a15" dependencies = [ - "block-buffer 0.9.0", - "digest 0.9.0", - "opaque-debug 0.3.0", + "block-buffer", + "digest", + "opaque-debug", ] [[package]] @@ -1675,12 +1600,6 @@ version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" -[[package]] -name = "opaque-debug" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" - [[package]] name = "opaque-debug" version = "0.3.0" @@ -1817,49 +1736,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" -[[package]] -name = "pest" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" -dependencies = [ - "ucd-trie", -] - -[[package]] -name = "pest_derive" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0" -dependencies = [ - "pest", - "pest_generator", -] - -[[package]] -name = "pest_generator" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99b8db626e31e5b81787b9783425769681b347011cc59471e33ea46d2ea0cf55" -dependencies = [ - "pest", - "pest_meta", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pest_meta" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d" -dependencies = [ - "maplit", - "pest", - "sha-1 0.8.2", -] - [[package]] name = "pin-project" version = "1.0.2" @@ -2172,7 +2048,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3648b669b10afeab18972c105e284a7b953a669b0be3514c27f9b17acab2f9cd" dependencies = [ "byteorder", - "digest 0.9.0", + "digest", "lazy_static", "num-bigint-dig", "num-integer", @@ -2203,7 +2079,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" dependencies = [ - "semver 0.9.0", + "semver", ] [[package]] @@ -2289,18 +2165,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" dependencies = [ - "semver-parser 0.7.0", - "serde", -] - -[[package]] -name = "semver" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" -dependencies = [ - "semver-parser 0.10.0", - "serde", + "semver-parser", ] [[package]] @@ -2309,16 +2174,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -[[package]] -name = "semver-parser" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e012c6c5380fb91897ba7b9261a0f565e624e869d42fe1a1d03fa0d68a083d5" -dependencies = [ - "pest", - "pest_derive", -] - [[package]] name = "serde" version = "1.0.118" @@ -2361,29 +2216,17 @@ dependencies = [ "serde", ] -[[package]] -name = "sha-1" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" -dependencies = [ - "block-buffer 0.7.3", - "digest 0.8.1", - "fake-simd", - "opaque-debug 0.2.3", -] - [[package]] name = "sha-1" version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce3cdf1b5e620a498ee6f2a171885ac7e22f0e12089ec4b3d22b84921792507c" dependencies = [ - "block-buffer 0.9.0", + "block-buffer", "cfg-if 1.0.0", "cpuid-bool", - "digest 0.9.0", - "opaque-debug 0.3.0", + "digest", + "opaque-debug", ] [[package]] @@ -2398,11 +2241,11 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e7aab86fe2149bad8c507606bdb3f4ef5e7b2380eb92350f56122cca72a42a8" dependencies = [ - "block-buffer 0.9.0", + "block-buffer", "cfg-if 1.0.0", "cpuid-bool", - "digest 0.9.0", - "opaque-debug 0.3.0", + "digest", + "opaque-debug", ] [[package]] @@ -2516,7 +2359,6 @@ version = "0.2.0" dependencies = [ "anyhow", "async-trait", - "cargo_metadata 0.10.0", "chrono", "clap 3.0.0-beta.2", "console 0.11.3", @@ -2551,13 +2393,13 @@ dependencies = [ "crossbeam-channel", "crossbeam-queue", "crossbeam-utils", - "digest 0.9.0", + "digest", "either", "encoding_rs", "futures-channel", "futures-core", "futures-util", - "generic-array 0.14.4", + "generic-array", "git2", "hashlink", "hex", @@ -2580,7 +2422,7 @@ dependencies = [ "rustls", "serde", "serde_json", - "sha-1 0.9.2", + "sha-1", "sha2", "smallvec", "sqlformat", @@ -2660,7 +2502,6 @@ dependencies = [ name = "sqlx-macros" version = "0.4.2" dependencies = [ - "cargo_metadata 0.12.1", "dotenv", "either", "futures", @@ -3116,12 +2957,6 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" -[[package]] -name = "ucd-trie" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" - [[package]] name = "unicode-bidi" version = "0.3.4" diff --git a/sqlx-cli/Cargo.toml b/sqlx-cli/Cargo.toml index 7547a4e00..a7ac3df42 100644 --- a/sqlx-cli/Cargo.toml +++ b/sqlx-cli/Cargo.toml @@ -37,9 +37,8 @@ async-trait = "0.1.30" console = "0.11.3" dialoguer = "0.7.1" serde_json = { version = "1.0.53", features = ["preserve_order"] } -serde = "1.0.110" +serde = { version = "1.0.110", features = ["derive"] } glob = "0.3.0" -cargo_metadata = "0.10.0" openssl = { version = "0.10.30", optional = true } # workaround for https://github.com/rust-lang/rust/issues/29497 remove_dir_all = "0.6.0" diff --git a/sqlx-cli/src/prepare.rs b/sqlx-cli/src/prepare.rs index 2eba3084d..7d643ee21 100644 --- a/sqlx-cli/src/prepare.rs +++ b/sqlx-cli/src/prepare.rs @@ -1,11 +1,12 @@ use anyhow::{bail, Context}; -use cargo_metadata::MetadataCommand; use console::style; use remove_dir_all::remove_dir_all; +use serde::Deserialize; use sqlx::any::{AnyConnectOptions, AnyKind}; use std::collections::BTreeMap; use std::fs::File; use std::io::{BufReader, BufWriter}; +use std::path::PathBuf; use std::process::Command; use std::str::FromStr; use std::time::SystemTime; @@ -86,10 +87,18 @@ fn run_prepare_step(merge: bool, cargo_args: Vec) -> anyhow::Result = Lazy::new(|| { let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("`CARGO_MANIFEST_DIR` must be set"); - let metadata = cargo_metadata::MetadataCommand::new() + let cargo = env::var_os("CARGO").expect("`CARGO` must be set"); + + let output = Command::new(&cargo) + .args(&["metadata", "--format-version=1"]) .current_dir(manifest_dir) - .exec() + .output() .expect("Could not fetch metadata"); + #[derive(Deserialize)] + struct Metadata { + workspace_root: PathBuf, + } + + let metadata: Metadata = + serde_json::from_slice(&output.stdout).expect("Invalid `cargo metadata` output"); + metadata.workspace_root }); From 1d87b6cc8dc7263d8ae04f2ef772c2393e5910a3 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Mon, 21 Dec 2020 18:12:21 +0100 Subject: [PATCH 12/18] feat: implement unsigned int support for sqlite --- sqlx-core/src/sqlite/types/mod.rs | 6 ++ sqlx-core/src/sqlite/types/uint.rs | 104 +++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 sqlx-core/src/sqlite/types/uint.rs diff --git a/sqlx-core/src/sqlite/types/mod.rs b/sqlx-core/src/sqlite/types/mod.rs index cafae4840..bf67ab0b6 100644 --- a/sqlx-core/src/sqlite/types/mod.rs +++ b/sqlx-core/src/sqlite/types/mod.rs @@ -5,9 +5,14 @@ //! | Rust type | SQLite type(s) | //! |---------------------------------------|------------------------------------------------------| //! | `bool` | BOOLEAN | +//! | `i8` | INTEGER | //! | `i16` | INTEGER | //! | `i32` | INTEGER | //! | `i64` | BIGINT, INT8 | +//! | `u8` | INTEGER | +//! | `u16` | INTEGER | +//! | `u32` | INTEGER | +//! | `i64` | BIGINT, INT8 | //! | `f32` | REAL | //! | `f64` | REAL | //! | `&str`, [`String`] | TEXT | @@ -47,5 +52,6 @@ mod int; #[cfg(feature = "json")] mod json; mod str; +mod uint; #[cfg(feature = "uuid")] mod uuid; diff --git a/sqlx-core/src/sqlite/types/uint.rs b/sqlx-core/src/sqlite/types/uint.rs new file mode 100644 index 000000000..b6e22e0eb --- /dev/null +++ b/sqlx-core/src/sqlite/types/uint.rs @@ -0,0 +1,104 @@ +use std::convert::TryInto; + +use crate::decode::Decode; +use crate::encode::{Encode, IsNull}; +use crate::error::BoxDynError; +use crate::sqlite::type_info::DataType; +use crate::sqlite::{Sqlite, SqliteArgumentValue, SqliteTypeInfo, SqliteValueRef}; +use crate::types::Type; + +impl Type for u8 { + fn type_info() -> SqliteTypeInfo { + SqliteTypeInfo(DataType::Int) + } + + fn compatible(ty: &SqliteTypeInfo) -> bool { + matches!(ty.0, DataType::Int | DataType::Int64) + } +} + +impl<'q> Encode<'q, Sqlite> for u8 { + fn encode_by_ref(&self, args: &mut Vec>) -> IsNull { + args.push(SqliteArgumentValue::Int(*self as i32)); + + IsNull::No + } +} + +impl<'r> Decode<'r, Sqlite> for u8 { + fn decode(value: SqliteValueRef<'r>) -> Result { + Ok(value.int().try_into()?) + } +} + +impl Type for u16 { + fn type_info() -> SqliteTypeInfo { + SqliteTypeInfo(DataType::Int) + } + + fn compatible(ty: &SqliteTypeInfo) -> bool { + matches!(ty.0, DataType::Int | DataType::Int64) + } +} + +impl<'q> Encode<'q, Sqlite> for u16 { + fn encode_by_ref(&self, args: &mut Vec>) -> IsNull { + args.push(SqliteArgumentValue::Int(*self as i32)); + + IsNull::No + } +} + +impl<'r> Decode<'r, Sqlite> for u16 { + fn decode(value: SqliteValueRef<'r>) -> Result { + Ok(value.int().try_into()?) + } +} + +impl Type for u32 { + fn type_info() -> SqliteTypeInfo { + SqliteTypeInfo(DataType::Int64) + } + + fn compatible(ty: &SqliteTypeInfo) -> bool { + matches!(ty.0, DataType::Int | DataType::Int64) + } +} + +impl<'q> Encode<'q, Sqlite> for u32 { + fn encode_by_ref(&self, args: &mut Vec>) -> IsNull { + args.push(SqliteArgumentValue::Int64(*self as i64)); + + IsNull::No + } +} + +impl<'r> Decode<'r, Sqlite> for u32 { + fn decode(value: SqliteValueRef<'r>) -> Result { + Ok(value.int64().try_into()?) + } +} + +impl Type for u64 { + fn type_info() -> SqliteTypeInfo { + SqliteTypeInfo(DataType::Int64) + } + + fn compatible(ty: &SqliteTypeInfo) -> bool { + matches!(ty.0, DataType::Int | DataType::Int64) + } +} + +impl<'q> Encode<'q, Sqlite> for u64 { + fn encode_by_ref(&self, args: &mut Vec>) -> IsNull { + args.push(SqliteArgumentValue::Int64(*self as i64)); + + IsNull::No + } +} + +impl<'r> Decode<'r, Sqlite> for u64 { + fn decode(value: SqliteValueRef<'r>) -> Result { + Ok(value.int64().try_into()?) + } +} From de4a7decfb760be0018f419f65d28008f57302fa Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Wed, 13 Jan 2021 23:35:31 -0800 Subject: [PATCH 13/18] fix(sqlite): i64 -> u64 in type docs --- sqlx-core/src/sqlite/types/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlx-core/src/sqlite/types/mod.rs b/sqlx-core/src/sqlite/types/mod.rs index bf67ab0b6..1f7dfc50e 100644 --- a/sqlx-core/src/sqlite/types/mod.rs +++ b/sqlx-core/src/sqlite/types/mod.rs @@ -12,7 +12,7 @@ //! | `u8` | INTEGER | //! | `u16` | INTEGER | //! | `u32` | INTEGER | -//! | `i64` | BIGINT, INT8 | +//! | `u64` | BIGINT, INT8 | //! | `f32` | REAL | //! | `f64` | REAL | //! | `&str`, [`String`] | TEXT | From c5d43db31224be9275a7761ce5e694fcb82c3af9 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 14 Jan 2021 13:24:25 +0100 Subject: [PATCH 14/18] Upgrade async runtime dependencies Co-authored-by: Josh Toft Co-authored-by: Philip A Reimer --- Cargo.lock | 274 +++++------------- Cargo.toml | 4 +- examples/mysql/todos/Cargo.toml | 2 +- examples/postgres/listen/Cargo.toml | 2 +- examples/postgres/todos/Cargo.toml | 2 +- examples/sqlite/todos/Cargo.toml | 2 +- sqlx-cli/Cargo.toml | 2 +- sqlx-core/Cargo.toml | 9 +- sqlx-core/src/io/buf.rs | 4 +- sqlx-core/src/migrate/source.rs | 4 + sqlx-core/src/mssql/connection/mod.rs | 24 +- sqlx-core/src/mysql/connection/auth.rs | 2 +- sqlx-core/src/mysql/connection/establish.rs | 2 +- sqlx-core/src/mysql/connection/mod.rs | 2 +- .../src/mysql/protocol/connect/handshake.rs | 6 +- sqlx-core/src/net/mod.rs | 12 + sqlx-core/src/net/socket.rs | 68 ++--- sqlx-core/src/net/tls/mod.rs | 40 +-- sqlx-core/src/postgres/connection/mod.rs | 2 +- sqlx-core/src/postgres/types/bit_vec.rs | 2 +- sqlx-macros/src/lib.rs | 3 +- sqlx-rt/Cargo.toml | 12 +- sqlx-rt/src/lib.rs | 13 +- sqlx-test/Cargo.toml | 4 +- tests/postgres/postgres.rs | 2 +- 25 files changed, 176 insertions(+), 323 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1c78ec74b..084e3fffa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,16 +12,11 @@ dependencies = [ [[package]] name = "actix-rt" -version = "1.1.1" +version = "2.0.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143fcc2912e0d1de2bcf4e2f720d2a60c28652ab4179685a1ee159e0fb3db227" +checksum = "4dfadca59a1d7755a3828708977a2de80b51af0381bd0002ce8f0df3f6091928" dependencies = [ "actix-macros", - "actix-threadpool", - "copyless", - "futures-channel", - "futures-util", - "smallvec", "tokio", ] @@ -72,7 +67,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -152,7 +147,7 @@ dependencies = [ "polling", "vec-arena", "waker-fn", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -189,14 +184,14 @@ dependencies = [ "futures-lite", "once_cell", "signal-hook", - "winapi 0.3.9", + "winapi", ] [[package]] name = "async-rustls" -version = "0.1.2" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f38092e8f467f47aadaff680903c7cbfeee7926b058d7f40af2dd4c878fbdee" +checksum = "9c86f33abd5a4f3e2d6d9251a9e0c6a7e52eb1113caf893dae8429bf4a53f378" dependencies = [ "futures-lite", "rustls", @@ -227,7 +222,7 @@ dependencies = [ "memchr", "num_cpus", "once_cell", - "pin-project-lite 0.2.0", + "pin-project-lite", "pin-utils", "slab", "wasm-bindgen-futures", @@ -273,7 +268,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -294,12 +289,6 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b" -[[package]] -name = "base64" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" - [[package]] name = "base64" version = "0.13.0" @@ -396,9 +385,9 @@ checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" [[package]] name = "bytes" -version = "0.5.6" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" +checksum = "ad1f8e949d755f9d79112b5bb46938e0ef9d3804a0b16dfab13aafcaa5f0fa72" [[package]] name = "cache-padded" @@ -446,7 +435,7 @@ dependencies = [ "num-integer", "num-traits", "time 0.1.44", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -518,7 +507,7 @@ dependencies = [ "terminal_size", "termios", "unicode-width", - "winapi 0.3.9", + "winapi", "winapi-util", ] @@ -534,7 +523,7 @@ dependencies = [ "regex", "terminal_size", "unicode-width", - "winapi 0.3.9", + "winapi", "winapi-util", ] @@ -544,12 +533,6 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd51eab21ab4fd6a3bf889e2d0958c0a6e3a61ad04260325e919e652a2a62826" -[[package]] -name = "copyless" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2df960f5d869b2dd8532793fde43eb5427cceb126c929747a26823ab0eeb536" - [[package]] name = "core-foundation" version = "0.9.1" @@ -822,12 +805,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - [[package]] name = "foreign-types" version = "0.3.2" @@ -859,27 +836,11 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69a039c3498dc930fe810151a34ba0c1c70b02b8625035592e74432f678591f2" -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags", - "fuchsia-zircon-sys", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - [[package]] name = "funty" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ba62103ce691c2fd80fbae2213dfdda9ce60804973ac6b6e97de818ea7f52c8" +checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" [[package]] name = "futures" @@ -940,7 +901,7 @@ dependencies = [ "futures-io", "memchr", "parking", - "pin-project-lite 0.2.0", + "pin-project-lite", "waker-fn", ] @@ -1152,15 +1113,6 @@ dependencies = [ "cfg-if 1.0.0", ] -[[package]] -name = "iovec" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", -] - [[package]] name = "ipnetwork" version = "0.17.0" @@ -1215,16 +1167,6 @@ dependencies = [ "structopt", ] -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - [[package]] name = "kv-log-macro" version = "1.0.7" @@ -1361,56 +1303,15 @@ dependencies = [ [[package]] name = "mio" -version = "0.6.23" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" +checksum = "e50ae3f04d169fcc9bde0b547d1c205219b7157e07ded9c5aff03e0637cb3ed7" dependencies = [ - "cfg-if 0.1.10", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", "libc", "log", - "miow 0.2.2", - "net2", - "slab", - "winapi 0.2.8", -] - -[[package]] -name = "mio-named-pipes" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656" -dependencies = [ - "log", - "mio", - "miow 0.3.6", - "winapi 0.3.9", -] - -[[package]] -name = "mio-uds" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" -dependencies = [ - "iovec", - "libc", - "mio", -] - -[[package]] -name = "miow" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", + "miow", + "ntapi", + "winapi", ] [[package]] @@ -1420,7 +1321,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897" dependencies = [ "socket2", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1475,18 +1376,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8123a81538e457d44b933a02faf885d3fe8408806b23fa700e8f01c6c3a98998" dependencies = [ "libc", - "winapi 0.3.9", -] - -[[package]] -name = "net2" -version = "0.2.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1507,6 +1397,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" +[[package]] +name = "ntapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +dependencies = [ + "winapi", +] + [[package]] name = "num-bigint" version = "0.2.6" @@ -1683,7 +1582,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1725,7 +1624,7 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4c220d01f863d13d96ca82359d1e81e64a7c6bf0637bcde7b2349630addf0c6" dependencies = [ - "base64 0.13.0", + "base64", "once_cell", "regex", ] @@ -1756,12 +1655,6 @@ dependencies = [ "syn", ] -[[package]] -name = "pin-project-lite" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c917123afa01924fc84bb20c4c03f004d9c38e5127e3c039bbf7f4b9c76a2f6b" - [[package]] name = "pin-project-lite" version = "0.2.0" @@ -1802,7 +1695,7 @@ dependencies = [ "libc", "log", "wepoll-sys", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2011,7 +1904,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2023,7 +1916,7 @@ dependencies = [ "log", "num_cpus", "rayon", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2038,7 +1931,7 @@ dependencies = [ "spin", "untrusted", "web-sys", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2084,11 +1977,11 @@ dependencies = [ [[package]] name = "rustls" -version = "0.18.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d1126dcf58e93cee7d098dbda643b5f92ed724f1f6a63007c1116eed6700c81" +checksum = "064fd21ff87c6e87ed4506e68beb42459caa4a0e2eb144932e6776768556980b" dependencies = [ - "base64 0.12.3", + "base64", "log", "ring", "sct", @@ -2117,7 +2010,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" dependencies = [ "lazy_static", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2298,7 +2191,7 @@ checksum = "97e0e9fd577458a4f61fb91fcb559ea2afecc54c934119421f9f5d3d5b1a1057" dependencies = [ "cfg-if 1.0.0", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2381,7 +2274,7 @@ version = "0.4.2" dependencies = [ "ahash 0.6.2", "atoi", - "base64 0.13.0", + "base64", "bigdecimal", "bit-vec", "bitflags", @@ -2430,6 +2323,7 @@ dependencies = [ "stringprep", "thiserror", "time 0.2.23", + "tokio-stream", "url", "uuid", "webpki", @@ -2704,7 +2598,7 @@ dependencies = [ "rand", "redox_syscall", "remove_dir_all 0.5.3", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2723,7 +2617,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bd2d183bd3fac5f5fe38ddbeb4dc9aec4a39a9d7d59e7491d900302da01cbe1" dependencies = [ "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2799,7 +2693,7 @@ checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ "libc", "wasi 0.10.0+wasi-snapshot-preview1", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2814,7 +2708,7 @@ dependencies = [ "stdweb", "time-macros", "version_check", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2867,33 +2761,29 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "0.2.24" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099837d3464c16a808060bb3f02263b412f6fafcb5d01c533d309985fbeebe48" +checksum = "d258221f566b6c803c7b4714abadc080172b272090cdc5e244a6d4dd13c3a6bd" dependencies = [ + "autocfg 1.0.1", "bytes", - "fnv", - "futures-core", - "iovec", - "lazy_static", "libc", "memchr", "mio", - "mio-named-pipes", - "mio-uds", "num_cpus", - "pin-project-lite 0.1.11", + "once_cell", + "parking_lot", + "pin-project-lite", "signal-hook-registry", - "slab", "tokio-macros", - "winapi 0.3.9", + "winapi", ] [[package]] name = "tokio-macros" -version = "0.2.6" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e44da00bfc73a25f814cd8d7e57a68a5c31b74b3152a0a1d1f590c97ed06265a" +checksum = "42517d2975ca3114b22a16192634e8241dc5cc1f130be194645970cc1c371494" dependencies = [ "proc-macro2", "quote", @@ -2902,9 +2792,9 @@ dependencies = [ [[package]] name = "tokio-native-tls" -version = "0.1.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd608593a919a8e05a7d1fc6df885e40f6a88d3a70a3a7eff23ff27964eda069" +checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" dependencies = [ "native-tls", "tokio", @@ -2912,16 +2802,26 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.14.1" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e12831b255bcfa39dc0436b01e19fea231a37db570686c06ee72c423479f889a" +checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6" dependencies = [ - "futures-core", "rustls", "tokio", "webpki", ] +[[package]] +name = "tokio-stream" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76066865172052eb8796c686f0b441a93df8b08d40a950b062ffb9a426f00edd" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "toml" version = "0.5.8" @@ -3060,7 +2960,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" dependencies = [ "same-file", - "winapi 0.3.9", + "winapi", "winapi-util", ] @@ -3190,12 +3090,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - [[package]] name = "winapi" version = "0.3.9" @@ -3206,12 +3100,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -3224,7 +3112,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3233,16 +3121,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - [[package]] name = "wyz" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index 6a9f14e09..b61fd93ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -102,8 +102,8 @@ anyhow = "1.0.31" time_ = { version = "0.2.16", package = "time" } futures = "0.3.5" env_logger = "0.7.1" -async-std = { version = "1.6.0", features = [ "attributes" ] } -tokio = { version = "0.2.21", features = [ "full" ] } +async-std = { version = "1.8.0", features = [ "attributes" ] } +tokio = { version = "1.0.1", features = [ "full" ] } dotenv = "0.15.0" trybuild = "1.0.24" sqlx-rt = { path = "./sqlx-rt" } diff --git a/examples/mysql/todos/Cargo.toml b/examples/mysql/todos/Cargo.toml index 7b2ccc010..017b0fb3a 100644 --- a/examples/mysql/todos/Cargo.toml +++ b/examples/mysql/todos/Cargo.toml @@ -6,7 +6,7 @@ workspace = "../../../" [dependencies] anyhow = "1.0" -async-std = { version = "1.5.0", features = [ "attributes" ] } +async-std = { version = "1.8.0", features = [ "attributes" ] } futures = "0.3" paw = "1.0" sqlx = { path = "../../../", features = [ "mysql", "runtime-async-std-rustls" ] } diff --git a/examples/postgres/listen/Cargo.toml b/examples/postgres/listen/Cargo.toml index a60eec0cc..95c3d7dd0 100644 --- a/examples/postgres/listen/Cargo.toml +++ b/examples/postgres/listen/Cargo.toml @@ -5,6 +5,6 @@ edition = "2018" workspace = "../../../" [dependencies] -async-std = { version = "1.4.0", features = [ "attributes", "unstable" ] } +async-std = { version = "1.8.0", features = [ "attributes", "unstable" ] } sqlx = { path = "../../../", features = [ "postgres", "tls" ] } futures = "0.3.1" diff --git a/examples/postgres/todos/Cargo.toml b/examples/postgres/todos/Cargo.toml index 0654d3be7..10f312d8c 100644 --- a/examples/postgres/todos/Cargo.toml +++ b/examples/postgres/todos/Cargo.toml @@ -6,7 +6,7 @@ workspace = "../../../" [dependencies] anyhow = "1.0" -async-std = { version = "1.4.0", features = [ "attributes" ] } +async-std = { version = "1.8.0", features = [ "attributes" ] } futures = "0.3" paw = "1.0" sqlx = { path = "../../../", features = ["postgres", "offline", "runtime-async-std-native-tls"] } diff --git a/examples/sqlite/todos/Cargo.toml b/examples/sqlite/todos/Cargo.toml index 4a4294739..2d179171b 100644 --- a/examples/sqlite/todos/Cargo.toml +++ b/examples/sqlite/todos/Cargo.toml @@ -6,7 +6,7 @@ workspace = "../../../" [dependencies] anyhow = "1.0" -async-std = { version = "1.5.0", features = [ "attributes" ] } +async-std = { version = "1.8.0", features = [ "attributes" ] } futures = "0.3" paw = "1.0" sqlx = { path = "../../../", features = ["sqlite"] } diff --git a/sqlx-cli/Cargo.toml b/sqlx-cli/Cargo.toml index a7ac3df42..0539daf3d 100644 --- a/sqlx-cli/Cargo.toml +++ b/sqlx-cli/Cargo.toml @@ -26,7 +26,7 @@ path = "src/bin/cargo-sqlx.rs" [dependencies] dotenv = "0.15" -tokio = { version = "0.2", features = ["macros"] } +tokio = { version = "1.0.1", features = ["macros", "rt", "rt-multi-thread"] } sqlx = { version = "0.4.0", path = "..", default-features = false, features = [ "runtime-async-std-native-tls", "migrate", "any", "offline" ] } futures = "0.3" clap = "=3.0.0-beta.2" diff --git a/sqlx-core/Cargo.toml b/sqlx-core/Cargo.toml index a50882536..e8c56aad6 100644 --- a/sqlx-core/Cargo.toml +++ b/sqlx-core/Cargo.toml @@ -43,9 +43,9 @@ runtime-async-std-rustls = [ "sqlx-rt/runtime-async-std-rustls", "_tls-rustls", runtime-tokio-rustls = [ "sqlx-rt/runtime-tokio-rustls", "_tls-rustls", "_rt-tokio" ] # for conditional compilation -_rt-actix = [] +_rt-actix = [ "tokio-stream" ] _rt-async-std = [] -_rt-tokio = [] +_rt-tokio = [ "tokio-stream" ] _tls-native-tls = [] _tls-rustls = [ "rustls", "webpki", "webpki-roots" ] @@ -61,7 +61,7 @@ bigdecimal_ = { version = "0.2.0", optional = true, package = "bigdecimal" } rust_decimal = { version = "1.8.1", optional = true } bit-vec = { version = "0.6.2", optional = true } bitflags = { version = "1.2.1", default-features = false } -bytes = "0.5.0" +bytes = "1.0.0" byteorder = { version = "1.3.4", default-features = false, features = [ "std" ] } chrono = { version = "0.4.11", default-features = false, features = [ "clock" ], optional = true } crc = { version = "1.8.1", optional = true } @@ -91,7 +91,7 @@ parking_lot = "0.11.0" rand = { version = "0.7.3", default-features = false, optional = true, features = [ "std" ] } regex = { version = "1.3.9", optional = true } rsa = { version = "0.3.0", optional = true } -rustls = { version = "0.18.0", features = [ "dangerous_configuration" ], optional = true } +rustls = { version = "0.19.0", features = [ "dangerous_configuration" ], optional = true } serde = { version = "1.0.106", features = [ "derive", "rc" ], optional = true } serde_json = { version = "1.0.51", features = [ "raw_value" ], optional = true } sha-1 = { version = "0.9.0", default-features = false, optional = true } @@ -99,6 +99,7 @@ sha2 = { version = "0.9.0", default-features = false, optional = true } sqlformat = "0.1.0" thiserror = "1.0.19" time = { version = "0.2.16", optional = true } +tokio-stream = { version = "0.1.2", features = ["fs"], optional = true } smallvec = "1.4.0" url = { version = "2.1.1", default-features = false } uuid = { version = "0.8.1", default-features = false, optional = true, features = [ "std" ] } diff --git a/sqlx-core/src/io/buf.rs b/sqlx-core/src/io/buf.rs index f89d8e233..7aa3289ec 100644 --- a/sqlx-core/src/io/buf.rs +++ b/sqlx-core/src/io/buf.rs @@ -21,8 +21,8 @@ pub trait BufExt: Buf { impl BufExt for Bytes { fn get_bytes_nul(&mut self) -> Result { - let nul = memchr(b'\0', self.bytes()) - .ok_or_else(|| err_protocol!("expected NUL in byte sequence"))?; + let nul = + memchr(b'\0', &self).ok_or_else(|| err_protocol!("expected NUL in byte sequence"))?; let v = self.slice(0..nul); diff --git a/sqlx-core/src/migrate/source.rs b/sqlx-core/src/migrate/source.rs index 65142f50c..7e06dd8c5 100644 --- a/sqlx-core/src/migrate/source.rs +++ b/sqlx-core/src/migrate/source.rs @@ -14,9 +14,13 @@ pub trait MigrationSource<'s>: Debug { impl<'s> MigrationSource<'s> for &'s Path { fn resolve(self) -> BoxFuture<'s, Result, BoxDynError>> { Box::pin(async move { + #[allow(unused_mut)] let mut s = fs::read_dir(self.canonicalize()?).await?; let mut migrations = Vec::new(); + #[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))] + let mut s = tokio_stream::wrappers::ReadDirStream::new(s); + while let Some(entry) = s.try_next().await? { if !entry.metadata().await?.is_file() { // not a file; ignore diff --git a/sqlx-core/src/mssql/connection/mod.rs b/sqlx-core/src/mssql/connection/mod.rs index 143ed4c04..38c577d06 100644 --- a/sqlx-core/src/mssql/connection/mod.rs +++ b/sqlx-core/src/mssql/connection/mod.rs @@ -7,9 +7,8 @@ use crate::mssql::statement::MssqlStatementMetadata; use crate::mssql::{Mssql, MssqlConnectOptions}; use crate::transaction::Transaction; use futures_core::future::BoxFuture; -use futures_util::{future::ready, FutureExt, TryFutureExt}; +use futures_util::{FutureExt, TryFutureExt}; use std::fmt::{self, Debug, Formatter}; -use std::net::Shutdown; use std::sync::Arc; mod establish; @@ -34,9 +33,26 @@ impl Connection for MssqlConnection { type Options = MssqlConnectOptions; - fn close(self) -> BoxFuture<'static, Result<(), Error>> { + #[allow(unused_mut)] + fn close(mut self) -> BoxFuture<'static, Result<(), Error>> { // NOTE: there does not seem to be a clean shutdown packet to send to MSSQL - ready(self.stream.shutdown(Shutdown::Both).map_err(Into::into)).boxed() + + #[cfg(feature = "_rt-async-std")] + { + use std::future::ready; + use std::net::Shutdown; + + ready(self.stream.shutdown(Shutdown::Both).map_err(Into::into)).boxed() + } + + #[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))] + { + use sqlx_rt::AsyncWriteExt; + + // FIXME: This is equivalent to Shutdown::Write, not Shutdown::Both like above + // https://docs.rs/tokio/1.0.1/tokio/io/trait.AsyncWriteExt.html#method.shutdown + async move { self.stream.shutdown().await.map_err(Into::into) }.boxed() + } } fn ping(&mut self) -> BoxFuture<'_, Result<(), Error>> { diff --git a/sqlx-core/src/mysql/connection/auth.rs b/sqlx-core/src/mysql/connection/auth.rs index 1de59d51d..3e625c1cf 100644 --- a/sqlx-core/src/mysql/connection/auth.rs +++ b/sqlx-core/src/mysql/connection/auth.rs @@ -1,4 +1,4 @@ -use bytes::buf::ext::Chain; +use bytes::buf::Chain; use bytes::Bytes; use digest::{Digest, FixedOutput}; use generic_array::GenericArray; diff --git a/sqlx-core/src/mysql/connection/establish.rs b/sqlx-core/src/mysql/connection/establish.rs index 170174b19..9e84cc4fc 100644 --- a/sqlx-core/src/mysql/connection/establish.rs +++ b/sqlx-core/src/mysql/connection/establish.rs @@ -1,3 +1,4 @@ +use bytes::buf::Buf; use bytes::Bytes; use crate::common::StatementCache; @@ -8,7 +9,6 @@ use crate::mysql::protocol::connect::{ }; use crate::mysql::protocol::Capabilities; use crate::mysql::{MySqlConnectOptions, MySqlConnection, MySqlSslMode}; -use bytes::buf::BufExt as _; impl MySqlConnection { pub(crate) async fn establish(options: &MySqlConnectOptions) -> Result { diff --git a/sqlx-core/src/mysql/connection/mod.rs b/sqlx-core/src/mysql/connection/mod.rs index 7290bbfbc..509426a63 100644 --- a/sqlx-core/src/mysql/connection/mod.rs +++ b/sqlx-core/src/mysql/connection/mod.rs @@ -50,7 +50,7 @@ impl Connection for MySqlConnection { fn close(mut self) -> BoxFuture<'static, Result<(), Error>> { Box::pin(async move { self.stream.send_packet(Quit).await?; - self.stream.shutdown()?; + self.stream.shutdown().await?; Ok(()) }) diff --git a/sqlx-core/src/mysql/protocol/connect/handshake.rs b/sqlx-core/src/mysql/protocol/connect/handshake.rs index fc4bf10da..02c5ff48d 100644 --- a/sqlx-core/src/mysql/protocol/connect/handshake.rs +++ b/sqlx-core/src/mysql/protocol/connect/handshake.rs @@ -1,4 +1,4 @@ -use bytes::buf::ext::{BufExt as _, Chain}; +use bytes::buf::Chain; use bytes::{Buf, Bytes}; use crate::error::Error; @@ -134,7 +134,7 @@ fn test_decode_handshake_mysql_8_0_18() { )); assert_eq!( - &*p.auth_plugin_data.to_bytes(), + &*p.auth_plugin_data.into_iter().collect::>(), &[17, 52, 97, 66, 48, 99, 6, 103, 116, 76, 3, 115, 15, 91, 52, 13, 108, 52, 46, 32,] ); } @@ -187,7 +187,7 @@ fn test_decode_handshake_mariadb_10_4_7() { )); assert_eq!( - &*p.auth_plugin_data.to_bytes(), + &*p.auth_plugin_data.into_iter().collect::>(), &[116, 54, 76, 92, 106, 34, 100, 83, 85, 49, 52, 79, 112, 104, 57, 34, 60, 72, 53, 110,] ); } diff --git a/sqlx-core/src/net/mod.rs b/sqlx-core/src/net/mod.rs index b3bca6458..cf42bd26b 100644 --- a/sqlx-core/src/net/mod.rs +++ b/sqlx-core/src/net/mod.rs @@ -3,3 +3,15 @@ mod tls; pub use socket::Socket; pub use tls::MaybeTlsStream; + +#[cfg(feature = "_rt-async-std")] +type PollReadBuf<'a> = [u8]; + +#[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))] +type PollReadBuf<'a> = sqlx_rt::ReadBuf<'a>; + +#[cfg(feature = "_rt-async-std")] +type PollReadOut = usize; + +#[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))] +type PollReadOut = (); diff --git a/sqlx-core/src/net/socket.rs b/sqlx-core/src/net/socket.rs index 929335b38..06d5575c0 100644 --- a/sqlx-core/src/net/socket.rs +++ b/sqlx-core/src/net/socket.rs @@ -1,7 +1,6 @@ #![allow(dead_code)] use std::io; -use std::net::Shutdown; use std::path::Path; use std::pin::Pin; use std::task::{Context, Poll}; @@ -36,12 +35,29 @@ impl Socket { )) } - pub fn shutdown(&self) -> io::Result<()> { - match self { - Socket::Tcp(s) => s.shutdown(Shutdown::Both), + pub async fn shutdown(&mut self) -> io::Result<()> { + #[cfg(feature = "_rt-async-std")] + { + use std::net::Shutdown; - #[cfg(unix)] - Socket::Unix(s) => s.shutdown(Shutdown::Both), + match self { + Socket::Tcp(s) => s.shutdown(Shutdown::Both), + + #[cfg(unix)] + Socket::Unix(s) => s.shutdown(Shutdown::Both), + } + } + + #[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))] + { + use sqlx_rt::AsyncWriteExt; + + match self { + Socket::Tcp(s) => s.shutdown().await, + + #[cfg(unix)] + Socket::Unix(s) => s.shutdown().await, + } } } } @@ -50,8 +66,8 @@ impl AsyncRead for Socket { fn poll_read( mut self: Pin<&mut Self>, cx: &mut Context<'_>, - buf: &mut [u8], - ) -> Poll> { + buf: &mut super::PollReadBuf<'_>, + ) -> Poll> { match &mut *self { Socket::Tcp(s) => Pin::new(s).poll_read(cx, buf), @@ -59,24 +75,6 @@ impl AsyncRead for Socket { Socket::Unix(s) => Pin::new(s).poll_read(cx, buf), } } - - #[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))] - fn poll_read_buf( - mut self: Pin<&mut Self>, - cx: &mut Context<'_>, - buf: &mut B, - ) -> Poll> - where - Self: Sized, - B: bytes::BufMut, - { - match &mut *self { - Socket::Tcp(s) => Pin::new(s).poll_read_buf(cx, buf), - - #[cfg(unix)] - Socket::Unix(s) => Pin::new(s).poll_read_buf(cx, buf), - } - } } impl AsyncWrite for Socket { @@ -121,22 +119,4 @@ impl AsyncWrite for Socket { Socket::Unix(s) => Pin::new(s).poll_close(cx), } } - - #[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))] - fn poll_write_buf( - mut self: Pin<&mut Self>, - cx: &mut Context<'_>, - buf: &mut B, - ) -> Poll> - where - Self: Sized, - B: bytes::Buf, - { - match &mut *self { - Socket::Tcp(s) => Pin::new(s).poll_write_buf(cx, buf), - - #[cfg(unix)] - Socket::Unix(s) => Pin::new(s).poll_write_buf(cx, buf), - } - } } diff --git a/sqlx-core/src/net/tls/mod.rs b/sqlx-core/src/net/tls/mod.rs index 4fb1cfb8a..3505a7e50 100644 --- a/sqlx-core/src/net/tls/mod.rs +++ b/sqlx-core/src/net/tls/mod.rs @@ -114,8 +114,8 @@ where fn poll_read( mut self: Pin<&mut Self>, cx: &mut Context<'_>, - buf: &mut [u8], - ) -> Poll> { + buf: &mut super::PollReadBuf<'_>, + ) -> Poll> { match &mut *self { MaybeTlsStream::Raw(s) => Pin::new(s).poll_read(cx, buf), MaybeTlsStream::Tls(s) => Pin::new(s).poll_read(cx, buf), @@ -123,24 +123,6 @@ where MaybeTlsStream::Upgrading => Poll::Ready(Err(io::ErrorKind::ConnectionAborted.into())), } } - - #[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))] - fn poll_read_buf( - mut self: Pin<&mut Self>, - cx: &mut Context<'_>, - buf: &mut B, - ) -> Poll> - where - Self: Sized, - B: bytes::BufMut, - { - match &mut *self { - MaybeTlsStream::Raw(s) => Pin::new(s).poll_read_buf(cx, buf), - MaybeTlsStream::Tls(s) => Pin::new(s).poll_read_buf(cx, buf), - - MaybeTlsStream::Upgrading => Poll::Ready(Err(io::ErrorKind::ConnectionAborted.into())), - } - } } impl AsyncWrite for MaybeTlsStream @@ -188,24 +170,6 @@ where MaybeTlsStream::Upgrading => Poll::Ready(Err(io::ErrorKind::ConnectionAborted.into())), } } - - #[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))] - fn poll_write_buf( - mut self: Pin<&mut Self>, - cx: &mut Context<'_>, - buf: &mut B, - ) -> Poll> - where - Self: Sized, - B: bytes::Buf, - { - match &mut *self { - MaybeTlsStream::Raw(s) => Pin::new(s).poll_write_buf(cx, buf), - MaybeTlsStream::Tls(s) => Pin::new(s).poll_write_buf(cx, buf), - - MaybeTlsStream::Upgrading => Poll::Ready(Err(io::ErrorKind::ConnectionAborted.into())), - } - } } impl Deref for MaybeTlsStream diff --git a/sqlx-core/src/postgres/connection/mod.rs b/sqlx-core/src/postgres/connection/mod.rs index 2688727ac..e0238f591 100644 --- a/sqlx-core/src/postgres/connection/mod.rs +++ b/sqlx-core/src/postgres/connection/mod.rs @@ -122,7 +122,7 @@ impl Connection for PgConnection { Box::pin(async move { self.stream.send(Terminate).await?; - self.stream.shutdown()?; + self.stream.shutdown().await?; Ok(()) }) diff --git a/sqlx-core/src/postgres/types/bit_vec.rs b/sqlx-core/src/postgres/types/bit_vec.rs index c5109b91b..ea0136780 100644 --- a/sqlx-core/src/postgres/types/bit_vec.rs +++ b/sqlx-core/src/postgres/types/bit_vec.rs @@ -76,7 +76,7 @@ impl Decode<'_, Postgres> for BitVec { ))?; } - let mut bitvec = BitVec::from_bytes(bytes.bytes()); + let mut bitvec = BitVec::from_bytes(&bytes); // Chop off zeroes from the back. We get bits in bytes, so if // our bitvec is not in full bytes, extra zeroes are added to diff --git a/sqlx-macros/src/lib.rs b/sqlx-macros/src/lib.rs index b42f20278..d23b0b30f 100644 --- a/sqlx-macros/src/lib.rs +++ b/sqlx-macros/src/lib.rs @@ -108,8 +108,7 @@ pub fn test(_attr: TokenStream, input: TokenStream) -> TokenStream { #[test] #(#attrs)* fn #name() #ret { - sqlx_rt::tokio::runtime::Builder::new() - .threaded_scheduler() + sqlx_rt::tokio::runtime::Builder::new_multi_thread() .enable_io() .enable_time() .build() diff --git a/sqlx-rt/Cargo.toml b/sqlx-rt/Cargo.toml index a2868d420..017f0a145 100644 --- a/sqlx-rt/Cargo.toml +++ b/sqlx-rt/Cargo.toml @@ -28,12 +28,12 @@ _tls-rustls = [ ] [dependencies] async-native-tls = { version = "0.3.3", optional = true } -async-rustls = { version = "0.1.0", optional = true } -actix-rt = { version = "1.1.1", optional = true } +async-rustls = { version = "0.2.0", optional = true } +actix-rt = { version = "=2.0.0-beta.1", optional = true } actix-threadpool = { version = "0.3.2", optional = true } -async-std = { version = "1.6.5", features = [ "unstable" ], optional = true } -tokio = { version = "0.2.21", optional = true, features = [ "blocking", "stream", "fs", "tcp", "uds", "macros", "rt-core", "rt-threaded", "time", "dns", "io-util" ] } -tokio-native-tls = { version = "0.1.0", optional = true } -tokio-rustls = { version = "0.14.0", optional = true } +async-std = { version = "1.7.0", features = [ "unstable" ], optional = true } +tokio = { version = "1.0.1", optional = true, features = [ "fs", "net", "macros", "rt", "rt-multi-thread", "time", "io-util" ] } +tokio-native-tls = { version = "0.3.0", optional = true } +tokio-rustls = { version = "0.22.0", optional = true } native-tls = { version = "0.2.4", optional = true } once_cell = { version = "1.4", features = ["std"], optional = true } diff --git a/sqlx-rt/src/lib.rs b/sqlx-rt/src/lib.rs index 75974abdc..54f35f3bc 100644 --- a/sqlx-rt/src/lib.rs +++ b/sqlx-rt/src/lib.rs @@ -36,8 +36,8 @@ pub use native_tls; not(feature = "_rt-async-std"), ))] pub use tokio::{ - self, fs, io::AsyncRead, io::AsyncReadExt, io::AsyncWrite, io::AsyncWriteExt, net::TcpStream, - task::spawn, task::yield_now, time::delay_for as sleep, time::timeout, + self, fs, io::AsyncRead, io::AsyncReadExt, io::AsyncWrite, io::AsyncWriteExt, io::ReadBuf, + net::TcpStream, task::spawn, task::yield_now, time::sleep, time::timeout, }; #[cfg(all( @@ -60,9 +60,7 @@ mod tokio_runtime { // lazily initialize a global runtime once for multiple invocations of the macros static RUNTIME: Lazy = Lazy::new(|| { - runtime::Builder::new() - // `.basic_scheduler()` requires calling `Runtime::block_on()` which needs mutability - .threaded_scheduler() + runtime::Builder::new_multi_thread() .enable_io() .enable_time() .build() @@ -70,14 +68,15 @@ mod tokio_runtime { }); pub fn block_on(future: F) -> F::Output { - RUNTIME.enter(|| RUNTIME.handle().block_on(future)) + RUNTIME.block_on(future) } pub fn enter_runtime(f: F) -> R where F: FnOnce() -> R, { - RUNTIME.enter(f) + RUNTIME.enter(); + f() } } diff --git a/sqlx-test/Cargo.toml b/sqlx-test/Cargo.toml index ed1279dda..60f299c1f 100644 --- a/sqlx-test/Cargo.toml +++ b/sqlx-test/Cargo.toml @@ -9,5 +9,5 @@ sqlx = { default-features = false, path = ".." } env_logger = "0.7.1" dotenv = "0.15.0" anyhow = "1.0.26" -async-std = { version = "1.5.0", features = [ "attributes" ] } -tokio = { version = "0.2.13", features = [ "full" ] } +async-std = { version = "1.8.0", features = [ "attributes" ] } +tokio = { version = "1.0.1", features = [ "full" ] } diff --git a/tests/postgres/postgres.rs b/tests/postgres/postgres.rs index 0e8c8bf39..df6fc795a 100644 --- a/tests/postgres/postgres.rs +++ b/tests/postgres/postgres.rs @@ -455,7 +455,7 @@ async fn it_can_drop_multiple_transactions() -> anyhow::Result<()> { #[sqlx_macros::test] async fn pool_smoke_test() -> anyhow::Result<()> { #[cfg(any(feature = "_rt-tokio", feature = "_rt-actix"))] - use tokio::{task::spawn, time::delay_for as sleep, time::timeout}; + use tokio::{task::spawn, time::sleep, time::timeout}; #[cfg(feature = "_rt-async-std")] use async_std::{future::timeout, task::sleep, task::spawn}; From e29b07c06966a3824136b288e96d8adcd8f8da93 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 14 Jan 2021 14:17:50 +0100 Subject: [PATCH 15/18] Add a changelog entry for the async runtime update --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e73b805f3..f534ef459 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [[#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 + - actix-rt 2.0 + ## 0.4.2 - 2020-12-19 - [[#908]] Fix `whoami` crash on FreeBSD platform [[@fundon]] [[@AldaronLau]] From d7761c74fa200da6657cf75e73ed7985882966a5 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 14 Jan 2021 18:19:11 +0100 Subject: [PATCH 16/18] Upgrade actix-rt to 2.0.0-beta.2 --- Cargo.lock | 8 ++++---- sqlx-rt/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 084e3fffa..25d2b56ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,9 +2,9 @@ # It is not intended for manual editing. [[package]] name = "actix-macros" -version = "0.1.3" +version = "0.2.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ca8ce00b267af8ccebbd647de0d61e0674b6e61185cc7a592ff88772bed655" +checksum = "32d550809c1471a3ed937cb2afefd7cba179a6ac4a0cb46361b3541bfcad7084" dependencies = [ "quote", "syn", @@ -12,9 +12,9 @@ dependencies = [ [[package]] name = "actix-rt" -version = "2.0.0-beta.1" +version = "2.0.0-beta.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dfadca59a1d7755a3828708977a2de80b51af0381bd0002ce8f0df3f6091928" +checksum = "ac24f3f660d4c394cc6d24272e526083c257d6045d3be76a9d0a76be5cb56515" dependencies = [ "actix-macros", "tokio", diff --git a/sqlx-rt/Cargo.toml b/sqlx-rt/Cargo.toml index 017f0a145..b54a8da2b 100644 --- a/sqlx-rt/Cargo.toml +++ b/sqlx-rt/Cargo.toml @@ -29,7 +29,7 @@ _tls-rustls = [ ] [dependencies] async-native-tls = { version = "0.3.3", optional = true } async-rustls = { version = "0.2.0", optional = true } -actix-rt = { version = "=2.0.0-beta.1", optional = true } +actix-rt = { version = "=2.0.0-beta.2", optional = true } actix-threadpool = { version = "0.3.2", optional = true } async-std = { version = "1.7.0", features = [ "unstable" ], optional = true } tokio = { version = "1.0.1", optional = true, features = [ "fs", "net", "macros", "rt", "rt-multi-thread", "time", "io-util" ] } From 227ed73315f0744ee632a1869a261c7aebd4e635 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 14 Jan 2021 18:21:13 +0100 Subject: [PATCH 17/18] rt: Disable macros in actix and tokio runtimes --- Cargo.lock | 11 ----------- sqlx-rt/Cargo.toml | 8 ++++++-- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 25d2b56ae..b9e4aa6f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,22 +1,11 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -[[package]] -name = "actix-macros" -version = "0.2.0-beta.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32d550809c1471a3ed937cb2afefd7cba179a6ac4a0cb46361b3541bfcad7084" -dependencies = [ - "quote", - "syn", -] - [[package]] name = "actix-rt" version = "2.0.0-beta.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac24f3f660d4c394cc6d24272e526083c257d6045d3be76a9d0a76be5cb56515" dependencies = [ - "actix-macros", "tokio", ] diff --git a/sqlx-rt/Cargo.toml b/sqlx-rt/Cargo.toml index b54a8da2b..842161195 100644 --- a/sqlx-rt/Cargo.toml +++ b/sqlx-rt/Cargo.toml @@ -29,11 +29,15 @@ _tls-rustls = [ ] [dependencies] async-native-tls = { version = "0.3.3", optional = true } async-rustls = { version = "0.2.0", optional = true } -actix-rt = { version = "=2.0.0-beta.2", optional = true } +actix-rt = { version = "=2.0.0-beta.2", default-features = false, optional = true } actix-threadpool = { version = "0.3.2", optional = true } async-std = { version = "1.7.0", features = [ "unstable" ], optional = true } -tokio = { version = "1.0.1", optional = true, features = [ "fs", "net", "macros", "rt", "rt-multi-thread", "time", "io-util" ] } tokio-native-tls = { version = "0.3.0", optional = true } tokio-rustls = { version = "0.22.0", optional = true } native-tls = { version = "0.2.4", optional = true } once_cell = { version = "1.4", features = ["std"], optional = true } + +[dependencies.tokio] +version = "1.0.1" +features = ["fs", "net", "rt", "rt-multi-thread", "time", "io-util"] +optional = true From 4d03e5be0b2cd5a6ecaecdf8e0d193410551c0a1 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 14 Jan 2021 18:25:28 +0100 Subject: [PATCH 18/18] rt: Normalize TOML array formatting --- sqlx-rt/Cargo.toml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sqlx-rt/Cargo.toml b/sqlx-rt/Cargo.toml index 842161195..3d639b2da 100644 --- a/sqlx-rt/Cargo.toml +++ b/sqlx-rt/Cargo.toml @@ -11,27 +11,27 @@ authors = [ ] [features] -runtime-actix-native-tls = [ "_rt-actix", "_tls-native-tls", "tokio-native-tls" ] -runtime-async-std-native-tls = [ "_rt-async-std", "_tls-native-tls", "async-native-tls" ] -runtime-tokio-native-tls = [ "_rt-tokio", "_tls-native-tls", "tokio-native-tls" ] +runtime-actix-native-tls = ["_rt-actix", "_tls-native-tls", "tokio-native-tls"] +runtime-async-std-native-tls = ["_rt-async-std", "_tls-native-tls", "async-native-tls"] +runtime-tokio-native-tls = ["_rt-tokio", "_tls-native-tls", "tokio-native-tls"] -runtime-actix-rustls = [ "_rt-actix", "_tls-rustls", "tokio-rustls" ] -runtime-async-std-rustls = [ "_rt-async-std", "_tls-rustls", "async-rustls" ] -runtime-tokio-rustls = [ "_rt-tokio", "_tls-rustls", "tokio-rustls" ] +runtime-actix-rustls = ["_rt-actix", "_tls-rustls", "tokio-rustls"] +runtime-async-std-rustls = ["_rt-async-std", "_tls-rustls", "async-rustls"] +runtime-tokio-rustls = ["_rt-tokio", "_tls-rustls", "tokio-rustls"] # Not used directly and not re-exported from sqlx -_rt-actix = [ "actix-rt", "actix-threadpool", "tokio", "once_cell" ] -_rt-async-std = [ "async-std" ] -_rt-tokio = [ "tokio", "once_cell" ] -_tls-native-tls = [ "native-tls" ] -_tls-rustls = [ ] +_rt-actix = ["actix-rt", "actix-threadpool", "tokio", "once_cell"] +_rt-async-std = ["async-std"] +_rt-tokio = ["tokio", "once_cell"] +_tls-native-tls = ["native-tls"] +_tls-rustls = [] [dependencies] async-native-tls = { version = "0.3.3", optional = true } async-rustls = { version = "0.2.0", optional = true } actix-rt = { version = "=2.0.0-beta.2", default-features = false, optional = true } actix-threadpool = { version = "0.3.2", optional = true } -async-std = { version = "1.7.0", features = [ "unstable" ], optional = true } +async-std = { version = "1.7.0", features = ["unstable"], optional = true } tokio-native-tls = { version = "0.3.0", optional = true } tokio-rustls = { version = "0.22.0", optional = true } native-tls = { version = "0.2.4", optional = true }