Back to list
ohaddahan

rust-sqlx

by ohaddahan

4🍴 1📅 Jan 21, 2026

SKILL.md


name: rust-sqlx description: | Rust SQLx patterns for PostgreSQL. Covers compile-time checked queries (sqlx::query!), runtime queries with FromRow, migrations with sqlx-cli, offline mode with sqlx prepare, and idiomatic Rust coding style for database access. Use when: writing Postgres queries in Rust, setting up database migrations, debugging sqlx compile errors, or optimizing database code structure. user-invocable: true allowed-tools: Read, Glob, Grep, Edit, Write, Bash(cargo:), Bash(sqlx:)

Rust SQLx Skill (PostgreSQL)

What this Skill is for

Use this Skill when:

  • Writing database queries in Rust with sqlx
  • Setting up or modifying PostgreSQL migrations
  • Debugging compile-time query errors
  • Structuring database access layers
  • Using sqlx prepare for offline/CI builds
  • Converting between compile-time and runtime queries

Stack decisions (opinionated)

  1. Prefer compile-time queries (query!, query_as!) when:

    • Query structure is known at compile time
    • You want maximum type safety
    • Working with fixed schemas
  2. Use runtime queries (query, query_as) when:

    • Building dynamic WHERE clauses
    • Table/column names come from configuration
    • Prototyping before committing to schema
  3. Always use connection pools (PgPool) in applications

    • Never pass raw connections around
    • Configure pool size based on workload
  4. Migrations via sqlx-cli

    • Reversible migrations by default
    • Keep migrations small and focused
    • Never modify deployed migrations

Operating procedure

1. Classify the task

  • New query (compile-time vs runtime)
  • Schema change (migration)
  • Connection/pool setup
  • CI/offline mode setup
  • Error handling patterns

2. Pick the right pattern

  • Compile-time: query!, query_as!, query_scalar!
  • Runtime: query, query_as with FromRow
  • Transactions: pool.begin() + tx.commit()
  • Batch operations: QueryBuilder for bulk inserts

3. Follow struct conventions

  • All fields public (per project rules)
  • Derive FromRow for database structs
  • Use dedicated input structs for 3+ parameters

4. Run verification

  • cargo sqlx prepare after query changes
  • cargo check to verify compile-time queries
  • Test with actual database connection

Progressive disclosure (read when needed)

Score

Total Score

50/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

Reviews

💬

Reviews coming soon