| 1 | The async SQL toolkit for Rust, built with ❤️ by [the LaunchBadge team]. |
| 2 | |
| 3 | See our [README] to get started or [browse our example projects]. |
| 4 | Have a question? [Check our FAQ] or [open a discussion]. |
| 5 | |
| 6 | ### Runtime Support |
| 7 | |
| 8 | SQLx supports both the [Tokio] and [async-std] runtimes. |
| 9 | |
| 10 | You choose which runtime SQLx uses by default by enabling one of the following features: |
| 11 | |
| 12 | * `runtime-async-std` |
| 13 | * `runtime-tokio` |
| 14 | |
| 15 | The `runtime-actix` feature also exists but is an alias of `runtime-tokio`. |
| 16 | |
| 17 | If more than one runtime feature is enabled, the Tokio runtime is used if a Tokio context exists on the current |
| 18 | thread, i.e. [`tokio::runtime::Handle::try_current()`] returns `Ok`; `async-std` is used otherwise. |
| 19 | |
| 20 | Note that while SQLx no longer produces a compile error if zero or multiple runtime features are enabled, |
| 21 | which is useful for libraries building on top of it, |
| 22 | **the use of nearly any async function in the API will panic without at least one runtime feature enabled**. |
| 23 | |
| 24 | The chief exception is the SQLite driver, which is runtime-agnostic, including its integration with the query macros. |
| 25 | However, [`SqlitePool`][crate::sqlite::SqlitePool] _does_ require runtime support for timeouts and spawning |
| 26 | internal management tasks. |
| 27 | |
| 28 | ### TLS Support |
| 29 | |
| 30 | For securely communicating with SQL servers over an untrusted network connection such as the internet, |
| 31 | you can enable Transport Layer Security (TLS) by enabling one of the following features: |
| 32 | |
| 33 | * `tls-native-tls`: Enables the [`native-tls`] backend which uses the OS-native TLS capabilities: |
| 34 | * SecureTransport on macOS. |
| 35 | * SChannel on Windows. |
| 36 | * OpenSSL on all other platforms. |
| 37 | * `tls-rustls`: Enables the [rustls] backend, a cross-platform TLS library. |
| 38 | * Only supports TLS revisions 1.2 and 1.3. |
| 39 | * If you get `HandshakeFailure` errors when using this feature, it likely means your database server does not support |
| 40 | these newer revisions. This might be resolved by enabling or switching to the `tls-native-tls` feature. |
| 41 | * rustls supports several providers of cryptographic primitives. The default |
| 42 | (enabled when you use the `tls-rustls` feature or `tls-rustls-ring`) is the |
| 43 | `ring` provider, which has fewer build-time dependencies but also has fewer |
| 44 | features. Alternatively, you can use `tls-rustls-aws-lc-rs` to use the |
| 45 | `aws-lc-rs` provider, which enables additional cipher suite support at the cost |
| 46 | of more onerous build requirements (depending on platform support). |
| 47 | |
| 48 | If more than one TLS feature is enabled, the `tls-native-tls` feature takes precedent so that it is only necessary to enable |
| 49 | it to see if it resolves the `HandshakeFailure` error without disabling `tls-rustls`. |
| 50 | |
| 51 | Consult the user manual for your database to find the TLS versions it supports. |
| 52 | |
| 53 | If your connection configuration requires a TLS upgrade but TLS support was not enabled, the connection attempt |
| 54 | will return an error. |
| 55 | |
| 56 | The legacy runtime+TLS combination feature flags are still supported, but for forward-compatibility, use of the separate |
| 57 | runtime and TLS feature flags is recommended. |
| 58 | |
| 59 | [the LaunchBadge team]: https://www.launchbadge.com |
| 60 | [README]: https://www.github.com/launchbadge/sqlx/tree/main/README.md |
| 61 | [browse our example projects]: https://www.github.com/launchbadge/sqlx/tree/main/examples |
| 62 | [Check our FAQ]: https://www.github.com/launchbadge/sqlx/tree/main/FAQ.md |
| 63 | [open a discussion]: https://github.com/launchbadge/sqlx/discussions/new?category=q-a |
| 64 | [Tokio]: https://www.tokio.rs |
| 65 | [async-std]: https://www.async.rs |
| 66 | [`tokio::runtime::Handle::try_current()`]: https://docs.rs/tokio/latest/tokio/runtime/struct.Handle.html#method.try_current |
| 67 | [`native-tls`]: https://docs.rs/native-tls/latest/native_tls/ |
| 68 | [rustls]: https://docs.rs/rustls/latest/rustls/ |