Rename cargo features in preparation for rustls support

This commit is contained in:
Jonas Platte 2020-10-20 12:29:24 +02:00 committed by Ryan Leckey
parent 04f68632b4
commit a161bcba05
23 changed files with 203 additions and 164 deletions

View file

@ -32,7 +32,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
runtime: [async-std, tokio, actix]
runtime: [async-std-native-tls, tokio-native-tls, actix-native-tls]
steps:
- uses: actions/checkout@v2
@ -145,7 +145,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
runtime: [async-std, tokio, actix]
runtime: [async-std-native-tls, tokio-native-tls, actix-native-tls]
needs: check
steps:
- uses: actions/checkout@v2
@ -181,7 +181,7 @@ jobs:
strategy:
matrix:
postgres: [12, 10, 9_6, 9_5]
runtime: [async-std, tokio, actix]
runtime: [async-std-native-tls, tokio-native-tls, actix-native-tls]
needs: check
steps:
- uses: actions/checkout@v2
@ -233,7 +233,7 @@ jobs:
strategy:
matrix:
mysql: [8, 5_7, 5_6]
runtime: [async-std, tokio, actix]
runtime: [async-std-native-tls, tokio-native-tls, actix-native-tls]
needs: check
steps:
- uses: actions/checkout@v2
@ -276,7 +276,7 @@ jobs:
strategy:
matrix:
mariadb: [10_5, 10_4, 10_3, 10_2, 10_1]
runtime: [async-std, tokio, actix]
runtime: [async-std-native-tls, tokio-native-tls, actix-native-tls]
needs: check
steps:
- uses: actions/checkout@v2
@ -320,7 +320,7 @@ jobs:
strategy:
matrix:
mssql: [2019]
runtime: [async-std, tokio, actix]
runtime: [async-std-native-tls, tokio-native-tls, actix-native-tls]
needs: check
steps:
- uses: actions/checkout@v2

View file

@ -37,7 +37,7 @@ features = [ "all" ]
rustdoc-args = ["--cfg", "docsrs"]
[features]
default = [ "macros", "runtime-async-std", "migrate" ]
default = [ "macros", "runtime-async-std-native-tls", "migrate" ]
macros = [ "sqlx-macros" ]
migrate = [ "sqlx-macros/migrate", "sqlx-core/migrate" ]
@ -53,10 +53,21 @@ all = [ "tls", "all-databases", "all-types" ]
all-databases = [ "mysql", "sqlite", "postgres", "mssql", "any" ]
all-types = [ "bigdecimal", "decimal", "json", "time", "chrono", "ipnetwork", "uuid", "bit-vec" ]
# runtime
runtime-async-std = [ "sqlx-core/runtime-async-std", "sqlx-macros/runtime-async-std" ]
runtime-actix = [ "sqlx-core/runtime-actix", "sqlx-macros/runtime-actix" ]
runtime-tokio = [ "sqlx-core/runtime-tokio", "sqlx-macros/runtime-tokio" ]
# previous runtimes, available as features for error messages better than just
# "feature doesn't exist"
runtime-actix = []
runtime-async-std = []
runtime-tokio = []
# actual runtimes
runtime-actix-native-tls = [ "sqlx-core/runtime-actix-native-tls", "sqlx-macros/runtime-actix-native-tls", "_rt-actix" ]
runtime-async-std-native-tls = [ "sqlx-core/runtime-async-std-native-tls", "sqlx-macros/runtime-async-std-native-tls", "_rt-async-std" ]
runtime-tokio-native-tls = [ "sqlx-core/runtime-tokio-native-tls", "sqlx-macros/runtime-tokio-native-tls", "_rt-tokio" ]
# for conditional compilation
_rt-actix = []
_rt-async-std = []
_rt-tokio = []
# database
any = [ "sqlx-core/any" ]

126
README.md
View file

@ -57,16 +57,16 @@
SQLx is an async, pure Rust<sub></sub> SQL crate featuring compile-time checked queries without a DSL.
* **Truly Asynchronous**. Built from the ground-up using async/await for maximum concurrency.
- **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.)
- **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.)
* **Database Agnostic**. Support for [PostgreSQL], [MySQL], [SQLite], and [MSSQL].
- **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<sub>††</sub> code.
- **Pure Rust**. The Postgres and MySQL/MariaDB drivers are written in pure Rust using **zero** unsafe<sub>††</sub> code.
* **Runtime Agnostic**. Works on [async-std](https://crates.io/crates/async-std) or [tokio](https://crates.io/crates/tokio) with the `runtime-async-std` or `runtime-tokio` cargo feature flag.
- **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)).
<sub><sup>† 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).</sup></sub>
@ -74,55 +74,50 @@ we could be pure Rust for SQLite is by porting _all_ of SQLite to Rust).</sup></
<sub><sup>†† SQLx uses `#![forbid(unsafe_code)]` unless the `sqlite` feature is enabled. As the SQLite driver interacts
with C, those interactions are `unsafe`.</sup></sub>
[PostgreSQL]: http://postgresql.org/
[SQLite]: https://sqlite.org/
[MySQL]: https://www.mysql.com/
[MSSQL]: https://www.microsoft.com/en-us/sql-server
[postgresql]: http://postgresql.org/
[sqlite]: https://sqlite.org/
[mysql]: https://www.mysql.com/
[mssql]: https://www.microsoft.com/en-us/sql-server
---
* Cross-platform. Being native Rust, SQLx will compile anywhere Rust is supported.
- Cross-platform. Being native Rust, SQLx will compile anywhere Rust is supported.
* Built-in connection pooling with `sqlx::Pool`.
- Built-in connection pooling with `sqlx::Pool`.
* Row streaming. Data is read asynchronously from the database and decoded on-demand.
- Row streaming. Data is read asynchronously from the database and decoded on-demand.
* Automatic statement preparation and caching. When using the high-level query API (`sqlx::query`), statements are
prepared and cached per-connection.
- Automatic statement preparation and caching. When using the high-level query API (`sqlx::query`), statements are
prepared and cached per-connection.
* Simple (unprepared) query execution including fetching results into the same `Row` types used by
the high-level API. Supports batch execution and returning results from all statements.
- Simple (unprepared) query execution including fetching results into the same `Row` types used by
the high-level API. Supports batch execution and returning results from all statements.
* Transport Layer Security (TLS) where supported ([MySQL] and [PostgreSQL]).
- Transport Layer Security (TLS) where supported ([MySQL] and [PostgreSQL]).
* Asynchronous notifications using `LISTEN` and `NOTIFY` for [PostgreSQL].
- Asynchronous notifications using `LISTEN` and `NOTIFY` for [PostgreSQL].
* Nested transactions with support for save points.
- Nested transactions with support for save points.
* `Any` database driver for changing the database driver at runtime. An `AnyPool` connects to the driver indicated by the URI scheme.
- `Any` database driver for changing the database driver at runtime. An `AnyPool` connects to the driver indicated by the URI scheme.
## Install
SQLx is compatible with the [`async-std`] and [`tokio`] runtimes.
SQLx is compatible with the [`async-std`], [`tokio`] and [`actix`] runtimes.
[`async-std`]: https://github.com/async-rs/async-std
[`tokio`]: https://github.com/tokio-rs/tokio
[`actix`]: https://github.com/actix/actix-net
**async-std**
By default, you get `async-std`. If you want a different runtime or TLS backend, just disable the default features and activate the corresponding feature, for example for tokio:
```toml
# Cargo.toml
[dependencies]
sqlx = "0.4.0-beta.1"
sqlx = { version = "0.4.0-beta.1", default-features = false, features = [ "runtime-tokio-native-tls", "macros" ] }
```
**tokio**
```toml
# Cargo.toml
[dependencies]
sqlx = { version = "0.4.0-beta.1", default-features = false, features = [ "runtime-tokio", "macros" ] }
```
<sub><sup>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).</sup></sub>
**actix**
@ -134,41 +129,41 @@ sqlx = { version = "0.4.0-beta.1", default-features = false, features = [ "runti
#### Cargo Feature Flags
* `runtime-async-std` (on by default): Use the `async-std` runtime.
- `runtime-async-std-native-tls` (on by default): Use the `async-std` runtime and `native-tls` TLS backend.
* `runtime-tokio`: Use the `tokio` runtime. Mutually exclusive to all other runtimes.
* `runtime-actix`: Use the `actix_rt` runtime. Mutually exclusive to all other runtimes.
- `runtime-tokio-native-tls`: Use the `tokio` runtime and `native-tls` TLS backend.
* `postgres`: Add support for the Postgres database server.
- `runtime-actix-native-tls`: Use the `actix` runtime and `native-tls` TLS backend.
* `mysql`: Add support for the MySQL (and MariaDB) database server.
- `postgres`: Add support for the Postgres database server.
* `mssql`: Add support for the MSSQL database server.
- `mysql`: Add support for the MySQL (and MariaDB) database server.
* `sqlite`: Add support for the self-contained [SQLite](https://sqlite.org/) database engine.
- `mssql`: Add support for the MSSQL database server.
* `any`: Add support for the `Any` database driver, which can proxy to a database driver at runtime.
- `sqlite`: Add support for the self-contained [SQLite](https://sqlite.org/) database engine.
* `macros`: Add support for the `query*!` macros, which allow compile-time checked queries.
* `migrate`: Add support for the migration management and `migrate!` macro, which allow compile-time embedded migrations.
- `any`: Add support for the `Any` database driver, which can proxy to a database driver at runtime.
* `uuid`: Add support for UUID (in Postgres).
- `macros`: Add support for the `query*!` macros, which allow compile-time checked queries.
* `chrono`: Add support for date and time types from `chrono`.
- `migrate`: Add support for the migration management and `migrate!` macro, which allow compile-time embedded migrations.
* `time`: Add support for date and time types from `time` crate (alternative to `chrono`, prefered by `query!` macro, if both enabled)
- `uuid`: Add support for UUID (in Postgres).
* `bigdecimal`: Add support for `NUMERIC` using the `bigdecimal` crate.
- `chrono`: Add support for date and time types from `chrono`.
* `decimal`: Add support for `NUMERIC` using the `rust_decimal` crate.
- `time`: Add support for date and time types from `time` crate (alternative to `chrono`, prefered by `query!` macro, if both enabled)
* `ipnetwork`: Add support for `INET` and `CIDR` (in postgres) using the `ipnetwork` crate.
- `bigdecimal`: Add support for `NUMERIC` using the `bigdecimal` crate.
* `json`: Add support for `JSON` and `JSONB` (in postgres) using the `serde_json` crate.
- `decimal`: Add support for `NUMERIC` using the `rust_decimal` crate.
* `tls`: Add support for TLS connections.
- `ipnetwork`: Add support for `INET` and `CIDR` (in postgres) using the `ipnetwork` crate.
- `json`: Add support for `JSON` and `JSONB` (in postgres) using the `serde_json` crate.
- `tls`: Add support for TLS connections.
## Usage
@ -310,30 +305,29 @@ WHERE organization = ?
Differences from `query()`:
* The input (or bind) parameters must be given all at once (and they are compile-time validated to be
the right number and the right type).
- The input (or bind) parameters must be given all at once (and they are compile-time validated to be
the right number and the right type).
* The output type is an anonymous record. In the above example the type would be similar to:
- The output type is an anonymous record. In the above example the type would be similar to:
```rust
{ country: String, count: i64 }
```
* The `DATABASE_URL` environment variable must be set at build time to a database which it can prepare
queries against; the database does not have to contain any data but must be the same
kind (MySQL, Postgres, etc.) and have the same schema as the database you will be connecting to at runtime.
- The `DATABASE_URL` environment variable must be set at build time to a database which it can prepare
queries against; the database does not have to contain any data but must be the same
kind (MySQL, Postgres, etc.) and have the same schema as the database you will be connecting to at runtime.
For convenience, you can use a .env file to set DATABASE_URL so that you don't have to pass it every time:
For convenience, you can use a .env file to set DATABASE_URL so that you don't have to pass it every time:
```
DATABASE_URL=mysql://localhost/my_database
```
```
DATABASE_URL=mysql://localhost/my_database
```
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.
```rust
// no traits are needed
struct Country { country: String, count: i64 }
@ -365,10 +359,10 @@ If the `sqlite` feature is enabled, this is downgraded to `#![deny(unsafe_code)]
Licensed under either of
* Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license
([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license
([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.

View file

@ -6,9 +6,9 @@ edition = "2018"
publish = false
[features]
runtime-actix = ["sqlx/runtime-actix", "sqlx-rt/runtime-actix"]
runtime-async-std = ["sqlx/runtime-async-std", "sqlx-rt/runtime-async-std"]
runtime-tokio = ["sqlx/runtime-tokio", "sqlx-rt/runtime-tokio"]
runtime-actix-native-tls = [ "sqlx/runtime-actix-native-tls", "sqlx-rt/runtime-actix-native-tls" ]
runtime-async-std-native-tls = [ "sqlx/runtime-async-std-native-tls", "sqlx-rt/runtime-async-std-native-tls" ]
runtime-tokio-native-tls = [ "sqlx/runtime-tokio-native-tls", "sqlx-rt/runtime-tokio-native-tls" ]
postgres = ["sqlx/postgres"]

View file

@ -23,8 +23,8 @@ This Cargo project implements various benchmarks for SQLx using
You must choose a runtime to execute the benchmarks on; the feature flags are the same as the `sqlx` crate:
```bash
cargo bench --features runtime-tokio
cargo bench --features runtime-async-std
cargo bench --features runtime-tokio-native-tls
cargo bench --features runtime-async-std-native-tls
```
When complete, the benchmark results will be in `target/criterion/`.

View file

@ -27,7 +27,7 @@ path = "src/bin/cargo-sqlx.rs"
[dependencies]
dotenv = "0.15"
tokio = { version = "0.2", features = ["macros"] }
sqlx = { version = "0.4.0-beta.1", path = "..", default-features = false, features = [ "runtime-async-std", "migrate", "any", "offline" ] }
sqlx = { version = "0.4.0-beta.1", path = "..", default-features = false, features = [ "runtime-async-std-native-tls", "migrate", "any", "offline" ] }
futures = "0.3"
clap = "=3.0.0-beta.2"
chrono = "0.4"

View file

@ -16,7 +16,7 @@ authors = [
features = ["all-databases", "all-types", "offline"]
[features]
default = [ "runtime-async-std", "migrate" ]
default = [ "runtime-async-std-native-tls", "migrate" ]
migrate = [ "sha2", "crc" ]
# databases
@ -34,9 +34,14 @@ decimal = [ "rust_decimal", "num-bigint" ]
json = [ "serde", "serde_json" ]
# runtimes
runtime-async-std = [ "sqlx-rt/runtime-async-std" ]
runtime-tokio = [ "sqlx-rt/runtime-tokio" ]
runtime-actix = [ "sqlx-rt/runtime-actix" ]
runtime-actix-native-tls = [ "sqlx-rt/runtime-actix-native-tls", "_rt-actix" ]
runtime-async-std-native-tls = [ "sqlx-rt/runtime-async-std-native-tls", "_rt-async-std" ]
runtime-tokio-native-tls = [ "sqlx-rt/runtime-tokio-native-tls", "_rt-tokio" ]
# for conditional compilation
_rt-actix = []
_rt-async-std = []
_rt-tokio = []
# support offline/decoupled building (enables serialization of `Describe`)
offline = [ "serde", "either/serde" ]

View file

@ -67,10 +67,10 @@ async fn upgrade(stream: &mut MySqlStream, options: &MySqlConnectOptions) -> Res
}
}
#[cfg(not(feature = "runtime-async-std"))]
#[cfg(not(feature = "_rt-async-std"))]
let connector = builder.build().map_err(Error::tls)?;
#[cfg(feature = "runtime-async-std")]
#[cfg(feature = "_rt-async-std")]
let connector = builder;
stream.upgrade(&options.host, connector.into()).await?;

View file

@ -35,7 +35,7 @@ pub use ssl_mode::MySqlSslMode;
/// # use sqlx_core::mysql::{MySqlConnectOptions, MySqlConnection, MySqlSslMode};
/// #
/// # fn main() {
/// # #[cfg(feature = "runtime-async-std")]
/// # #[cfg(feature = "_rt-async-std")]
/// # sqlx_rt::async_std::task::block_on::<_, Result<(), Error>>(async move {
/// // URI connection string
/// let conn = MySqlConnection::connect("mysql://root:password@localhost/db").await?;

View file

@ -60,7 +60,7 @@ impl AsyncRead for Socket {
}
}
#[cfg(any(feature = "runtime-actix", feature = "runtime-tokio"))]
#[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))]
fn poll_read_buf<B>(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
@ -102,7 +102,7 @@ impl AsyncWrite for Socket {
}
}
#[cfg(any(feature = "runtime-actix", feature = "runtime-tokio"))]
#[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))]
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
match &mut *self {
Socket::Tcp(s) => Pin::new(s).poll_shutdown(cx),
@ -112,7 +112,7 @@ impl AsyncWrite for Socket {
}
}
#[cfg(feature = "runtime-async-std")]
#[cfg(feature = "_rt-async-std")]
fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
match &mut *self {
Socket::Tcp(s) => Pin::new(s).poll_close(cx),
@ -122,7 +122,7 @@ impl AsyncWrite for Socket {
}
}
#[cfg(any(feature = "runtime-actix", feature = "runtime-tokio"))]
#[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))]
fn poll_write_buf<B>(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,

View file

@ -72,7 +72,7 @@ where
}
}
#[cfg(any(feature = "runtime-actix", feature = "runtime-tokio"))]
#[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))]
fn poll_read_buf<B>(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
@ -117,7 +117,7 @@ where
}
}
#[cfg(any(feature = "runtime-actix", feature = "runtime-tokio"))]
#[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))]
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
match &mut *self {
MaybeTlsStream::Raw(s) => Pin::new(s).poll_shutdown(cx),
@ -127,7 +127,7 @@ where
}
}
#[cfg(feature = "runtime-async-std")]
#[cfg(feature = "_rt-async-std")]
fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
match &mut *self {
MaybeTlsStream::Raw(s) => Pin::new(s).poll_close(cx),
@ -137,7 +137,7 @@ where
}
}
#[cfg(any(feature = "runtime-actix", feature = "runtime-tokio"))]
#[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))]
fn poll_write_buf<B>(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
@ -166,10 +166,10 @@ where
match self {
MaybeTlsStream::Raw(s) => s,
#[cfg(not(feature = "runtime-async-std"))]
#[cfg(not(feature = "_rt-async-std"))]
MaybeTlsStream::Tls(s) => s.get_ref().get_ref().get_ref(),
#[cfg(feature = "runtime-async-std")]
#[cfg(feature = "_rt-async-std")]
MaybeTlsStream::Tls(s) => s.get_ref(),
MaybeTlsStream::Upgrading => panic!(io::Error::from(io::ErrorKind::ConnectionAborted)),
@ -185,10 +185,10 @@ where
match self {
MaybeTlsStream::Raw(s) => s,
#[cfg(not(feature = "runtime-async-std"))]
#[cfg(not(feature = "_rt-async-std"))]
MaybeTlsStream::Tls(s) => s.get_mut().get_mut().get_mut(),
#[cfg(feature = "runtime-async-std")]
#[cfg(feature = "_rt-async-std")]
MaybeTlsStream::Tls(s) => s.get_mut(),
MaybeTlsStream::Upgrading => panic!(io::Error::from(io::ErrorKind::ConnectionAborted)),

View file

@ -84,10 +84,10 @@ async fn upgrade(stream: &mut PgStream, options: &PgConnectOptions) -> Result<bo
}
}
#[cfg(not(feature = "runtime-async-std"))]
#[cfg(not(feature = "_rt-async-std"))]
let connector = builder.build().map_err(Error::tls)?;
#[cfg(feature = "runtime-async-std")]
#[cfg(feature = "_rt-async-std")]
let connector = builder;
stream.upgrade(&options.host, connector.into()).await?;

View file

@ -150,7 +150,7 @@ impl PgListener {
/// # use sqlx_core::postgres::PgListener;
/// # use sqlx_core::error::Error;
/// #
/// # #[cfg(feature = "runtime-async-std")]
/// # #[cfg(feature = "_rt-async-std")]
/// # sqlx_rt::block_on::<_, Result<(), Error>>(async move {
/// # let mut listener = PgListener::connect("postgres:// ...").await?;
/// loop {
@ -183,7 +183,7 @@ impl PgListener {
/// # use sqlx_core::postgres::PgListener;
/// # use sqlx_core::error::Error;
/// #
/// # #[cfg(feature = "runtime-async-std")]
/// # #[cfg(feature = "_rt-async-std")]
/// # sqlx_rt::block_on::<_, Result<(), Error>>(async move {
/// # let mut listener = PgListener::connect("postgres:// ...").await?;
/// loop {

View file

@ -54,7 +54,7 @@ pub use ssl_mode::PgSslMode;
/// # use sqlx_core::postgres::{PgConnectOptions, PgConnection, PgSslMode};
/// #
/// # fn main() {
/// # #[cfg(feature = "runtime-async-std")]
/// # #[cfg(feature = "_rt-async-std")]
/// # sqlx_rt::async_std::task::block_on::<_, Result<(), Error>>(async move {
/// // URI connection string
/// let conn = PgConnection::connect("postgres://localhost/mydb").await?;

View file

@ -31,7 +31,7 @@ use std::{borrow::Cow, time::Duration};
/// use std::str::FromStr;
///
/// # fn main() {
/// # #[cfg(feature = "runtime-async-std")]
/// # #[cfg(feature = "_rt-async-std")]
/// # sqlx_rt::async_std::task::block_on::<_, Result<(), Error>>(async move {
/// let conn = SqliteConnectOptions::from_str("sqlite://data.db")?
/// .journal_mode(SqliteJournalMode::Wal)

View file

@ -16,13 +16,18 @@ authors = [
proc-macro = true
[features]
default = [ "runtime-async-std", "migrate" ]
default = [ "runtime-async-std-native-tls", "migrate" ]
migrate = [ "sha2" ]
# runtimes
runtime-async-std = [ "sqlx-core/runtime-async-std", "sqlx-rt/runtime-async-std" ]
runtime-tokio = [ "sqlx-core/runtime-tokio", "sqlx-rt/runtime-tokio" ]
runtime-actix = [ "sqlx-core/runtime-actix", "sqlx-rt/runtime-actix" ]
runtime-actix-native-tls = [ "sqlx-core/runtime-actix-native-tls", "sqlx-rt/runtime-actix-native-tls", "_rt-actix" ]
runtime-async-std-native-tls = [ "sqlx-core/runtime-async-std-native-tls", "sqlx-rt/runtime-async-std-native-tls", "_rt-async-std" ]
runtime-tokio-native-tls = [ "sqlx-core/runtime-tokio-native-tls", "sqlx-rt/runtime-tokio-native-tls", "_rt-tokio" ]
# for conditional compilation
_rt-actix = []
_rt-async-std = []
_rt-tokio = []
# offline building support
offline = ["sqlx-core/offline", "serde", "serde_json", "hex", "sha2"]

View file

@ -103,7 +103,7 @@ pub fn test(_attr: TokenStream, input: TokenStream) -> TokenStream {
let body = &input.block;
let attrs = &input.attrs;
let result = if cfg!(feature = "runtime-tokio") {
let result = if cfg!(feature = "_rt-tokio") {
quote! {
#[test]
#(#attrs)*
@ -117,7 +117,7 @@ pub fn test(_attr: TokenStream, input: TokenStream) -> TokenStream {
.block_on(async { #body })
}
}
} else if cfg!(feature = "runtime-async-std") {
} else if cfg!(feature = "_rt-async-std") {
quote! {
#[test]
#(#attrs)*
@ -125,7 +125,7 @@ pub fn test(_attr: TokenStream, input: TokenStream) -> TokenStream {
sqlx_rt::async_std::task::block_on(async { #body })
}
}
} else if cfg!(feature = "runtime-actix") {
} else if cfg!(feature = "_rt-actix") {
quote! {
#[test]
#(#attrs)*

View file

@ -11,9 +11,15 @@ authors = [
]
[features]
runtime-actix = [ "actix-rt", "actix-threadpool", "tokio", "tokio-native-tls", "once_cell" ]
runtime-async-std = [ "async-std", "async-native-tls" ]
runtime-tokio = [ "tokio", "tokio-native-tls", "once_cell" ]
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" ]
# 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" ]
[dependencies]
async-native-tls = { version = "0.3.3", optional = true }
@ -22,5 +28,5 @@ actix-threadpool = { version = "0.3.2", optional = true }
async-std = { version = "1.6.0", 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 }
native-tls = "0.2.4"
native-tls = { version = "0.2.4", optional = true }
once_cell = { version = "1.4", features = ["std"], optional = true }

View file

@ -1,21 +1,24 @@
#[cfg(not(any(
feature = "runtime-actix",
feature = "runtime-async-std",
feature = "runtime-tokio",
feature = "runtime-actix-native-tls",
feature = "runtime-async-std-native-tls",
feature = "runtime-tokio-native-tls",
)))]
compile_error!(
"one of 'runtime-actix', 'runtime-async-std' or 'runtime-tokio' features must be enabled"
"one of the features ['runtime-actix-native-tls', 'runtime-async-std-native-tls', \
'runtime-tokio-native-tls'] must be enabled"
);
#[cfg(any(
all(feature = "runtime-actix", feature = "runtime-async-std"),
all(feature = "runtime-actix", feature = "runtime-tokio"),
all(feature = "runtime-async-std", feature = "runtime-tokio"),
all(feature = "_rt-actix", feature = "_rt-async-std"),
all(feature = "_rt-actix", feature = "_rt-tokio"),
all(feature = "_rt-async-std", feature = "_rt-tokio"),
))]
compile_error!(
"only one of 'runtime-actix', 'runtime-async-std' or 'runtime-tokio' features can be enabled"
"only one of ['runtime-actix-native-tls', 'runtime-async-std-native-tls', \
'runtime-tokio-native-tls'] can be enabled"
);
#[cfg(all(feature = "_tls-native-tls"))]
pub use native_tls::{self, Error as TlsError};
//
@ -23,8 +26,8 @@ pub use native_tls::{self, Error as TlsError};
//
#[cfg(all(
any(feature = "runtime-tokio", feature = "runtime-actix"),
not(feature = "runtime-async-std"),
any(feature = "_rt-tokio", feature = "_rt-actix"),
not(feature = "_rt-async-std"),
))]
pub use tokio::{
self, fs, io::AsyncRead, io::AsyncReadExt, io::AsyncWrite, io::AsyncWriteExt, net::TcpStream,
@ -33,12 +36,16 @@ pub use tokio::{
#[cfg(all(
unix,
any(feature = "runtime-tokio", feature = "runtime-actix"),
not(feature = "runtime-async-std"),
any(feature = "_rt-tokio", feature = "_rt-actix"),
not(feature = "_rt-async-std"),
))]
pub use tokio::net::UnixStream;
#[cfg(all(feature = "tokio-native-tls", not(feature = "async-native-tls")))]
#[cfg(all(
feature = "_tls-native-tls",
any(feature = "_rt-tokio", feature = "_rt-actix"),
not(feature = "_rt-async-std"),
))]
pub use tokio_native_tls::{TlsConnector, TlsStream};
//
@ -46,8 +53,8 @@ pub use tokio_native_tls::{TlsConnector, TlsStream};
//
#[cfg(all(
feature = "runtime-tokio",
not(any(feature = "runtime-actix", feature = "runtime-async-std",))
feature = "_rt-tokio",
not(any(feature = "_rt-actix", feature = "_rt-async-std")),
))]
#[macro_export]
macro_rules! blocking {
@ -60,12 +67,12 @@ macro_rules! blocking {
// actix
//
#[cfg(feature = "runtime-actix")]
#[cfg(feature = "_rt-actix")]
pub use {actix_rt, actix_threadpool};
#[cfg(all(
feature = "runtime-actix",
not(any(feature = "runtime-tokio", feature = "runtime-async-std",))
feature = "_rt-actix",
not(any(feature = "_rt-tokio", feature = "_rt-async-std")),
))]
#[macro_export]
macro_rules! blocking {
@ -82,8 +89,8 @@ macro_rules! blocking {
//
#[cfg(all(
feature = "runtime-async-std",
not(any(feature = "runtime-actix", feature = "runtime-tokio",))
feature = "_rt-async-std",
not(any(feature = "_rt-actix", feature = "_rt-tokio")),
))]
pub use async_std::{
self, fs, future::timeout, io::prelude::ReadExt as AsyncReadExt,
@ -92,8 +99,8 @@ pub use async_std::{
};
#[cfg(all(
feature = "runtime-async-std",
not(any(feature = "runtime-actix", feature = "runtime-tokio",))
feature = "_rt-async-std",
not(any(feature = "_rt-actix", feature = "_rt-tokio")),
))]
#[macro_export]
macro_rules! blocking {
@ -104,8 +111,8 @@ macro_rules! blocking {
#[cfg(all(
unix,
feature = "runtime-async-std",
not(any(feature = "runtime-actix", feature = "runtime-tokio",))
feature = "_rt-async-std",
not(any(feature = "_rt-actix", feature = "_rt-tokio")),
))]
pub use async_std::os::unix::net::UnixStream;
@ -113,14 +120,14 @@ pub use async_std::os::unix::net::UnixStream;
pub use async_native_tls::{TlsConnector, TlsStream};
#[cfg(all(
feature = "runtime-async-std",
not(any(feature = "runtime-actix", feature = "runtime-tokio"))
feature = "_rt-async-std",
not(any(feature = "_rt-actix", feature = "_rt-tokio")),
))]
pub use async_std::task::block_on;
#[cfg(all(
feature = "runtime-async-std",
not(any(feature = "runtime-actix", feature = "runtime-tokio"))
feature = "_rt-async-std",
not(any(feature = "_rt-actix", feature = "_rt-tokio")),
))]
pub fn enter_runtime<F, R>(f: F) -> R
where
@ -131,12 +138,12 @@ where
}
#[cfg(all(
any(feature = "runtime-tokio", feature = "runtime-actix"),
not(feature = "runtime-async-std")
any(feature = "_rt-tokio", feature = "_rt-actix"),
not(feature = "_rt-async-std"),
))]
pub use tokio_runtime::{block_on, enter_runtime};
#[cfg(any(feature = "runtime-tokio", feature = "runtime-actix"))]
#[cfg(any(feature = "_rt-tokio", feature = "_rt-actix"))]
mod tokio_runtime {
use once_cell::sync::Lazy;
use tokio::runtime::{self, Runtime};

View file

@ -1,5 +1,16 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
#[cfg(any(
feature = "runtime-actix",
feature = "runtime-async-std",
feature = "runtime-tokio"
))]
compile_error!(
"the features 'runtime-actix', 'runtime-async-std' and 'runtime-tokio' have been removed in
favor of new features 'runtime-{rt}-{tls}' where rt is one of 'actix', 'async-std' and
'tokio'."
);
pub use sqlx_core::acquire::Acquire;
pub use sqlx_core::arguments::{Arguments, IntoArguments};
pub use sqlx_core::column::Column;

View file

@ -5,7 +5,7 @@
///
/// ```rust,ignore
/// # use sqlx::Connect;
/// # #[cfg(all(feature = "mysql", feature = "runtime-async-std"))]
/// # #[cfg(all(feature = "mysql", feature = "_rt-async-std"))]
/// # #[async_std::main]
/// # async fn main() -> sqlx::Result<()>{
/// # let db_url = dotenv::var("DATABASE_URL").expect("DATABASE_URL must be set");
@ -24,7 +24,7 @@
/// # Ok(())
/// # }
/// #
/// # #[cfg(any(not(feature = "mysql"), not(feature = "runtime-async-std")))]
/// # #[cfg(any(not(feature = "mysql"), not(feature = "_rt-async-std")))]
/// # fn main() {}
/// ```
///
@ -54,7 +54,7 @@
///
/// ```rust,ignore
/// # use sqlx::Connect;
/// # #[cfg(all(feature = "mysql", feature = "runtime-async-std"))]
/// # #[cfg(all(feature = "mysql", feature = "_rt-async-std"))]
/// # #[async_std::main]
/// # async fn main() -> sqlx::Result<()>{
/// # let db_url = dotenv::var("DATABASE_URL").expect("DATABASE_URL must be set");
@ -75,7 +75,7 @@
/// # Ok(())
/// # }
/// #
/// # #[cfg(any(not(feature = "mysql"), not(feature = "runtime-async-std")))]
/// # #[cfg(any(not(feature = "mysql"), not(feature = "_rt-async-std")))]
/// # fn main() {}
/// ```
///
@ -328,7 +328,7 @@ macro_rules! query_unchecked (
/// `src/my_query.rs`:
/// ```rust,ignore
/// # use sqlx::Connect;
/// # #[cfg(all(feature = "mysql", feature = "runtime-async-std"))]
/// # #[cfg(all(feature = "mysql", feature = "_rt-async-std"))]
/// # #[async_std::main]
/// # async fn main() -> sqlx::Result<()>{
/// # let db_url = dotenv::var("DATABASE_URL").expect("DATABASE_URL must be set");
@ -345,7 +345,7 @@ macro_rules! query_unchecked (
/// # Ok(())
/// # }
/// #
/// # #[cfg(any(not(feature = "mysql"), not(feature = "runtime-async-std")))]
/// # #[cfg(any(not(feature = "mysql"), not(feature = "_rt-async-std")))]
/// # fn main() {}
/// ```
#[macro_export]
@ -397,7 +397,7 @@ macro_rules! query_file_unchecked (
/// string:
/// ```rust,ignore
/// # use sqlx::Connect;
/// # #[cfg(all(feature = "mysql", feature = "runtime-async-std"))]
/// # #[cfg(all(feature = "mysql", feature = "_rt-async-std"))]
/// # #[async_std::main]
/// # async fn main() -> sqlx::Result<()>{
/// # let db_url = dotenv::var("DATABASE_URL").expect("DATABASE_URL must be set");
@ -425,7 +425,7 @@ macro_rules! query_file_unchecked (
/// # Ok(())
/// # }
/// #
/// # #[cfg(any(not(feature = "mysql"), not(feature = "runtime-async-std")))]
/// # #[cfg(any(not(feature = "mysql"), not(feature = "_rt-async-std")))]
/// # fn main() {}
/// ```
///
@ -526,7 +526,7 @@ macro_rules! query_as (
///
/// ```rust,ignore
/// # use sqlx::Connect;
/// # #[cfg(all(feature = "mysql", feature = "runtime-async-std"))]
/// # #[cfg(all(feature = "mysql", feature = "_rt-async-std"))]
/// # #[async_std::main]
/// # async fn main() -> sqlx::Result<()>{
/// # let db_url = dotenv::var("DATABASE_URL").expect("DATABASE_URL must be set");
@ -550,7 +550,7 @@ macro_rules! query_as (
/// # Ok(())
/// # }
/// #
/// # #[cfg(any(not(feature = "mysql"), not(feature = "runtime-async-std")))]
/// # #[cfg(any(not(feature = "mysql"), not(feature = "_rt-async-std")))]
/// # fn main() {}
/// ```
#[macro_export]

View file

@ -335,7 +335,7 @@ async fn it_can_prepare_then_execute() -> anyhow::Result<()> {
}
// repro is more reliable with the basic scheduler used by `#[tokio::test]`
#[cfg(feature = "runtime-tokio")]
#[cfg(feature = "_rt-tokio")]
#[tokio::test]
async fn test_issue_622() -> anyhow::Result<()> {
use std::time::Instant;

View file

@ -454,10 +454,10 @@ async fn it_can_drop_multiple_transactions() -> anyhow::Result<()> {
#[ignore]
#[sqlx_macros::test]
async fn pool_smoke_test() -> anyhow::Result<()> {
#[cfg(any(feature = "runtime-tokio", feature = "runtime-actix"))]
#[cfg(any(feature = "_rt-tokio", feature = "_rt-actix"))]
use tokio::{task::spawn, time::delay_for as sleep, time::timeout};
#[cfg(feature = "runtime-async-std")]
#[cfg(feature = "_rt-async-std")]
use async_std::{future::timeout, task::sleep, task::spawn};
eprintln!("starting pool");
@ -711,7 +711,7 @@ async fn it_can_prepare_then_execute() -> anyhow::Result<()> {
}
// repro is more reliable with the basic scheduler used by `#[tokio::test]`
#[cfg(feature = "runtime-tokio")]
#[cfg(feature = "_rt-tokio")]
#[tokio::test]
async fn test_issue_622() -> anyhow::Result<()> {
use std::time::Instant;