DEV.co
Open-Source Databases · transact-rs

sqlx

SQLx is an async Rust SQL toolkit that enables compile-time checked database queries without a DSL. It supports PostgreSQL, MySQL, MariaDB, and SQLite with pure Rust drivers (except SQLite, which wraps libsqlite3) and is runtime/TLS agnostic.

Source: GitHub — github.com/transact-rs/sqlx
17.3k
GitHub stars
1.6k
Forks
Rust
Primary language
Apache-2.0
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositorytransact-rs/sqlx
Ownertransact-rs
Primary languageRust
LicenseApache-2.0 — OSI-approved
Stars17.3k
Forks1.6k
Open issues749
Latest releaseUnknown
Last updated2026-07-07
Sourcehttps://github.com/transact-rs/sqlx

What sqlx is

A zero-unsafe async SQL client for Rust (forbid(unsafe_code) except sqlite feature) featuring compile-time query validation via macros, connection pooling, row streaming, statement caching, and support for multiple async runtimes (tokio, async-std, actix) and TLS backends (native-tls, rustls). MySQL/PostgreSQL drivers are pure Rust; SQLite uses libsqlite3-sys bindings.

Quickstart

Get the sqlx source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/transact-rs/sqlx.gitcd sqlx# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

High-concurrency backend services in Rust

Leverage compile-time query checking and native async/await to build low-latency, memory-safe database-driven services with minimal runtime overhead.

Cross-database applications

Use the Any driver to switch database backends at runtime (via connection string scheme), enabling schema-agnostic multi-tenant or environment-flexible deployments.

Microservices and API servers

Combine compile-time safety with flexible runtime selection (tokio/async-std), automatic connection pooling, and nested transactions for reliable data access layers.

Implementation considerations

  • Compile-time query checking requires the macros feature and a live database connection during compilation; CI/CD must provide database access or use offline mode.
  • Runtime and TLS backend must be selected explicitly via Cargo features; mismatched runtime (e.g., tokio queries in async-std) will cause panics.
  • Connection pooling (sqlx::Pool) is built-in but requires explicit configuration; tune pool size, timeout, and idle behavior for your workload.
  • SQLite with compile-time checks requires static linking or system SQLite 3.20.0+; bundled mode simplifies but increases binary size.
  • Transaction handling uses savepoints for nesting; ensure your application handles rollback semantics correctly, especially in error paths.

When to avoid it — and what to weigh

  • MSSQL is required — MSSQL support was removed after version 0.7 and is pending a full rewrite; production MSSQL users must stay on 0.6.x or migrate to alternatives.
  • ORM-like features are essential — SQLx is explicitly not an ORM; it lacks automatic relationship mapping, query builders, or schema generation. If you need those, consider Diesel or sqlc.
  • Zero compile-time overhead is required — Compile-time checked queries (query! macro) require database connectivity at compile time; if offline builds are mandatory, disable macros and use runtime-only mode.
  • Non-Rust environments — SQLx is Rust-only; no official language bindings or language-agnostic wrapper libraries are provided in the core project.

License & commercial use

Licensed under Apache License 2.0 (Apache-2.0), a permissive OSI-approved license.

Apache-2.0 is a permissive license that permits commercial use, modification, and distribution under clear terms (provide notice of changes, include license copy, state modifications). No license fee or contributor agreement required. Verify compliance with all transitive dependencies' licenses.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityModerate
DEV.co fitStrong
Assessment confidenceHigh
Security considerations

Postgres and MySQL/MariaDB drivers use #![forbid(unsafe_code)] (zero-unsafe except SQLite), reducing memory-safety risks. SQLite driver uses libsqlite3-sys with unsafe bindings; ensure system or bundled SQLite is kept current. Supports TLS (native-tls and rustls variants) for transport security. No details on SQL injection mitigation beyond parameterized queries (query! macro enforces static SQL, reducing injection surface). No independent security audit data provided; requires review of your threat model.

Alternatives to consider

Diesel

Mature Rust ORM with schema generation, relationship mapping, and query builder; better if you need abstraction beyond raw SQL, but less flexible for dynamic queries.

sqlc (or upstream sqlc-gen-go et al.)

SQL-first code generation for type safety across languages; simpler if polyglot stacks or offline code generation is preferred, but no async runtime integration.

SeaORM

Async-first Rust ORM with similar runtime flexibility; choose if you prioritize ORM convenience over SQLx's minimal-abstraction philosophy.

Software development agency

Build on sqlx with DEV.co software developers

SQLx brings compile-time safety and async-first performance to Rust backends. Let Devco help you architect a scalable, maintainable database integration for your microservices or API.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

sqlx FAQ

Can I use SQLx without compile-time query checking?
Yes. Omit the macros feature and use sqlx::query() and sqlx::query_raw() for runtime-only queries. Lose static validation but retain type-safe Row mapping and connection pooling.
Does SQLx work with async-std AND tokio in the same binary?
No. You must select a single runtime feature (runtime-tokio, runtime-async-std, etc.). Mixing runtimes will cause panics. Use the Any driver for runtime selection, not for switching async frameworks.
Is MSSQL supported?
Not in current versions. MSSQL support was removed after 0.7 and is undergoing a full rewrite. Stay on 0.6.x if MSSQL is required, or migrate to another client.
How does compile-time checking work offline (in CI without a database)?
Use SQLX_OFFLINE=true and pre-generated sqlx-data.json files. Compile-time validation is skipped; runtime errors surface instead. Not recommended for production.

Work with a software development agency

Adopting sqlx is usually one piece of a larger software development effort. As a software development agency, DEV.co provides software development services and web development expertise — pairing senior software developers and web developers with your team to design, build, and operate open-source databases software in production.

Ready to Build a Type-Safe Database Layer?

SQLx brings compile-time safety and async-first performance to Rust backends. Let Devco help you architect a scalable, maintainable database integration for your microservices or API.