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() ] )); -