Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ SQLx is an async, pure Rust<sub>†</sub> SQL crate featuring compile-time check

- **Pure Rust**. The Postgres and MySQL/MariaDB drivers are written in pure Rust using **zero** unsafe<sub>††</sub> code.

- **Runtime Agnostic**. Works on different runtimes ([`async-std`] / [`tokio`] / [`actix`]) and TLS backends ([`native-tls`], [`rustls`]).
- **Runtime Agnostic**. Works on different runtimes ([`async-global-executor`], [`async-std`], [`smol`], [`tokio`]) and TLS backends ([`native-tls`], [`rustls`]).

<small><small>

Expand Down Expand Up @@ -119,11 +119,12 @@ The SQLite driver directly invokes the SQLite3 API via `libsqlite3-sys`, which r

## Install

SQLx is compatible with the [`async-std`], [`tokio`], and [`actix`] runtimes; and, the [`native-tls`] and [`rustls`] TLS backends. When adding the dependency, you must choose a runtime feature that is `runtime` + `tls`.
SQLx is compatible with the [`async-global-executor`], [`async-std`], [`smol`], and [`tokio`] runtimes; and, the [`native-tls`] and [`rustls`] TLS backends. When adding the dependency, you must choose a runtime feature that is `runtime` + `tls`.

[`async-global-executor`]: https://github.com/async-rs/async-global-executor
[`async-std`]: https://github.com/async-rs/async-std
[`smol`]: https://github.com/smol-rs/smol
[`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

Expand All @@ -132,6 +133,12 @@ SQLx is compatible with the [`async-std`], [`tokio`], and [`actix`] runtimes; an
[dependencies]
# PICK ONE OF THE FOLLOWING:

# async-global-executor (no TLS)
sqlx = { version = "0.9", features = [ "runtime-async-global-executor" ] }

# smol (no TLS)
sqlx = { version = "0.9", features = [ "runtime-smol" ] }

# tokio (no TLS)
sqlx = { version = "0.9", features = [ "runtime-tokio" ] }
# tokio + native-tls
Expand All @@ -142,17 +149,6 @@ sqlx = { version = "0.9", features = [ "runtime-tokio", "tls-rustls-ring-webpki"
sqlx = { version = "0.9", features = [ "runtime-tokio", "tls-rustls-ring-native-roots" ] }
# tokio + rustls with aws-lc-rs
sqlx = { version = "0.9", features = [ "runtime-tokio", "tls-rustls-aws-lc-rs" ] }

# async-std (no TLS)
sqlx = { version = "0.9", features = [ "runtime-async-std" ] }
# async-std + native-tls
sqlx = { version = "0.9", features = [ "runtime-async-std", "tls-native-tls" ] }
# async-std + rustls with ring and WebPKI CA certificates
sqlx = { version = "0.9", features = [ "runtime-async-std", "tls-rustls-ring-webpki" ] }
# async-std + rustls with ring and platform's native CA certificates
sqlx = { version = "0.9", features = [ "runtime-async-std", "tls-rustls-ring-native-roots" ] }
# async-std + rustls with aws-lc-rs
sqlx = { version = "0.9", features = [ "runtime-async-std", "tls-rustls-aws-lc-rs" ] }
```

#### Cargo Feature Flags
Expand All @@ -163,8 +159,12 @@ or separately.
For forward compatibility, you should use the separate runtime and TLS features as the combination features may
be removed in the future.

- `runtime-async-global-executor`: Use the `async-global-executor` runtime without enabling a TLS backend.

- `runtime-async-std`: Use the `async-std` runtime without enabling a TLS backend.

- `runtime-smol`: Use the `smol` runtime without enabling a TLS backend.

- `runtime-tokio`: Use the `tokio` runtime without enabling a TLS backend.

- Actix-web is fully compatible with Tokio and so a separate runtime feature is no longer needed.
Expand Down Expand Up @@ -253,9 +253,7 @@ use sqlx::postgres::PgPoolOptions;
// use sqlx::mysql::MySqlPoolOptions;
// etc.

#[async_std::main] // Requires the `attributes` feature of `async-std`
// or #[tokio::main]
// or #[actix_web::main]
#[tokio::main]
async fn main() -> Result<(), sqlx::Error> {
// Create a connection pool
// for MySQL/MariaDB, use MySqlPoolOptions::new()
Expand Down
18 changes: 9 additions & 9 deletions src/lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ Have a question? [Check our FAQ] or [open a discussion].

### Runtime Support

SQLx supports both the [Tokio] and [async-std] runtimes.
SQLx supports the [async-global-executor], [async-std], [smol], and [Tokio] runtimes.

You choose which runtime SQLx uses by default by enabling one of the following features:
Choose the runtime SQLx uses by enabling one of the following features:

* `runtime-async-global-executor`
* `runtime-async-std`
* `runtime-smol`
* `runtime-tokio`

If more than one runtime feature is enabled, the Tokio runtime is used if a Tokio context exists on the current
thread, i.e. [`tokio::runtime::Handle::try_current()`] returns `Ok`; `async-std` is used otherwise.

Note that while SQLx no longer produces a compile error if zero or multiple runtime features are enabled,
which is useful for libraries building on top of it,
Applications should generally enable exactly one runtime feature. SQLx does not produce a compile error if zero or
multiple runtime features are enabled, which is useful for libraries building on top of it, but
**the use of nearly any async function in the API will panic without at least one runtime feature enabled**.

The chief exception is the SQLite driver, which is runtime-agnostic, including its integration with the query macros.
Expand Down Expand Up @@ -57,7 +56,8 @@ will return an error.
[Check our FAQ]: https://www.github.com/launchbadge/sqlx/tree/main/FAQ.md
[open a discussion]: https://github.com/launchbadge/sqlx/discussions/new?category=q-a
[Tokio]: https://www.tokio.rs
[async-std]: https://www.async.rs
[`tokio::runtime::Handle::try_current()`]: https://docs.rs/tokio/latest/tokio/runtime/struct.Handle.html#method.try_current
[async-global-executor]: https://github.com/async-rs/async-global-executor
[async-std]: https://github.com/async-rs/async-std
[smol]: https://github.com/smol-rs/smol
[`native-tls`]: https://docs.rs/native-tls/latest/native_tls/
[rustls]: https://docs.rs/rustls/latest/rustls/
14 changes: 10 additions & 4 deletions src/macros/test.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
Mark an `async fn` as a test with SQLx support.

The test will automatically be executed in the async runtime according to the chosen
`runtime-{async-std, tokio}` feature. If more than one runtime feature is enabled, `runtime-tokio` is preferred.
`#[sqlx::test]` requires one of SQLx's runtime features:

By default, this behaves identically to `#[tokio::test]`<sup>1</sup> or `#[async_std::test]`:
* `runtime-async-global-executor`
* `runtime-async-std`
* `runtime-smol`
* `runtime-tokio`

Applications should generally enable exactly one runtime feature.

By default, this runs the async test to completion<sup>1</sup>:

```rust
# // Note if reading these examples directly in `test.md`:
Expand All @@ -18,7 +24,7 @@ async fn test_async_fn() {

However, several advanced features are also supported as shown in the next section.

<sup>1</sup>`#[sqlx::test]` does not recognize any of the control arguments supported by `#[tokio::test]`
<sup>1</sup>When `runtime-tokio` is selected, `#[sqlx::test]` does not recognize any of the control arguments supported by `#[tokio::test]`
as that would have complicated the implementation. If your use case requires any of those, feel free to open an issue.

### Automatic Test Database Management (requires `migrate` feature)
Expand Down
Loading