Replies: 1 comment 2 replies
-
I think a lot of people tend to reach for |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
👋 Hi folks,
While I've been programming for a looong time I'm relatively new to Rust and very new to sqlx.
In larger apps I've found it's valuable to have queries defined in dedicated
.sql
files separate from the code so we can track all the unique queries that get executed against our database. In my current experimental app, I've got auser_queries.sql
file defined, with each query named like this:Then in my
build.rs
file I have a function that parses this sql file to produce a Rust file like this:Finally, in my actual model code I
include!
that generated file and have all the query constants available to me with autocomplete within that module:This seems pretty simple but I thought I'd check if there was any interest in me putting a pull request together and polishing it up. No point in everyone writing their own parser/generator. Would this be of value to sqlx? Are others doing something similar, or did I miss a common utility for this already?
Thanks everyone!
Beta Was this translation helpful? Give feedback.
All reactions