transact-rs /sqlx
🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite.
★ 17,669⑂ 1,794👁 63⑃ 1,713● 2,209▤ 0
+0
Daily
17,669
stars
1,794
forks
63
watchers
1,713
prs
2,209
issues
0
releases
README
SQLx
🧰 The Rust SQL Toolkit
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.
[postgresql]: http://postgresql.org/
[sqlite]: https://sqlite.org/
[mysql]: https://www.mysql.com/
[mariadb]: https://www.mariadb.org/
[mssql]: https://www.microsoft.com/en-us/sql-server
[SQLx Pro initiative]: https://github.com/launchbadge/sqlx/discussions/1616
---
- 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.
[async-std]: https://github.com/async-rs/async-std
[tokio]: https://github.com/tokio-rs/tokio
[actix]: https://github.com/actix/actix-net
[native-tls]: https:/Top issues
#294Support for INSERTing multiple records?43 comments · 2020-05-01#1004Postgres enums and query_as!42 comments · 2021-01-21#942[Proposal] [Next] Query Logging Improvements33 comments · 2020-12-29#514query_as! macros do not use FromRow33 comments · 2020-07-13#3487Support jiff as a date time lib backend29 comments · 2024-09-05#1014More useful examples29 comments · 2021-01-24#481Isolation level support27 comments · 2020-07-05#563Mysql failure while dropping a future in the middle of reading or writing to the stream.26 comments · 2020-07-26
Discussions
#4500Collecting metrics of a Pool2 comments · 2026-11-02#4499deleteme0 comments · 2026-11-02#4476Encoding custom types for Sqlite, incompatibility in 0.9.01 comments · 2026-10-23#4465Use migration files for compile time query checks, rather than live database0 comments · 2026-10-16#4459If I pause tokio's clock, acquiring a connection from the pool always times out. How can I best work around this?2 comments · 2026-10-14#4457Question about Nagle / TCP_NODELAY and 0.9.1?0 comments · 2026-10-13#4456I have a minor need to update migration checksums. Horrible idea?1 comments · 2026-10-12#4405Expected memory impact when using `Query::fetch`2 comments · 2026-09-08