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 an async, pure Rust SQL crate that lets you write plain SQL and have the compiler verify it — without a domain-specific language, query builder, or object-relational mapper. It connects to your database at compile time so that your queries are checked for correctness before your code ever runs.

Key features

Truly async

Built from the ground up using async/await for maximum concurrency. No blocking calls, no threads-per-connection overhead.

Compile-time query verification

The query! macro talks to your development database at build time to verify SQL syntax, parameter counts, and result types.

Pure Rust drivers

The PostgreSQL and MySQL/MariaDB drivers are written in pure Rust with zero unsafe code. SQLite wraps the C libsqlite3 library.

Multi-database

First-class support for PostgreSQL, MySQL, MariaDB, and SQLite through a shared, database-agnostic API.

Runtime agnostic

Works with tokio, async-std, and actix. Choose your runtime without being locked in.

Connection pooling

Built-in connection pool via sqlx::Pool. Rows are streamed asynchronously and decoded on demand.

TLS support

Transport Layer Security where supported (PostgreSQL, MySQL, MariaDB), with both native-tls and rustls backends.

Nested transactions

Supports save points and nested transactions across all supported databases.

SQLx is not an ORM

SQLx supports compile-time checked queries, but it does not provide a Rust API or DSL for building queries. Instead, it provides macros that take regular SQL as input and verify it against your actual database. The way this works is that SQLx connects to your development database at compile time to have the database itself verify your SQL. This has some important implications:
  • Any syntax that your development database accepts can be used, including database-specific extensions and custom functions.
  • The extent of SQL verification depends on how much information the database exposes when preparing a statement.
  • You write real SQL — the same queries you would write in a database client — and get Rust type safety on top.
If you are looking for an ORM, the SQLx ecosystem wiki lists async-compatible options like SeaORM and ormx.

Supported databases

DatabaseFeature flagNotes
PostgreSQLpostgresPure Rust driver, full async, TLS supported
MySQLmysqlPure Rust driver, full async, TLS supported
MariaDBmysqlShares driver with MySQL
SQLitesqliteWraps libsqlite3, bundled by default
MSSQL was supported prior to version 0.7 but has been removed pending a full rewrite of the driver. See the SQLx Pro initiative for updates.

Supported runtimes

SQLx is runtime agnostic. You select your runtime through feature flags when adding the dependency:
RuntimeFeature flag
Tokioruntime-tokio
async-stdruntime-async-std
async-global-executorruntime-async-global-executor
smolruntime-smol
Actix-web is fully compatible with Tokio and does not require a separate runtime feature.

Next steps

Get started with SQLx

Connect to a database and run your first compile-time verified query in under 10 minutes.

Installation and feature flags

Add SQLx to your Cargo.toml and choose the right runtime, TLS, and database features.

Build docs developers (and LLMs) love