Repolode
transact-rs

transact-rs/sqlx

Async, pure Rust SQL toolkit with compile-time checked queries written as plain SQL, supporting PostgreSQL, MySQL/MariaDB, and SQLite.

Stars
17,587
Forks
1,750
Open issues
785
Last commit
4 hours ago

What is it?

SQLx is a Rust crate for talking to SQL databases asynchronously. Instead of a query builder or DSL, you write regular SQL strings, and the query macros ask your development database to verify them at compile time, so syntax and type errors surface before the program runs. It is explicitly not an ORM; mapping rows to structs is done with derive macros or `query_as`.

The crate provides a connection pool, row streaming, prepared-statement caching, transactions with save points, and LISTEN/NOTIFY support on PostgreSQL. The Postgres and MySQL/MariaDB drivers are implemented in pure Rust without unsafe code, while the SQLite driver wraps the C SQLite library. It works with the tokio and async-std runtimes and with native-tls or rustls for TLS.

An `Any` driver lets an application pick the database backend at runtime from the connection URL scheme.

Key features

  • 01Compile-time checked SQL queries via query macros, without a query-builder DSL.
  • 02Async API with a built-in connection pool and row streaming.
  • 03Supports PostgreSQL, MySQL/MariaDB, and SQLite.
  • 04Automatic prepared-statement caching per connection.
  • 05Nested transactions with save points.
  • 06LISTEN/NOTIFY support on PostgreSQL.
  • 07Works with tokio or async-std and native-tls or rustls.

Use cases

  • Building async Rust web services backed by PostgreSQL or MySQL.
  • Writing hand-tuned SQL while still catching schema mismatches at build time.
  • Embedding SQLite in a Rust application with async access.
  • Creating database-agnostic tools that choose the driver from a URL at runtime.

Quick start

  1. 1

    Add sqlx to Cargo.toml with a runtime feature (runtime-tokio or runtime-async-std) and optionally a TLS feature

  2. 2

    Enable the database driver you need (postgres, mysql, or sqlite) in the sqlx features list

  3. 3

    Create a connection pool with PgPoolOptions (or the matching pool type) and run a query as shown in the Quickstart

Things to know

  • The SQLite driver relies on the C libsqlite3 library and uses unsafe code, so it is not pure Rust.
  • Compile-time checked query macros need a development database available at build time unless offline mode is used.
  • The MSSQL driver was removed after version 0.7 and is not currently supported.

Topics

FAQ

What is sqlx?
Async, pure Rust SQL toolkit with compile-time checked queries written as plain SQL, supporting PostgreSQL, MySQL/MariaDB, and SQLite. SQLx is a Rust crate for talking to SQL databases asynchronously. Instead of a query builder or DSL, you write regular SQL strings, and the query macros ask your development database to verify them at compile time, so syntax and type errors surface before the program runs. It is explicitly not an ORM; mapping rows to structs is done with derive macros or `query_as`.
Is sqlx free to use? What license does it have?
sqlx is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
Is sqlx still maintained?
Actively maintained. The last commit to sqlx was on Oct 21, 2026.
What can I use sqlx for?
Building async Rust web services backed by PostgreSQL or MySQL. Writing hand-tuned SQL while still catching schema mismatches at build time. Embedding SQLite in a Rust application with async access. Creating database-agnostic tools that choose the driver from a URL at runtime.
How do I install sqlx?
Add sqlx to Cargo.toml with a runtime feature (runtime-tokio or runtime-async-std) and optionally a TLS feature Enable the database driver you need (postgres, mysql, or sqlite) in the sqlx features list Create a connection pool with PgPoolOptions (or the matching pool type) and run a query as shown in the Quickstart
Where can I get sqlx?
The source code and installation instructions are on GitHub: https://github.com/transact-rs/sqlx

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects