sqlx is a free, open source databases project written in Rust and released under Apache-2.0. It has 17,480 GitHub stars, 1,699 forks and 754 open issues, and was last pushed 3 days ago. On this registry it ranks #34 of 81 tracked projects in Databases, with 5 head-to-head comparisons available.

What is sqlx?

SQLx is an async, pure Rust SQL crate that provides compile-time checked queries without a domain-specific language, aimed at Rust developers building applications against PostgreSQL, MySQL, MariaDB, or SQLite.

What it is

SQLx is a SQL toolkit distributed as a Rust crate, licensed Apache-2.0. It supplies database drivers for PostgreSQL, MySQL, MariaDB, and SQLite, built from the ground up on async/await for concurrency. It is runtime agnostic, working across async-std, tokio, and actix, and TLS-backend agnostic across native-tls and rustls. The README states plainly that SQLx is not an ORM, and the compile-time checking is optional rather than mandatory.

The concrete problem it solves is the query layer. Applications that adopt an ORM take on a model-mapping layer and a query DSL they may not want; applications that hand-roll a driver wrapper lose connection pooling, statement caching, and any compile-time verification of SQL. SQLx sits between those options: it checks queries at compile time while leaving the SQL written as SQL, and it ships the pooling, streaming, and transaction machinery that would otherwise be written by hand. The Postgres and MySQL/MariaDB drivers are pure Rust with zero unsafe code, guarded by #![forbid(unsafe_code)] unless the sqlite feature is enabled.

Key capabilities

  • Compile-time checked queries without a DSL, in an async, pure Rust crate.
  • Database agnostic across PostgreSQL, MySQL, MariaDB, and SQLite, plus an Any driver and AnyPool that connect to the driver indicated by the URL scheme.
  • Built-in connection pooling through sqlx::Pool.
  • Row streaming: data is read asynchronously from the database and decoded on demand.
  • Automatic statement preparation and caching per connection when using the high-level query API, sqlx::query; simple unprepared execution with batch execution, returning results from all statements into the same Row types.
  • Nested transactions with save point support, asynchronous LISTEN and NOTIFY notifications for PostgreSQL, and TLS where supported on MySQL, MariaDB, and PostgreSQL.
  • Cross-platform compilation anywhere Rust is supported, with configurable runtime and TLS backends.

Who uses it and how

  • Rust application teams running on tokio, async-std, or actix that want SQL access without adopting an ORM model layer.
  • Services that must compile and run on every platform Rust supports.
  • Applications that switch database driver at runtime, using AnyPool to select the driver from the connection URL scheme.
  • PostgreSQL applications that need asynchronous notifications delivered through LISTEN and NOTIFY.
  • Deployments requiring TLS to MySQL, MariaDB, or PostgreSQL, which choose between the native-tls and rustls backends.

Getting started

Add the crate to Cargo.toml and select one runtime feature plus one TLS feature, for example sqlx = { version = "0.9", features = ["runtime-tokio", "tls-native-tls"] }. Alternatives include runtime-async-std, tls-rustls-ring-webpki, tls-rustls-ring-native-roots, and tls-rustls-aws-lc-rs.

How it compares

The facts name no comparable tools and no paid products this project replaces, so SQLx stands alone in this registry. The only positional claim the README makes is negative: it is explicitly not an ORM, and compile-time checked queries can be used or skipped at the developer's discretion.

When to use it — and when not to

A self-hoster must still operate the database itself, since SQLx is a crate rather than a service, and the SQLite path pulls in the libsqlite3 C library through libsqlite3-sys, which requires unsafe code and forfeits the crate's pure-Rust guarantee for that driver. Teams needing MSSQL should not pick it: that driver was supported before version 0.7 and has been removed pending a rewrite under the SQLx Pro initiative. The project carries 754 open issues, so expect an active but large backlog.

project readme (upstream, from github) — read inline

SQLx

🧰 The Rust SQL Toolkit
actions status Crates.io version chat docs.rs docs Download

Install | Usage | Docs | Ecosystem | Discord


Built with ❤️ by The LaunchBadge team


Have a question? Be sure to check the FAQ first!

SQLx is an async, pure Rust SQL crate featuring compile-time checked queries without a DSL.

  • Truly Asynchronous. Built from the ground-up using async/await for maximum concurrency.

  • Compile-time checked queries (if you want). See SQLx is not an ORM.

  • Database Agnostic. Support for PostgreSQL, MySQL, MariaDB, SQLite.

    • MSSQL was supported prior to version 0.7, but has been removed pending a full rewrite of the driver as part of our SQLx Pro initiative.
  • Pure Rust. The Postgres and MySQL/MariaDB drivers are written in pure Rust using zero unsafe†† code.

  • Runtime Agnostic. Works on different runtimes (async-std / tokio / actix) and TLS backends (native-tls, rustls).

† The SQLite driver uses the libsqlite3 C library as SQLite is an embedded database (the only way we could be pure Rust for SQLite is by porting all of SQLite to Rust).

†† SQLx uses #![forbid(unsafe_code)] unless the sqlite feature is enabled. The SQLite driver directly invokes the SQLite3 API via libsqlite3-sys, which requires unsafe.


  • Cross-platform. Being native Rust, SQLx will compile anywhere Rust is supported.

  • Built-in connection pooling with sqlx::Pool.

  • Row streaming. Data is read asynchronously from the database and decoded on demand.

  • Automatic statement preparation and caching. When using the high-level query API (sqlx::query), statements are prepared and cached per connection.

  • Simple (unprepared) query execution including fetching results into the same Row types used by the high-level API. Supports batch execution and returns results from all statements.

  • Transport Layer Security (TLS) where supported (MySQL, MariaDB and PostgreSQL).

  • Asynchronous notifications using LISTEN and NOTIFY for PostgreSQL.

  • Nested transactions with support for save points.

  • Any database driver for changing the database driver at runtime. An AnyPool connects to the driver indicated by the URL scheme.

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.

# Cargo.toml
[dependencies]
# PICK ONE OF THE FOLLOWING:

# tokio (no TLS)
sqlx = { version = "0.9", features = [ "runtime-tokio" ] }
# tokio + native-tls
sqlx = { version = "0.9", features = [ "runtime-tokio", "tls-native-tls" ] }
# tokio + rustls with ring and WebPKI CA certificates
sqlx = { version = "0.9", features = [ "runtime-tokio", "tls-rustls-ring-webpki" ] }
# tokio + rustls with ring and platform's native CA certificates
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

For backward-compatibility reasons, the runtime and TLS features can either be chosen together as a single feature, 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-std: Use the async-std 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.
  • tls-native-tls: Use the native-tls TLS backend (OpenSSL on *nix, SChannel on Windows, Secure Transport on macOS).

  • tls-rustls: Use the rustls TLS backend (cross-platform backend, only supports TLS 1.2 and 1.3).

  • tls-rustls-aws-lc-rs: Use the rustls TLS backend with aws-lc-rs.

  • postgres: Add support for the Postgres database server.

  • mysql: Add support for the MySQL/MariaDB database server.

  • Note: RSA auth without TLS requires mysql-rsa (not enabled by mysql).

  • mysql-rsa: Enable RSA password encryption for caching_sha2_password/sha256_password when TLS is off. Only enable it if you must connect without TLS to servers that require RSA auth. Prefer using TLS.

  • mssql: Add support for the MSSQL database server.

  • sqlite: Add support for the self-contained SQLite database engine with SQLite bundled and statically-linked.

  • sqlite-unbundled: The same as above (sqlite), but link SQLite from the system instead of the bundled version.

    • Allows updating SQLite independently of SQLx or using forked versions.
    • You must have SQLite installed on the system or provide a path to the library at build time. See the rusqlite README for details.
    • May result in link errors if the SQLite version is too old. Version 3.20.0 or newer is recommended.
    • Can increase build time due to the use of bindgen.
  • sqlite-preupdate-hook: enables SQLite's preupdate hook API.

    • Exposed as a separate feature because it's generally not enabled by default.
    • Using this feature with sqlite-unbundled may cause linker failures if the system SQLite version does not support it.
  • any: Add support for the Any database driver, which can proxy to a database driver at runtime.

  • derive: Add support for the derive family macros, those are FromRow, Type, Encode, Decode.

  • macros: Add support for the query*! macros, which allows compile-time checked queries.

  • migrate: Add support for the migration management and migrate! macro, which allow compile-time embedded migrations.

  • uuid: Add support for UUID.

  • chrono: Add support for date and time types from chrono.

  • time: Add support for date and time types from time crate (alternative to chrono, which is preferred by query! macro, if both enabled)

readme truncated — read the full docs on github

Frequently asked questions

Is sqlx free to use?

sqlx is open source under the Apache-2.0 licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does sqlx do?

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite.

What is sqlx written in?

sqlx is primarily written in Rust. Its source is publicly available at https://github.com/transact-rs/sqlx, and it has 17,480 GitHub stars.