How transact-rs/sqlx works
SQLx is an asynchronous Rust SQL toolkit. In the main workflow, an application builds a query, binds Rust values, executes it through an executor and database driver, then consumes decoded rows. The repository also provides compile-time query checking and derives, connection pooling, runtime-selectable Any, migrations and PostgreSQL notifications. Driver internals and some CLI relationships are represented at subsystem level where the supplied excerpts do not establish finer-grained calls; those links are omitted or marked unverified.
Main entry points: executor.rs Executor API · query.rs Query builders · lib.rs SQLx CLI · query_as.rs Typed queries
Components 21
Query API
- Query builders
sqlx-core/src/query.rs - Typed queries
sqlx-core/src/query_as.rs - Dynamic builder
sqlx-core/src/query_builder.rs
Execution Core
- Executor API
sqlx-core/src/executor.rs - Connection pool
sqlx-core/src/pool/mod.rs - Transactions
sqlx-core/src/transaction.rs - Value conversion
sqlx-core/src/encode.rs - Row mapping
sqlx-core/src/from_row.rs
Database Drivers
- PostgreSQL driver
sqlx-postgres/src/connection/executor.rs - MySQL driver
sqlx-mysql/src/connection/executor.rs - SQLite driver
sqlx-sqlite/src/connection/executor.rs - Runtime Any driver
sqlx-core/src/any/driver.rs - PG notifications
sqlx-postgres/src/listener.rs
Compile-Time Support
- Query macros
sqlx-macros-core/src/query/mod.rs - Type derives
sqlx-macros-core/src/derives/mod.rs
CLI Operations
- SQLx CLI
sqlx-cli/src/lib.rs - Migration commands
sqlx-cli/src/migrate.rs - Database commands
sqlx-cli/src/database.rs - Offline preparation
sqlx-cli/src/prepare.rs
Other components
- Rust application
- Database server
Connections 23
- Rust application → Query builders: builds query
- Rust application → Typed queries: maps results
- Query builders → Executor API: executes through
sqlx-core/src/query.rs - Typed queries → Executor API: fetches through
sqlx-core/src/query_as.rs - Dynamic builder → Query builders: builds query
sqlx-core/src/query_builder.rs - Query builders → Value conversion: encodes bindings
sqlx-core/src/query.rs - Typed queries → Row mapping: maps rows
sqlx-core/src/query_as.rs - Executor API → Connection pool: uses pooled connections
sqlx-core/src/executor.rs - Executor API → PostgreSQL driver: dispatches execution
- Executor API → MySQL driver: dispatches execution
- Executor API → SQLite driver: dispatches execution
- Executor API → Runtime Any driver: supports runtime driver
- PostgreSQL driver → Database server: speaks protocol
- MySQL driver → Database server: speaks protocol
- SQLite driver → Database server: queries embedded store
- Rust application → Query macros: checks queries
- Rust application → Type derives: derives mappings
- SQLx CLI → Migration commands: runs migrations
sqlx-cli/src/lib.rs - SQLx CLI → Database commands: runs database commands
sqlx-cli/src/lib.rs - SQLx CLI → Offline preparation: prepares queries
sqlx-cli/src/lib.rs - Rust application → Connection pool: acquires connections
- Rust application → Transactions: starts transactions
- Rust application → PG notifications: listens for events