Replies: 1 comment
-
For what it's worth, I think this problem also applies to the Lines 314 to 330 in 419877d The sqlx/sqlx-macros-core/src/query/input.rs Lines 53 to 59 in 419877d I would be interested in a way to generate these inputs, which is also sorta discussed within the
If I'm trying to have my "query be generated by a macro" -- as that documentation around the I'm worried that e.g. if I wrote my own proc macro to emit a SQL literal, I would need to be cautious to not run afoul of rust-lang/reference#692 |
Beta Was this translation helpful? Give feedback.
-
I'm interested in using sqlx from a context where a
build.rs
file can help with generating SQL, that sqlx can help validate. I have a codebase that includes a fair amount of boilerplate, so writing all SQL by hand is onerous, and I'd like to use Rust code to generate that SQL. However, sqlx's ability to validate query input/output seems quite handy, and I'd also like to make use of that.Here's the architecture I was considering:
build.rs
. This file ends up withinconcat!(std::env!("OUT_DIR"), "/my_query.sql")
.However, in practice, I've noticed that even though "code generation" of the SQL happens before the
sqlx::query_file
call, thesqlx
macros really want to operate on a string literal path:query_file!
:sqlx/src/macros/mod.rs
Lines 387 to 396 in 419877d
Calls
expand_query
:sqlx/sqlx-macros/src/lib.rs
Lines 7 to 23 in 419877d
Parses the input
source_file
as a literal:sqlx/sqlx-macros-core/src/query/input.rs
Lines 60 to 62 in 419877d
Is there any consideration for parsing these
source_file
paths as something other than a literal? If the sqlx proc macros could determine this file path slightly more dynamically, it seems possible to make that handoff from "build script" to "sqlx".Curious if others have hit this problem too, or if there are other approaches folks have taken to a similar problem.
Beta Was this translation helpful? Give feedback.
All reactions