About this project
SQLx is an asynchronous Rust library for executing SQL from application code. It is explicitly not an ORM and does not provide a Rust query-builder DSL; developers write ordinary SQL strings. The optional `query!` and `query_as!` macros connect to a development database at build time to validate query syntax, bind parameters, and result shapes. A `DATABASE_URL` with a compatible schema is required for this verification, while the `sqlx` CLI can cache query metadata for offline builds.
Supported databases include PostgreSQL, MySQL, MariaDB, and SQLite. MSSQL support existed before version 0.7 but was removed pending a driver rewrite. The PostgreSQL and MySQL/MariaDB drivers are written in pure Rust; SQLite uses the libsqlite3 C library, and unsafe code is confined to the SQLite integration when that feature is enabled.
The toolkit includes built-in connection pooling, single-connection APIs, asynchronous row streaming, `fetch`, `fetch_one`, `fetch_optional`, and `fetch_all` helpers, parameter binding, automatic prepared-statement caching, unprepared and batch query execution, TLS support for network databases, PostgreSQL `LISTEN`/`NOTIFY`, nested transactions with savepoints, and an `Any` driver that can select a database backend at runtime from the connection URL.
SQLx works with Tokio, async-std, and Actix-compatible runtimes, and offers native-tls or rustls backend options through Cargo features. Additional features provide derive macros such as `FromRow`, migration management and embedded migrations, and integrations for UUID, date/time crates, JSON, decimal types, IP network types, and byte strings.
It is cross-platform wherever Rust is supported and is dual-licensed under Apache License 2.0 and MIT.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.