From 5d9c292132a23a245ba5a179765a374c94ffde44 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Sat, 22 May 2021 16:38:54 -0700 Subject: [PATCH 01/10] release: v0.5.4 --- CHANGELOG.md | 7 +++++++ Cargo.lock | 10 +++++----- Cargo.toml | 6 +++--- sqlx-cli/Cargo.toml | 4 ++-- sqlx-core/Cargo.toml | 4 ++-- sqlx-macros/Cargo.toml | 6 +++--- sqlx-rt/Cargo.toml | 2 +- 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1189e2d2bc..e190bbc5b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.5.4 - 2021-05-22 + +- [[#1235]] Fix compilation with rustls from an eager update to webpki [[@ETCaton]] + +[#1235]: https://github.com/launchbadge/sqlx/pull/1235 + ## 0.5.3 - 2021-05-21 - [[#1211]] Even more tweaks and fixes to the Pool internals [[@abonander]] @@ -911,3 +917,4 @@ Fix docs.rs build by enabling a runtime feature in the docs.rs metadata in `Carg [@guylapid]: https://github.com/guylapid [@natproach]: https://github.com/NatPRoach [@feikesteenbergen]: https://github.com/feikesteenbergen +[@etcaton]: https://github.com/ETCaton diff --git a/Cargo.lock b/Cargo.lock index 82aa0caeed..c2d26c1e69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2255,7 +2255,7 @@ dependencies = [ [[package]] name = "sqlx" -version = "0.5.3" +version = "0.5.4" dependencies = [ "anyhow", "async-std", @@ -2288,7 +2288,7 @@ dependencies = [ [[package]] name = "sqlx-cli" -version = "0.5.3" +version = "0.5.4" dependencies = [ "anyhow", "async-trait", @@ -2310,7 +2310,7 @@ dependencies = [ [[package]] name = "sqlx-core" -version = "0.5.3" +version = "0.5.4" dependencies = [ "ahash", "atoi", @@ -2435,7 +2435,7 @@ dependencies = [ [[package]] name = "sqlx-macros" -version = "0.5.3" +version = "0.5.4" dependencies = [ "dotenv", "either", @@ -2456,7 +2456,7 @@ dependencies = [ [[package]] name = "sqlx-rt" -version = "0.5.3" +version = "0.5.4" dependencies = [ "actix-rt", "async-native-tls", diff --git a/Cargo.toml b/Cargo.toml index 6234ea8d49..d276745a30 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ members = [ [package] name = "sqlx" -version = "0.5.3" +version = "0.5.4" license = "MIT OR Apache-2.0" readme = "README.md" repository = "https://github.com/launchbadge/sqlx" @@ -129,8 +129,8 @@ bstr = ["sqlx-core/bstr"] git2 = ["sqlx-core/git2"] [dependencies] -sqlx-core = { version = "0.5.3", path = "sqlx-core", default-features = false } -sqlx-macros = { version = "0.5.3", path = "sqlx-macros", default-features = false, optional = true } +sqlx-core = { version = "0.5.4", path = "sqlx-core", default-features = false } +sqlx-macros = { version = "0.5.4", path = "sqlx-macros", default-features = false, optional = true } [dev-dependencies] anyhow = "1.0.31" diff --git a/sqlx-cli/Cargo.toml b/sqlx-cli/Cargo.toml index 6b9f1549fd..2ae47aec2a 100644 --- a/sqlx-cli/Cargo.toml +++ b/sqlx-cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sqlx-cli" -version = "0.5.3" +version = "0.5.4" description = "Command-line utility for SQLx, the Rust SQL toolkit." edition = "2018" readme = "README.md" @@ -27,7 +27,7 @@ path = "src/bin/cargo-sqlx.rs" [dependencies] dotenv = "0.15" tokio = { version = "1.0.1", features = ["macros", "rt", "rt-multi-thread"] } -sqlx = { version = "0.5.3", path = "..", default-features = false, features = [ +sqlx = { version = "0.5.4", path = "..", default-features = false, features = [ "runtime-async-std-native-tls", "migrate", "any", diff --git a/sqlx-core/Cargo.toml b/sqlx-core/Cargo.toml index 7d4ade7798..2d15453bfb 100644 --- a/sqlx-core/Cargo.toml +++ b/sqlx-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sqlx-core" -version = "0.5.3" +version = "0.5.4" repository = "https://github.com/launchbadge/sqlx" description = "Core of SQLx, the rust SQL toolkit. Not intended to be used directly." license = "MIT OR Apache-2.0" @@ -100,7 +100,7 @@ offline = ["serde", "either/serde"] [dependencies] ahash = "0.7.2" atoi = "0.4.0" -sqlx-rt = { path = "../sqlx-rt", version = "0.5.3" } +sqlx-rt = { path = "../sqlx-rt", version = "0.5.4" } base64 = { version = "0.13.0", default-features = false, optional = true, features = ["std"] } bigdecimal_ = { version = "0.2.0", optional = true, package = "bigdecimal" } rust_decimal = { version = "1.8.1", optional = true } diff --git a/sqlx-macros/Cargo.toml b/sqlx-macros/Cargo.toml index 91ae1f6071..731dfc8209 100644 --- a/sqlx-macros/Cargo.toml +++ b/sqlx-macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sqlx-macros" -version = "0.5.3" +version = "0.5.4" repository = "https://github.com/launchbadge/sqlx" description = "Macros for SQLx, the rust SQL toolkit. Not intended to be used directly." license = "MIT OR Apache-2.0" @@ -84,8 +84,8 @@ heck = "0.3.1" either = "1.5.3" once_cell = "1.5.2" proc-macro2 = { version = "1.0.9", default-features = false } -sqlx-core = { version = "0.5.3", default-features = false, path = "../sqlx-core" } -sqlx-rt = { version = "0.5.3", default-features = false, path = "../sqlx-rt" } +sqlx-core = { version = "0.5.4", default-features = false, path = "../sqlx-core" } +sqlx-rt = { version = "0.5.4", default-features = false, path = "../sqlx-rt" } serde = { version = "1.0.111", features = ["derive"], optional = true } serde_json = { version = "1.0.30", features = ["preserve_order"], optional = true } sha2 = { version = "0.9.1", optional = true } diff --git a/sqlx-rt/Cargo.toml b/sqlx-rt/Cargo.toml index 75fa4bc9c4..62bb08e4ad 100644 --- a/sqlx-rt/Cargo.toml +++ b/sqlx-rt/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sqlx-rt" -version = "0.5.3" +version = "0.5.4" repository = "https://github.com/launchbadge/sqlx" license = "MIT OR Apache-2.0" description = "Runtime abstraction used by SQLx, the Rust SQL toolkit. Not intended to be used directly." From eda78a725875b0603c7db6af94ecb3ff84a780a7 Mon Sep 17 00:00:00 2001 From: toshokan Date: Sun, 23 May 2021 21:53:50 -0400 Subject: [PATCH 02/10] Fix infinite compile loop regression from recursive Lazy reference --- sqlx-macros/src/query/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sqlx-macros/src/query/mod.rs b/sqlx-macros/src/query/mod.rs index d114f54528..eed89967f0 100644 --- a/sqlx-macros/src/query/mod.rs +++ b/sqlx-macros/src/query/mod.rs @@ -37,7 +37,7 @@ struct Metadata { static METADATA: Lazy = Lazy::new(|| { use std::env; - let manifest_dir = env::var("CARGO_MANIFEST_DIR") + let manifest_dir: PathBuf = env::var("CARGO_MANIFEST_DIR") .expect("`CARGO_MANIFEST_DIR` must be set") .into(); @@ -47,7 +47,7 @@ static METADATA: Lazy = Lazy::new(|| { // If a .env file exists at CARGO_MANIFEST_DIR, load environment variables from this, // otherwise fallback to default dotenv behaviour. - let env_path = METADATA.manifest_dir.join(".env"); + let env_path = manifest_dir.join(".env"); if env_path.exists() { let res = dotenv::from_path(&env_path); if let Err(e) = res { From 694a2ac478fc3f9c7b6c879e99964b426bad84ea Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Mon, 24 May 2021 09:34:34 -0700 Subject: [PATCH 03/10] release: v0.5.5 --- CHANGELOG.md | 7 +++++++ Cargo.lock | 10 +++++----- Cargo.toml | 6 +++--- sqlx-cli/Cargo.toml | 4 ++-- sqlx-core/Cargo.toml | 4 ++-- sqlx-macros/Cargo.toml | 6 +++--- sqlx-rt/Cargo.toml | 2 +- 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e190bbc5b1..3e3addaecd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.5.5 - 2021-05-24 + +- [[#1242]] Fix infinite loop at compile time when using query macros [[@toshokan]] + +[#1242]: https://github.com/launchbadge/sqlx/pull/1242 + ## 0.5.4 - 2021-05-22 - [[#1235]] Fix compilation with rustls from an eager update to webpki [[@ETCaton]] @@ -918,3 +924,4 @@ Fix docs.rs build by enabling a runtime feature in the docs.rs metadata in `Carg [@natproach]: https://github.com/NatPRoach [@feikesteenbergen]: https://github.com/feikesteenbergen [@etcaton]: https://github.com/ETCaton +[@toshokan]: https://github.com/toshokan diff --git a/Cargo.lock b/Cargo.lock index c2d26c1e69..bab48c5036 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2255,7 +2255,7 @@ dependencies = [ [[package]] name = "sqlx" -version = "0.5.4" +version = "0.5.5" dependencies = [ "anyhow", "async-std", @@ -2288,7 +2288,7 @@ dependencies = [ [[package]] name = "sqlx-cli" -version = "0.5.4" +version = "0.5.5" dependencies = [ "anyhow", "async-trait", @@ -2310,7 +2310,7 @@ dependencies = [ [[package]] name = "sqlx-core" -version = "0.5.4" +version = "0.5.5" dependencies = [ "ahash", "atoi", @@ -2435,7 +2435,7 @@ dependencies = [ [[package]] name = "sqlx-macros" -version = "0.5.4" +version = "0.5.5" dependencies = [ "dotenv", "either", @@ -2456,7 +2456,7 @@ dependencies = [ [[package]] name = "sqlx-rt" -version = "0.5.4" +version = "0.5.5" dependencies = [ "actix-rt", "async-native-tls", diff --git a/Cargo.toml b/Cargo.toml index d276745a30..2861b2024e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ members = [ [package] name = "sqlx" -version = "0.5.4" +version = "0.5.5" license = "MIT OR Apache-2.0" readme = "README.md" repository = "https://github.com/launchbadge/sqlx" @@ -129,8 +129,8 @@ bstr = ["sqlx-core/bstr"] git2 = ["sqlx-core/git2"] [dependencies] -sqlx-core = { version = "0.5.4", path = "sqlx-core", default-features = false } -sqlx-macros = { version = "0.5.4", path = "sqlx-macros", default-features = false, optional = true } +sqlx-core = { version = "0.5.5", path = "sqlx-core", default-features = false } +sqlx-macros = { version = "0.5.5", path = "sqlx-macros", default-features = false, optional = true } [dev-dependencies] anyhow = "1.0.31" diff --git a/sqlx-cli/Cargo.toml b/sqlx-cli/Cargo.toml index 2ae47aec2a..0c0d92a0bb 100644 --- a/sqlx-cli/Cargo.toml +++ b/sqlx-cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sqlx-cli" -version = "0.5.4" +version = "0.5.5" description = "Command-line utility for SQLx, the Rust SQL toolkit." edition = "2018" readme = "README.md" @@ -27,7 +27,7 @@ path = "src/bin/cargo-sqlx.rs" [dependencies] dotenv = "0.15" tokio = { version = "1.0.1", features = ["macros", "rt", "rt-multi-thread"] } -sqlx = { version = "0.5.4", path = "..", default-features = false, features = [ +sqlx = { version = "0.5.5", path = "..", default-features = false, features = [ "runtime-async-std-native-tls", "migrate", "any", diff --git a/sqlx-core/Cargo.toml b/sqlx-core/Cargo.toml index 2d15453bfb..bfa3f5f9ae 100644 --- a/sqlx-core/Cargo.toml +++ b/sqlx-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sqlx-core" -version = "0.5.4" +version = "0.5.5" repository = "https://github.com/launchbadge/sqlx" description = "Core of SQLx, the rust SQL toolkit. Not intended to be used directly." license = "MIT OR Apache-2.0" @@ -100,7 +100,7 @@ offline = ["serde", "either/serde"] [dependencies] ahash = "0.7.2" atoi = "0.4.0" -sqlx-rt = { path = "../sqlx-rt", version = "0.5.4" } +sqlx-rt = { path = "../sqlx-rt", version = "0.5.5" } base64 = { version = "0.13.0", default-features = false, optional = true, features = ["std"] } bigdecimal_ = { version = "0.2.0", optional = true, package = "bigdecimal" } rust_decimal = { version = "1.8.1", optional = true } diff --git a/sqlx-macros/Cargo.toml b/sqlx-macros/Cargo.toml index 731dfc8209..b76185ed53 100644 --- a/sqlx-macros/Cargo.toml +++ b/sqlx-macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sqlx-macros" -version = "0.5.4" +version = "0.5.5" repository = "https://github.com/launchbadge/sqlx" description = "Macros for SQLx, the rust SQL toolkit. Not intended to be used directly." license = "MIT OR Apache-2.0" @@ -84,8 +84,8 @@ heck = "0.3.1" either = "1.5.3" once_cell = "1.5.2" proc-macro2 = { version = "1.0.9", default-features = false } -sqlx-core = { version = "0.5.4", default-features = false, path = "../sqlx-core" } -sqlx-rt = { version = "0.5.4", default-features = false, path = "../sqlx-rt" } +sqlx-core = { version = "0.5.5", default-features = false, path = "../sqlx-core" } +sqlx-rt = { version = "0.5.5", default-features = false, path = "../sqlx-rt" } serde = { version = "1.0.111", features = ["derive"], optional = true } serde_json = { version = "1.0.30", features = ["preserve_order"], optional = true } sha2 = { version = "0.9.1", optional = true } diff --git a/sqlx-rt/Cargo.toml b/sqlx-rt/Cargo.toml index 62bb08e4ad..942a54753f 100644 --- a/sqlx-rt/Cargo.toml +++ b/sqlx-rt/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sqlx-rt" -version = "0.5.4" +version = "0.5.5" repository = "https://github.com/launchbadge/sqlx" license = "MIT OR Apache-2.0" description = "Runtime abstraction used by SQLx, the Rust SQL toolkit. Not intended to be used directly." From 4986ea2e5971ce1ab561bb84aa6be9c880a1d68e Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 31 May 2021 00:52:25 +0200 Subject: [PATCH 04/10] Improve root README.md and sqlx-cli/README.md (#1262) * readme: Fix inconsistent list style * readme: Improve text alignment * readme: Fix missing links * readme: Consistently use code formatting for runtime & TLS crates and dedup links * readme: Add SQLx is not an ORM section * readme: Improve documentation about offline mode --- README.md | 50 ++++++++++++++++++++++++++++++++++++---------- sqlx-cli/README.md | 17 +++++++++++----- 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index df8a0e056d..7b14e4574b 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@
- Built with ❤️ by The LaunchBadge team + Built with ❤️ by The LaunchBadge team

@@ -59,20 +59,23 @@ SQLx is an async, pure Rust SQL crate featuring compile-time check - **Truly Asynchronous**. Built from the ground-up using async/await for maximum concurrency. -- **Type-safe SQL** (if you want it) without DSLs. Use the `query!()` macro to check your SQL and bind parameters at - compile time. (You can still use dynamic SQL queries if you like.) +- **Compile-time checked queries** (if you want). See [SQLx is not an ORM](#sqlx-is-not-an-orm). - **Database Agnostic**. Support for [PostgreSQL], [MySQL], [SQLite], and [MSSQL]. - **Pure Rust**. The Postgres and MySQL/MariaDB drivers are written in pure Rust using **zero** unsafe†† code. -* **Runtime Agnostic**. Works on different runtimes ([async-std](https://crates.io/crates/async-std) / [tokio](https://crates.io/crates/tokio) / [actix](https://crates.io/crates/actix-rt)) and TLS backends ([native-tls](https://crates.io/crates/native-tls), [rustls](https://crates.io/crates/rustls)). +- **Runtime Agnostic**. Works on different runtimes ([`async-std`] / [`tokio`] / [`actix`]) and TLS backends ([`native-tls`], [`rustls`]). -† The SQLite driver uses the libsqlite3 C library as SQLite is an embedded database (the only way -we could be pure Rust for SQLite is by porting _all_ of SQLite to Rust). + -†† SQLx uses `#![forbid(unsafe_code)]` unless the `sqlite` feature is enabled. As the SQLite driver interacts -with C, those interactions are `unsafe`. +† The SQLite driver uses the libsqlite3 C library as SQLite is an embedded database (the only way +we could be pure Rust for SQLite is by porting _all_ of SQLite to Rust). + +†† SQLx uses `#![forbid(unsafe_code)]` unless the `sqlite` feature is enabled. As the SQLite driver interacts +with C, those interactions are `unsafe`. + + [postgresql]: http://postgresql.org/ [sqlite]: https://sqlite.org/ @@ -108,6 +111,8 @@ SQLx is compatible with the [`async-std`], [`tokio`] and [`actix`] runtimes; and [`async-std`]: https://github.com/async-rs/async-std [`tokio`]: https://github.com/tokio-rs/tokio [`actix`]: https://github.com/actix/actix-net +[`native-tls`]: https://crates.io/crates/native-tls +[`rustls`]: https://crates.io/crates/rustls ```toml # Cargo.toml @@ -118,7 +123,7 @@ sqlx = { version = "0.5", features = [ "runtime-tokio-rustls" ] } sqlx = { version = "0.5", features = [ "runtime-async-std-native-tls" ] } ``` -The runtime and TLS backend not being separate feature sets to select is a workaround for a [Cargo issue](https://github.com/rust-lang/cargo/issues/3494). +The runtime and TLS backend not being separate feature sets to select is a workaround for a [Cargo issue](https://github.com/rust-lang/cargo/issues/3494). #### Cargo Feature Flags @@ -168,6 +173,24 @@ sqlx = { version = "0.5", features = [ "runtime-async-std-native-tls" ] } - `tls`: Add support for TLS connections. +## SQLx is not an ORM! + +SQLx supports **compile-time checked queries**. It does not, however, do this by providing a Rust +API or DSL (domain-specific language) for building queries. Instead, it provides macros that take +regular SQL as an input and ensure that it is valid for your database. The way this works is that +SQLx connects to your development DB at compile time to have the database itself verify (and return +some info on) your SQL queries. This has some potentially surprising implications: + +- Since SQLx never has to parse the SQL string itself, any syntax that the development DB accepts + can be used (including things added by database extensions) +- Due to the different amount of information databases let you retrieve about queries, the extent of + SQL verification you get from the query macros depends on the database + +**If you are looking for an (asynchronous) ORM,** you can check out [`ormx`], which is built on top +of SQLx. + +[`ormx`]: https://crates.io/crates/ormx + ## Usage ### Quickstart @@ -336,8 +359,8 @@ Differences from `query()`: ``` The biggest downside to `query!()` is that the output type cannot be named (due to Rust not -officially supporting anonymous records). To address that, there is a `query_as!()` macro that is identical -except that you can name the output type. +officially supporting anonymous records). To address that, there is a `query_as!()` macro that is +mostly identical except that you can name the output type. ```rust // no traits are needed @@ -359,6 +382,11 @@ WHERE organization = ? // countries[0].count ``` +To avoid the need of having a development database around to compile the project even when no +modifications (to the database-accessing parts of the code) are done, you can enable "offline mode" +to cache the results of the SQL query analysis using the `sqlx` command-line tool. See +[sqlx-cli/README.md](./sqlx-cli/README.md#enable-building-in-offline-mode-with-query). + ## Safety This crate uses `#![forbid(unsafe_code)]` to ensure everything is implemented in 100% Safe Rust. diff --git a/sqlx-cli/README.md b/sqlx-cli/README.md index 0c47941c4e..f098dad8ab 100644 --- a/sqlx-cli/README.md +++ b/sqlx-cli/README.md @@ -49,17 +49,19 @@ $ sqlx migrate run Compares the migration history of the running database against the `migrations/` folder and runs any scripts that are still pending. -#### Enable building in "offline" mode with `query!()` +#### Enable building in "offline mode" with `query!()` Note: must be run as `cargo sqlx`. ```bash cargo sqlx prepare ``` -Saves query data to `sqlx-data.json` in the current directory; check this file into version control -and an active database connection will no longer be needed to build your project. -Has no effect unless the `offline` feature of `sqlx` is enabled in your project. Omitting that feature is the most likely cause if you get a `sqlx-data.json` file that looks like this: +Saves query metadata to `sqlx-data.json` in the current directory; check this file into version +control and an active database connection will no longer be needed to build your project. + +Has no effect unless the `offline` feature of `sqlx` is enabled in your project. Omitting that +feature is the most likely cause if you get a `sqlx-data.json` file that looks like this: ```json { @@ -67,10 +69,12 @@ Has no effect unless the `offline` feature of `sqlx` is enabled in your project. } ``` ----- +--- + ```bash cargo sqlx prepare --check ``` + Exits with a nonzero exit status if the data in `sqlx-data.json` is out of date with the current database schema and queries in the project. Intended for use in Continuous Integration. @@ -79,3 +83,6 @@ database schema and queries in the project. Intended for use in Continuous Integ To make sure an accidentally-present `DATABASE_URL` environment variable or `.env` file does not result in `cargo build` (trying to) access the database, you can set the `SQLX_OFFLINE` environment variable to `true`. + +If you want to make this the default, just add it to your `.env` file. `cargo sqlx prepare` will +still do the right thing and connect to the database. From 358b80f62e84392c5efbfd4fa1e21a44c0705e42 Mon Sep 17 00:00:00 2001 From: Rohan Sharma Date: Wed, 2 Jun 2021 00:50:12 +0530 Subject: [PATCH 05/10] Rename _expr to expr (#1264) --- sqlx-macros/src/query/args.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sqlx-macros/src/query/args.rs b/sqlx-macros/src/query/args.rs index b46b7f664e..71094a67d2 100644 --- a/sqlx-macros/src/query/args.rs +++ b/sqlx-macros/src/query/args.rs @@ -79,13 +79,13 @@ pub fn quote_args( use ::sqlx::ty_match::{WrapSameExt as _, MatchBorrowExt as _}; // evaluate the expression only once in case it contains moves - let _expr = ::sqlx::ty_match::dupe_value(#name); + let expr = ::sqlx::ty_match::dupe_value(#name); - // if `_expr` is `Option`, get `Option<$ty>`, otherwise `$ty` - let ty_check = ::sqlx::ty_match::WrapSame::<#param_ty, _>::new(&_expr).wrap_same(); + // if `expr` is `Option`, get `Option<$ty>`, otherwise `$ty` + let ty_check = ::sqlx::ty_match::WrapSame::<#param_ty, _>::new(&expr).wrap_same(); - // if `_expr` is `&str`, convert `String` to `&str` - let (mut _ty_check, match_borrow) = ::sqlx::ty_match::MatchBorrow::new(ty_check, &_expr); + // if `expr` is `&str`, convert `String` to `&str` + let (mut _ty_check, match_borrow) = ::sqlx::ty_match::MatchBorrow::new(ty_check, &expr); _ty_check = match_borrow.match_borrow(); From cba5f64851a07204c5517391090cb2bdc9caf480 Mon Sep 17 00:00:00 2001 From: Vlad Beffa Date: Fri, 9 Jul 2021 17:07:58 -0500 Subject: [PATCH 06/10] redo changes from abhijeetbhagat:ws-support --- sqlx-bench/Cargo.toml | 13 ++++++++++ sqlx-bench/benches/wasm_querying.rs | 26 +++++++++++++++++++ sqlx-core/Cargo.toml | 2 ++ sqlx-rt/src/lib.rs | 11 +++++--- sqlx-test/Cargo.toml | 5 ++++ sqlx-wasm-test/Cargo.toml | 2 +- .../src/pg_types_tests_ipnetwork.rs | 1 - 7 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 sqlx-bench/benches/wasm_querying.rs diff --git a/sqlx-bench/Cargo.toml b/sqlx-bench/Cargo.toml index 0b288ca892..7d961f6e2f 100644 --- a/sqlx-bench/Cargo.toml +++ b/sqlx-bench/Cargo.toml @@ -32,6 +32,14 @@ runtime-tokio-rustls = [ "sqlx-rt/runtime-tokio-rustls", ] +runtime-wasm-bindgen = [ + "sqlx/runtime-wasm-bindgen", + "sqlx-rt/runtime-wasm-bindgen", + "_rt-wasm-bindgen" +] + +_rt-wasm-bindgen = [] + postgres = ["sqlx/postgres"] [dependencies] @@ -45,3 +53,8 @@ sqlx-rt = { version = "0.5", path = "../sqlx-rt", default-features = false } name = "pg_pool" harness = false required-features = ["postgres"] + +[[bench]] +name = "wasm_querying" +harness = false +required-features = ["postgres", "runtime-wasm-bindgen"] diff --git a/sqlx-bench/benches/wasm_querying.rs b/sqlx-bench/benches/wasm_querying.rs new file mode 100644 index 0000000000..0c6e89facd --- /dev/null +++ b/sqlx-bench/benches/wasm_querying.rs @@ -0,0 +1,26 @@ +use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use sqlx::Row; +use sqlx::{postgres::PgRow, Connection}; +use sqlx::{Database, PgConnection, Postgres}; +use sqlx_rt::spawn; + +const URL: &str = "postgresql://paul:pass123@127.0.0.1:8080/jetasap_dev"; + +fn select() { + spawn(async { + let mut conn = ::Connection::connect(URL) + .await + .unwrap(); + + let airports = sqlx::query("select * from airports") + .fetch_all(&mut conn) + .await; + }); +} + +fn criterion_benchmark(c: &mut Criterion) { + c.bench_function("fib 20", |b| b.iter(|| select())); +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); diff --git a/sqlx-core/Cargo.toml b/sqlx-core/Cargo.toml index c9c6e5b46a..01b33e3ab1 100644 --- a/sqlx-core/Cargo.toml +++ b/sqlx-core/Cargo.toml @@ -91,6 +91,7 @@ runtime-tokio-rustls = ["sqlx-rt/runtime-tokio-rustls", "_tls-rustls", "_rt-toki _rt-actix = ["tokio-stream"] _rt-async-std = [] _rt-tokio = ["tokio-stream"] +_rt-wasm-bindgen = ["getrandom"] _tls-native-tls = [] _tls-rustls = ["rustls", "webpki", "webpki-roots"] @@ -121,6 +122,7 @@ futures-channel = { version = "0.3.5", default-features = false, features = ["si futures-core = { version = "0.3.5", default-features = false } futures-util = { version = "0.3.5", features = ["sink"] } generic-array = { version = "0.14.4", default-features = false, optional = true } +getrandom = { version = "0.2.2", optional = true, features = ["js"] } hex = "0.4.2" hmac = { version = "0.10.1", default-features = false, optional = true } itoa = "0.4.5" diff --git a/sqlx-rt/src/lib.rs b/sqlx-rt/src/lib.rs index 527b66c580..6b31831d09 100644 --- a/sqlx-rt/src/lib.rs +++ b/sqlx-rt/src/lib.rs @@ -5,12 +5,11 @@ feature = "runtime-actix-rustls", feature = "runtime-async-std-rustls", feature = "runtime-tokio-rustls", - ) -))] +)))] compile_error!( "one of the features ['runtime-actix-native-tls', 'runtime-async-std-native-tls', \ 'runtime-tokio-native-tls', 'runtime-actix-rustls', 'runtime-async-std-rustls', \ - 'runtime-tokio-rustls'] must be enabled" + 'runtime-tokio-rustls', 'runtime-wasm-bindgen'] must be enabled" ); #[cfg(any( @@ -137,7 +136,11 @@ macro_rules! blocking { #[cfg(all( feature = "_rt-async-std", - not(any(feature = "_rt-actix", feature = "_rt-tokio")), + not(any( + feature = "_rt-actix", + feature = "_rt-tokio", + feature = "_rt-wasm-bindgen" + )), not(target_arch = "wasm32") ))] pub use async_std::{ diff --git a/sqlx-test/Cargo.toml b/sqlx-test/Cargo.toml index 60f299c1fe..6cbc72f143 100644 --- a/sqlx-test/Cargo.toml +++ b/sqlx-test/Cargo.toml @@ -4,6 +4,11 @@ version = "0.1.0" edition = "2018" publish = false +[features] +runtime-wasm-bindgen = ["_rt-wasm-bindgen"] + +_rt-wasm-bindgen = [] + [dependencies] sqlx = { default-features = false, path = ".." } env_logger = "0.7.1" diff --git a/sqlx-wasm-test/Cargo.toml b/sqlx-wasm-test/Cargo.toml index 8697ae7d69..e385dd691e 100644 --- a/sqlx-wasm-test/Cargo.toml +++ b/sqlx-wasm-test/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib", "rlib"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -sqlx = { path = "..", features = ["postgres", "decimal", "bigdecimal", "time", "chrono", "bit-vec", "ipnetwork", "uuid", "json"] } +sqlx = { path = "..", features = ["postgres", "decimal", "bigdecimal", "time", "chrono", "bit-vec", "ipnetwork", "uuid", "json", "runtime-wasm-bindgen"] } wasm-bindgen-futures = { version = "^0.3", features = ["futures_0_3"] } wasm-bindgen = { version = "0.2.73" } ws_stream_wasm = "0.7" diff --git a/sqlx-wasm-test/src/pg_types_tests_ipnetwork.rs b/sqlx-wasm-test/src/pg_types_tests_ipnetwork.rs index 206a15ff49..71e18bff8b 100644 --- a/sqlx-wasm-test/src/pg_types_tests_ipnetwork.rs +++ b/sqlx-wasm-test/src/pg_types_tests_ipnetwork.rs @@ -50,4 +50,3 @@ test_type!(ipnetwork_vec>(Postgres, "8.8.8.8/24".parse::().unwrap() ] )); - From 48ba951f00e40f0014c1b22d594f4d9cbdaa6e88 Mon Sep 17 00:00:00 2001 From: Vlad Beffa Date: Fri, 9 Jul 2021 17:48:39 -0500 Subject: [PATCH 07/10] wip --- Cargo.toml | 5 +++++ sqlx-rt/Cargo.toml | 1 + 2 files changed, 6 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 7336a90db7..26f74684e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -88,6 +88,10 @@ runtime-tokio-native-tls = [ "sqlx-macros/runtime-tokio-native-tls", "_rt-tokio", ] +runtime-wasm-bindgen = [ + "sqlx-core/_rt-wasm-bindgen", + "_rt-wasm-bindgen" +] runtime-actix-rustls = [ "sqlx-core/runtime-actix-rustls", @@ -109,6 +113,7 @@ runtime-tokio-rustls = [ _rt-actix = [] _rt-async-std = [] _rt-tokio = [] +_rt-wasm-bindgen = [] # database any = ["sqlx-core/any"] diff --git a/sqlx-rt/Cargo.toml b/sqlx-rt/Cargo.toml index 5d1cb0326e..785af7a3a0 100644 --- a/sqlx-rt/Cargo.toml +++ b/sqlx-rt/Cargo.toml @@ -18,6 +18,7 @@ runtime-async-std-native-tls = [ "async-native-tls", ] runtime-tokio-native-tls = ["_rt-tokio", "_tls-native-tls", "tokio-native-tls"] +runtime-wasm-bindgen = [] runtime-actix-rustls = ["_rt-actix", "_tls-rustls", "tokio-rustls"] runtime-async-std-rustls = ["_rt-async-std", "_tls-rustls", "async-rustls"] From 8ef5d0abfae26d3b4bc95f73fe03db7e9fae2df3 Mon Sep 17 00:00:00 2001 From: Vlad Beffa Date: Mon, 12 Jul 2021 14:03:46 -0500 Subject: [PATCH 08/10] remove runtime-wasm-bindgen feature --- Cargo.toml | 5 ----- sqlx-bench/Cargo.toml | 10 +--------- sqlx-core/Cargo.toml | 1 - sqlx-rt/src/lib.rs | 8 ++------ sqlx-test/Cargo.toml | 5 ----- sqlx-wasm-test/Cargo.toml | 2 +- 6 files changed, 4 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 26f74684e3..7336a90db7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -88,10 +88,6 @@ runtime-tokio-native-tls = [ "sqlx-macros/runtime-tokio-native-tls", "_rt-tokio", ] -runtime-wasm-bindgen = [ - "sqlx-core/_rt-wasm-bindgen", - "_rt-wasm-bindgen" -] runtime-actix-rustls = [ "sqlx-core/runtime-actix-rustls", @@ -113,7 +109,6 @@ runtime-tokio-rustls = [ _rt-actix = [] _rt-async-std = [] _rt-tokio = [] -_rt-wasm-bindgen = [] # database any = ["sqlx-core/any"] diff --git a/sqlx-bench/Cargo.toml b/sqlx-bench/Cargo.toml index 7d961f6e2f..167311ac53 100644 --- a/sqlx-bench/Cargo.toml +++ b/sqlx-bench/Cargo.toml @@ -32,14 +32,6 @@ runtime-tokio-rustls = [ "sqlx-rt/runtime-tokio-rustls", ] -runtime-wasm-bindgen = [ - "sqlx/runtime-wasm-bindgen", - "sqlx-rt/runtime-wasm-bindgen", - "_rt-wasm-bindgen" -] - -_rt-wasm-bindgen = [] - postgres = ["sqlx/postgres"] [dependencies] @@ -57,4 +49,4 @@ required-features = ["postgres"] [[bench]] name = "wasm_querying" harness = false -required-features = ["postgres", "runtime-wasm-bindgen"] +required-features = ["postgres"] diff --git a/sqlx-core/Cargo.toml b/sqlx-core/Cargo.toml index 01b33e3ab1..ce9463e572 100644 --- a/sqlx-core/Cargo.toml +++ b/sqlx-core/Cargo.toml @@ -91,7 +91,6 @@ runtime-tokio-rustls = ["sqlx-rt/runtime-tokio-rustls", "_tls-rustls", "_rt-toki _rt-actix = ["tokio-stream"] _rt-async-std = [] _rt-tokio = ["tokio-stream"] -_rt-wasm-bindgen = ["getrandom"] _tls-native-tls = [] _tls-rustls = ["rustls", "webpki", "webpki-roots"] diff --git a/sqlx-rt/src/lib.rs b/sqlx-rt/src/lib.rs index 6b31831d09..9b82302d99 100644 --- a/sqlx-rt/src/lib.rs +++ b/sqlx-rt/src/lib.rs @@ -9,7 +9,7 @@ compile_error!( "one of the features ['runtime-actix-native-tls', 'runtime-async-std-native-tls', \ 'runtime-tokio-native-tls', 'runtime-actix-rustls', 'runtime-async-std-rustls', \ - 'runtime-tokio-rustls', 'runtime-wasm-bindgen'] must be enabled" + 'runtime-tokio-rustls'] must be enabled" ); #[cfg(any( @@ -136,11 +136,7 @@ macro_rules! blocking { #[cfg(all( feature = "_rt-async-std", - not(any( - feature = "_rt-actix", - feature = "_rt-tokio", - feature = "_rt-wasm-bindgen" - )), + not(any(feature = "_rt-actix", feature = "_rt-tokio")), not(target_arch = "wasm32") ))] pub use async_std::{ diff --git a/sqlx-test/Cargo.toml b/sqlx-test/Cargo.toml index 6cbc72f143..60f299c1fe 100644 --- a/sqlx-test/Cargo.toml +++ b/sqlx-test/Cargo.toml @@ -4,11 +4,6 @@ version = "0.1.0" edition = "2018" publish = false -[features] -runtime-wasm-bindgen = ["_rt-wasm-bindgen"] - -_rt-wasm-bindgen = [] - [dependencies] sqlx = { default-features = false, path = ".." } env_logger = "0.7.1" diff --git a/sqlx-wasm-test/Cargo.toml b/sqlx-wasm-test/Cargo.toml index e385dd691e..8697ae7d69 100644 --- a/sqlx-wasm-test/Cargo.toml +++ b/sqlx-wasm-test/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib", "rlib"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -sqlx = { path = "..", features = ["postgres", "decimal", "bigdecimal", "time", "chrono", "bit-vec", "ipnetwork", "uuid", "json", "runtime-wasm-bindgen"] } +sqlx = { path = "..", features = ["postgres", "decimal", "bigdecimal", "time", "chrono", "bit-vec", "ipnetwork", "uuid", "json"] } wasm-bindgen-futures = { version = "^0.3", features = ["futures_0_3"] } wasm-bindgen = { version = "0.2.73" } ws_stream_wasm = "0.7" From 6c4e066e1a60aaef0c66a654ba62361c456c9c85 Mon Sep 17 00:00:00 2001 From: Vlad Beffa Date: Mon, 12 Jul 2021 14:08:02 -0500 Subject: [PATCH 09/10] remove runtime-wasm-bindgen feature --- sqlx-rt/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/sqlx-rt/Cargo.toml b/sqlx-rt/Cargo.toml index 785af7a3a0..5d1cb0326e 100644 --- a/sqlx-rt/Cargo.toml +++ b/sqlx-rt/Cargo.toml @@ -18,7 +18,6 @@ runtime-async-std-native-tls = [ "async-native-tls", ] runtime-tokio-native-tls = ["_rt-tokio", "_tls-native-tls", "tokio-native-tls"] -runtime-wasm-bindgen = [] runtime-actix-rustls = ["_rt-actix", "_tls-rustls", "tokio-rustls"] runtime-async-std-rustls = ["_rt-async-std", "_tls-rustls", "async-rustls"] From 6bec24e05426d91a7654b1235a0357b6eda9b07e Mon Sep 17 00:00:00 2001 From: Vlad Beffa Date: Mon, 12 Jul 2021 14:12:48 -0500 Subject: [PATCH 10/10] removed unneeded dependency --- sqlx-core/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/sqlx-core/Cargo.toml b/sqlx-core/Cargo.toml index ce9463e572..c9c6e5b46a 100644 --- a/sqlx-core/Cargo.toml +++ b/sqlx-core/Cargo.toml @@ -121,7 +121,6 @@ futures-channel = { version = "0.3.5", default-features = false, features = ["si futures-core = { version = "0.3.5", default-features = false } futures-util = { version = "0.3.5", features = ["sink"] } generic-array = { version = "0.14.4", default-features = false, optional = true } -getrandom = { version = "0.2.2", optional = true, features = ["js"] } hex = "0.4.2" hmac = { version = "0.10.1", default-features = false, optional = true } itoa = "0.4.5"