axum-impl-database

Create sqlx PgPool router state and safe query handlers for Axum services.

Updated May 20, 2026
One-click install
npx skills add https://github.com/Impertio-Studio/Axum-Claude-Skill-Package --skill axum-impl-database
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: axum-impl-database
Source: https://github.com/Impertio-Studio/Axum-Claude-Skill-Package/tree/main/skills/source/axum-impl/axum-impl-database
Command: npx skills add https://github.com/Impertio-Studio/Axum-Claude-Skill-Package --skill axum-impl-database

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Prevents common, high-impact database integration failures in Axum by ensuring a sqlx connection pool is created once and reused correctly across handlers.

Core Features & Use Cases

  • Correct sqlx pool lifecycle: build the PgPool once in startup and share it via router state rather than creating per-request pools.
  • Safe pool usage in handlers: use State<PgPool> (no Arc or Mutex) and return Result instead of calling unwrap on query results.
  • Reliability under load: always set acquire_timeout to avoid requests hanging forever when the pool is saturated.
  • Version-aware extractor support: migrate or implement the DatabaseConnection FromRequestParts extractor for Axum 0.7 vs 0.8.
  • Query patterns and transactions: choose compile-time checked query macros vs runtime query functions and run atomic transactions with drop-rollback safety.

Quick Start

Use the axum-impl-database skill to design your sqlx PgPool setup, handler query code, and the correct Axum 0.7/0.8 DatabaseConnection extractor for your service.

Frequently Asked Questions about axum-impl-database

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I share a sqlx connection pool safely across Axum handlers?

To share a sqlx connection pool safely in Axum, build the PgPool once at startup using PgPoolOptions and pass it via router State<PgPool>, avoiding Arc or Mutex wrapping for direct, safe handler access.

What's the best way to handle sqlx transactions in Axum to prevent partial writes?

The best way to handle sqlx transactions in Axum is using the transaction method with drop-rollback safety, ensuring atomic operations that automatically roll back if a query fails before commit.

Do I need to set acquire_timeout for sqlx PgPoolOptions in an Axum service?

Yes, you need to set acquire_timeout in PgPoolOptions to ensure Axum service reliability under load, preventing requests from hanging indefinitely when the sqlx connection pool becomes saturated.

Does the DatabaseConnection FromRequestParts extractor work differently in Axum 0.7 and 0.8?

Yes, the DatabaseConnection FromRequestParts extractor requires version-aware migration or implementation adjustments when moving between Axum 0.7 and 0.8 to maintain correct request extraction behavior.

Why should I use Result propagation instead of unwrap on sqlx queries in Axum handlers?

You should use Result propagation instead of unwrap on sqlx queries in Axum handlers to enforce safe error handling, preventing application panics and allowing proper error responses when query execution fails.

When do I use sqlx query macros versus runtime query functions in Axum?

Use sqlx compile-time checked query macros when you want static SQL validation during builds, and use runtime query functions like fetch_one or fetch_all in Axum when you need dynamic SQL query construction.