Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/launchbadge/sqlx/llms.txt

Use this file to discover all available pages before exploring further.

SQLx is a highly modular crate. Almost all functionality — including the async runtime, TLS backend, database drivers, and Rust type integrations — is gated behind Cargo feature flags. You must enable at least one runtime feature and one database feature to compile a working SQLx integration. The default feature set is any, macros, migrate, and json. In most cases you will want to replace this with an explicit list tailored to your project.
[dependencies]
sqlx = { version = "0.8", default-features = false, features = [
    "runtime-tokio",
    "tls-rustls-ring-webpki",
    "postgres",
    "macros",
    "migrate",
    "uuid",
    "chrono",
] }

Runtime features

Exactly one runtime feature must be enabled. These features are not TLS-coupled — pair them with a TLS feature separately.
FeatureAsync runtime
runtime-tokioTokio
runtime-async-stdasync-std
runtime-async-global-executorasync-global-executor
runtime-smolsmol

TLS features

TLS is required by most hosted databases over public networks. Choose one TLS backend, or use tls-none to compile without TLS support (useful for local development or when the connection is secured at the network layer).
FeatureBackend
tls-rustls-ring-webpkirustls with the Ring crypto provider and WebPKI roots
tls-rustls-ring-native-rootsrustls with Ring and native system certificate roots
tls-rustls-aws-lc-rsrustls with the AWS-LC-rs crypto provider
tls-native-tlsPlatform-native TLS (openssl on Linux, Secure Transport on macOS, SChannel on Windows)
tls-noneNo TLS support (compile-time no-op flag)
tls-rustls-ring and tls-rustls are kept as aliases for backward compatibility. They resolve to tls-rustls-ring-webpki. Prefer the explicit names in new projects.

Database features

Enable exactly the drivers you need.
FeatureDriver
postgresPostgreSQL and compatible databases
mysqlMySQL and MariaDB
mysql-rsaAdds RSA-encrypted password support for MySQL (sha2_password / caching_sha2_password)
sqliteSQLite via bundled libsqlite3. Enables sqlite-bundled, sqlite-deserialize, sqlite-load-extension, and sqlite-unlock-notify
sqlite-bundledSQLite with a bundled copy of libsqlite3 (requires a C compiler)
sqlite-unbundledSQLite linking against the system-provided libsqlite3
anyType-erased AnyPool / AnyConnection that dispatches to any enabled driver at runtime

SQLite sub-features

These features expose conditionally compiled SQLite APIs. They require sqlite-bundled or sqlite-unbundled to also be enabled, and some require specific compile-time flags on the underlying C library.
FeatureDescription
sqlite-deserializeEnables SqliteConnection::deserialize() and ::serialize(). Incompatible with -DSQLITE_OMIT_DESERIALIZE; requires -DSQLITE_ENABLE_DESERIALIZE on SQLite < 3.36.0.
sqlite-load-extensionEnables SqliteConnectOptions::extension() and ::extension_with_entrypoint(). Also required to use drivers.sqlite.unsafe-load-extensions in sqlx.toml. Incompatible with -DSQLITE_OMIT_LOAD_EXTENSION.
sqlite-preupdate-hookEnables sqlite3_preupdate_hook. Requires -DSQLITE_ENABLE_PREUPDATE_HOOK (set automatically by sqlite-bundled).
sqlite-unlock-notifyEnables internal handling of SQLITE_LOCKED_SHAREDCACHE. Requires -DSQLITE_ENABLE_UNLOCK_NOTIFY (set automatically by sqlite-bundled).

Macro and utility features

FeatureDescription
macrosEnables the query!, query_as!, query_scalar!, and query_file! compile-time macro family. Enables derive and offline mode.
deriveEnables #[derive(FromRow)] and #[derive(Type)].
migrateEnables sqlx::migrate!() and the migration runner.
sqlx-tomlEnables parsing of a sqlx.toml configuration file in the crate root. Not enabled by default. See the sqlx.toml configuration reference.

Type features

These features add support for mapping database types to popular Rust crates. Each feature enables integration across all drivers that support the corresponding SQL type.
FeatureRust crateSQL types
jsonserde_json::ValueJSON, JSONB
uuiduuidUUID
chronochronoDATE, TIME, DATETIME, TIMESTAMP
timetimeDATE, TIME, DATETIME, TIMESTAMP
bigdecimalbigdecimalNUMERIC, DECIMAL
rust_decimalrust_decimalNUMERIC, DECIMAL
ipnetipnetCIDR, INET (Postgres)
ipnetworkipnetworkCIDR, INET (Postgres)
mac_addressmac_addressMACADDR (Postgres)
bit-vecbit-vecBIT, VARBIT (Postgres)
bstrbstrBinary string types
When both chrono and time are enabled (for example via Cargo feature unification), time takes precedence. Similarly, when both bigdecimal and rust_decimal are enabled, rust_decimal takes precedence. Use sqlx.toml with the sqlx-toml feature to override this behavior — see macros.preferred-crates.

Build docs developers (and LLMs) love