sql-forge adds compile-time checked dynamic SQL to sqlx
sql-forge tries to make dynamic SQL feel native in Rust without giving up sqlx’s compile-time checks. It wraps branching queries in a proc-macro DSL instead of string soup.
Dynamic SQL is where a lot of Rust back ends stop feeling crisp and start feeling brittle, and sql-forge was built to close that gap without asking teams to leave sqlx behind. The project was announced in the Rust Programming Language Forum’s announcements category on June 2, 2026, with lucasbasquerotto pitching it as a compile-time validated superset for sqlx that can handle branching queries more cleanly.
The pitch is practical, not theoretical. sql-forge is a proc-macro that uses sqlx under the hood, supports MySQL, PostgreSQL, and SQLite, and combines compile-time SQL validation with a runtime QueryBuilder for the parts of a statement that really do need to change. Its README says it supports named parameters and optional sections that are swapped in at runtime, which is exactly the sort of pattern that usually sends teams into string concatenation, ad hoc state machines, or a pile of if statements around query fragments.

That matters because sqlx itself has always drawn a bright line around what it can inspect. The query! macro requires a string literal, or a concatenation of string literals, so the SQL can be introspected at compile time. Once the query becomes dynamic, or comes from another macro, that guarantee is gone. sqlx’s QueryBuilder is explicitly a runtime construction API, which is useful, but it shifts more responsibility back onto the developer. Even sqlx’s broader docs frame the crate as an async, pure-Rust SQL toolkit with compile-time checked queries and no DSL, which leaves dynamic branching outside the easy path.
The frustration is not new. In a 2024 Rust forum thread, weiznich said SQLx is not really designed for dynamic queries and that once you go that route, you lose the compile-time advantages and fall back to lower-level string-based query building. Another crate in the same space, sqlx_conditional_queries, takes a different tack by generating multiple query_as! invocations for each conditional branch, but it warns that the number of variants can grow as a Cartesian product of the conditions. That is the real tradeoff sql-forge is trying to attack: keeping sqlx’s safety model while making dynamic SQL less of a maintenance tax.
If sql-forge matures into something teams can standardize on, the appeal is obvious. It does not try to replace sqlx’s best case; it tries to keep compile-time checking alive in the exact place Rust database code usually falls apart.
This article was produced by Prism’s automated news system from verified source data, official records, and press releases, then run through automated quality and moderation checks before publishing. The system is built and supervised by the people who set the standards it runs under. Read our full AI policy.
Did this article answer your question?


