wait... proc macros are run at compile time, right? so db queries at compile time?!
but.. but.. why?
wait... proc macros are run at compile time, right? so db queries at compile time?!
but.. but.. why?
Compile time verification that you haven't made a typo in your SQL, and that if you have updated your db schema that your code also reflects these changes.
Turning runtime errors in to compile time errors is one of Rust's superpowers.
The real issue is that in performance benchmarks Diesel beats SQLx, at least last I checked. I'm hopeful the rewrite/upgrades to SQLx that are coming shorten this gap.
This is just ensuring it is valid at compile time.
On deploy you just run your migrations first. Obviously you have to do some planning.
It's a major productivity boost honestly, after building a semi large app with it.
And yes, it does actually run the queries. It populates dummy data and runs it in a transaction from what I can tell.
It's honestly very nice. The code, my migrations, my DB browser, all in one window in my IDE.
And the query is validated by running it, at compile time, by inserting mock inputs inside a transaction. It works really well.
Even if you disagree that the DB must be the source of authority and it can differ, the development boon of the process is worth the 5% chance there is some issue later, which can probably be easily resolved.
your infrastructure is not that .tf definition, it's whatever is currently deployed to ec2
in the same way, your schema is not that .sql file, it's whatever the database says it is :)
You can keep pushing this argument but it doesn't mean anything in any practical sense.
(You can also check in the results of the database queries, so you only need the db in the build stack when you touch db-related code).
Yes, but it can also run in 'offline' mode where it builds against saved metadata [0]
0: https://github.com/launchbadge/sqlx/blob/main/sqlx-cli/READM...
The idea is kinda neat but....