axum-impl-database
Installation
SKILL.md
Axum Database Access with sqlx
Overview
An Axum service talks to a SQL database through a sqlx connection pool. The
pool is an expensive resource: every connection is a real TCP socket (usually
with TLS) plus a server-side session. The pool MUST be created exactly once at
startup and shared with every handler through router state.
sqlx exposes the pool as Pool<DB>, with the type aliases PgPool for
Postgres, MySqlPool for MySQL, and SqlitePool for SQLite. This skill uses
Postgres; the patterns apply uniformly to the other databases by substituting
the type.
Three rules dominate correct database code in Axum: