explaingit

launchbadge/sqlx

16,992RustAudience · developerComplexity · 3/5Setup · moderate

TLDR

SQLx is a Rust library for running SQL queries against PostgreSQL, MySQL, MariaDB, and SQLite with the unique ability to verify your queries are actually correct at compile time, with full async support.

Mindmap

mindmap
  root((SQLx))
    What it does
      Rust SQL toolkit
      Compile-time query check
      Async database access
    Databases
      PostgreSQL
      MySQL and MariaDB
      SQLite
    Key features
      Connection pool
      Row streaming
      Nested transactions
      LISTEN and NOTIFY
    Tech
      Rust
      Tokio and async-std
      rustls and native-tls
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Build a Rust web API that reads and writes to PostgreSQL with queries verified correct at compile time.

USE CASE 2

Add an async connection pool to a Tokio-based Rust service with streaming query results.

USE CASE 3

Stream large result sets row-by-row from SQLite without loading everything into memory at once.

USE CASE 4

Receive real-time events from PostgreSQL using async LISTEN and NOTIFY in a Rust background service.

Tech stack

RustPostgreSQLMySQLSQLiteMariaDBtokio

Getting it running

Difficulty · moderate Time to first run · 30min

Compile-time checked queries require a running development database at build time and DATABASE_URL set in the environment.

License information is not mentioned in the repository description.

In plain English

SQLx is a Rust library for talking to SQL databases, the ones that store data in tables, like PostgreSQL, MySQL, MariaDB and SQLite. It is meant for Rust programmers who want to write actual SQL queries rather than going through a heavy abstraction that hides the database. The project calls itself the Rust SQL toolkit. Its standout feature is compile-time checked queries. You hand SQLx a SQL statement and, while your code is being compiled, it actually contacts your development database, verifies the query is valid, and confirms that the types of the results match what your Rust code expects. If the query is wrong or the schema has changed, the build fails before the program runs. This is optional, you can also issue queries the normal way without the check. SQLx is built to be asynchronous, meaning many database operations can be in flight at once without blocking. It works with the popular Rust async runtimes (async-std, tokio, actix) and TLS backends (native-tls, rustls). It ships with a built-in connection pool, streams rows as they arrive, caches prepared statements, supports nested transactions with save points, and offers PostgreSQL-specific features like asynchronous LISTEN and NOTIFY notifications. An Any driver lets you pick the database at runtime from the connection URL. The Postgres and MySQL/MariaDB drivers are pure Rust with no unsafe code, the SQLite driver wraps the libsqlite3 C library because SQLite is embedded. Reach for SQLx when building a Rust application that needs a real database, you want first-class async support, and you would rather write SQL directly, with the safety net of compile-time verification, than adopt a full ORM.

Copy-paste prompts

Prompt 1
Set up SQLx in a Tokio-based Rust app to connect to PostgreSQL, run a compile-time checked query to fetch users by email, and return results as JSON.
Prompt 2
Write a Rust function using SQLx that inserts a row into a SQLite database with a compile-time checked macro and handles errors cleanly.
Prompt 3
How do I configure a SQLx PostgreSQL connection pool in an Axum web server and share it across all request handlers?
Prompt 4
Set up SQLx database migrations using the sqlx CLI to create and evolve a PostgreSQL schema in my Rust project.
Prompt 5
Show me how to listen for PostgreSQL NOTIFY events from a Rust async task using SQLx PgListener.
Open on GitHub → Explain another repo

← launchbadge on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.