TheDocumentation 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.
Any driver is a thin runtime-dispatch layer that routes connections to the correct underlying driver based on the URL scheme. It lets you write code that works against AnyPool and AnyConnection without specifying a concrete database type, with the actual backend chosen at startup from environment variables or configuration. This is useful for libraries that must support multiple databases, or for codebases that test against SQLite locally and deploy against PostgreSQL in production.
Feature flag
Enable theany feature alongside at least one concrete driver:
any is part of SQLx’s default feature set, so if you are not overriding default-features it is already enabled.
Installing drivers
Before creating anyAnyPool or AnyConnection, you must register the set of available drivers exactly once at process startup by calling sqlx::any::install_default_drivers(). Without this call, any attempt to open a connection will panic.
install_default_drivers registers every driver that was compiled in (controlled by feature flags). If you need fine-grained control over which drivers are available, use the lower-level sqlx::any::install_drivers instead.
URL-based routing
TheAny driver selects the underlying driver from the URL scheme:
| URL scheme | Driver used |
|---|---|
postgres:// or postgresql:// | PostgreSQL driver |
mysql:// | MySQL / MariaDB driver |
sqlite: | SQLite driver |
AnyPool) and expose the same API, while the work is delegated to the appropriate concrete driver.
Core types
| Type | Description |
|---|---|
AnyPool | Alias for Pool<Any>. Manages a pool of AnyConnections. |
AnyConnection | A single database-agnostic connection. |
AnyRow | A row returned by an Any query. |
AnyConnectOptions | Parsed connection options; the scheme determines the driver. |
AnyPoolOptions | Alias for PoolOptions<Any>. |
Writing database-agnostic code
UseAnyPool as the connection source throughout your application layer:
- Postgres (production)
- SQLite (local / CI)
Testing with SQLite, deploying on PostgreSQL
A common pattern is to run fast integration tests against an in-memory SQLite database and deploy against PostgreSQL:Limitations
TheAny driver is a useful abstraction, but it has inherent constraints compared to using a concrete driver directly:
No driver-specific types
PostgreSQL-specific types (
JSONB, arrays, ranges, custom enums), MySQL-specific types, and SQLite pragmas are not accessible through the Any API. Use the concrete driver when you need these features.No driver-specific extensions
PgListener (LISTEN/NOTIFY), advisory locks, PostgreSQL COPY, and other driver-specific APIs are not available via AnyPool. Acquire a typed connection when needed.SQL dialect differences
Bind parameter syntax differs: PostgreSQL uses
$1, MySQL uses ?, and SQLite accepts both. The Any driver does not normalise SQL; you must write queries that are valid in all target databases.compile-time macros unsupported
The
query! and query_as! macros require a concrete database URL at compile time and do not work with AnyPool. Use the runtime sqlx::query() API instead.Third-party drivers (e.g.
sqlx-exasol) can be registered with sqlx::any::install_drivers and used through AnyPool as long as they implement the AnyDriver trait. Since SQLx 0.7, drivers no longer need to be compiled into the sqlx crate itself.