Announcing qusql: Compile-time SQL Checking for Rust, No Database Required

77 points antialize 11 comments

If you've used sqlx's query! macro, you know the drill: run cargo sqlx prepare, commit sqlx-data.json, keep a database running in CI. It works, but it's not frictionless.

qusql-sqlx-type is an (almost) drop-in replacement for sqlx::query! that:

  • Reads your schema from a plain SQL file next to your Cargo.toml
  • Type-checks all queries at cargo check time with no database connection.
  • Requires no side-channel file, no prepare step, and enables fully offline CI

When you typo a column name, you get this at compile time:

error:    ╭─[ query:1:8 ]
          │
        1 │ SELECT titl, body FROM notes WHERE id = $1
          │        ──┬─
          │          ╰─── Unknown identifier
          │
          │ Help: did you mean `title`?
       ───╯
 --> src/main.rs:7:24

This currently works for MySQL and PostgreSQL. Read more in this post.

For MySQL/MariaDB there is qusql-mysql-type, which wraps qusql-mysql, a cancellation-safe async driver that benchmarks roughly 1.5–2x faster than sqlx on MySQL workloads. More details here.

We've been using this in production at Scalgo for years, and now feel it's ready to share with a broader audience.

Feedback, questions, and contributions are very welcome!