sqlx

Verify SQL queries at compile time in Rust applications using sqlx.

Updated Jun 15, 2025
One-click install
npx skills add https://github.com/patrickhaahr/dotfiles --skill sqlx
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sqlx
Source: https://github.com/patrickhaahr/dotfiles/tree/main/opencode/.config/opencode/skills/sqlx
Command: npx skills add https://github.com/patrickhaahr/dotfiles --skill sqlx

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

sqlx provides a pragmatic approach to executing SQL in Rust without an ORM, offering compile-time verification of queries and safe async execution for database-backed applications. It ensures you can write raw SQL while catching errors at compile time.

Core Features & Use Cases

  • Compile-time verification of queries with query! and query_as!.
  • Async, non-blocking execution suitable for tokio, async-std, or actix.
  • Database-agnostic support for PostgreSQL, MySQL, MariaDB, and SQLite.
  • Not an ORM; focuses on safe, direct SQL execution with tooling.
  • Use Case: Build high-performance microservices that require precise SQL control and minimal boilerplate.

Quick Start

Create a Rust project, add sqlx to Cargo.toml with the appropriate features (runtime and database), then establish a connection pool and run a compile-time checked query.

Frequently Asked Questions about sqlx

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

FAQPage Schema
How do I verify SQL queries at compile time in Rust without using an ORM?

Compile-time SQL verification in Rust is achieved using sqlx macros like query! and query_as!, which check raw SQL against your database schema during the build process. This catches query errors early without requiring an ORM.

Can I execute SQL queries asynchronously in Rust with PostgreSQL and MySQL?

Yes, you can execute SQL queries asynchronously in Rust with PostgreSQL, MySQL, MariaDB, and SQLite. The sqlx crate provides non-blocking database execution that integrates smoothly with async runtimes like tokio, async-std, or actix.

What is the best way to catch database query errors before running a Rust application?

The best way to catch database query errors before running a Rust application is compile-time SQL verification. By using sqlx macros, the Rust compiler validates your SQL syntax and types against the live database, preventing runtime failures.

How do I set up a Rust project to use compile-time checked SQL queries?

To set up compile-time checked SQL queries, create a Rust project, add sqlx to your Cargo.toml with the appropriate runtime and database features, establish a database connection pool, and use the query! macro for your SQL statements.

Does compile-time SQL verification work across multiple databases in Rust?

Compile-time SQL verification works across multiple databases in Rust, offering database-agnostic support for PostgreSQL, MySQL, MariaDB, and SQLite. This allows you to build high-performance microservices with precise cross-database SQL control.

Why use compile-time SQL macros instead of an ORM for Rust microservices?

Compile-time SQL macros are used instead of an ORM for Rust microservices to provide safe, direct SQL execution with minimal boilerplate. This approach ensures high performance and precise SQL control while still catching syntax errors during compilation.