Skip to content

Commit

Permalink
redo changes from abhijeetbhagat:ws-support
Browse files Browse the repository at this point in the history
  • Loading branch information
vbeffa committed Jul 9, 2021
1 parent 38d57b5 commit cba5f64
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 6 deletions.
13 changes: 13 additions & 0 deletions sqlx-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"]
26 changes: 26 additions & 0 deletions sqlx-bench/benches/wasm_querying.rs
Original file line number Diff line number Diff line change
@@ -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 = <Postgres as Database>::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);
2 changes: 2 additions & 0 deletions sqlx-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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"
Expand Down
11 changes: 7 additions & 4 deletions sqlx-rt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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::{
Expand Down
5 changes: 5 additions & 0 deletions sqlx-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion sqlx-wasm-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion sqlx-wasm-test/src/pg_types_tests_ipnetwork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@ test_type!(ipnetwork_vec<Vec<sqlx::types::ipnetwork::IpNetwork>>(Postgres,
"8.8.8.8/24".parse::<sqlx::types::ipnetwork::IpNetwork>().unwrap()
]
));

0 comments on commit cba5f64

Please sign in to comment.