Open musjj opened 1 month ago
I think formatting itself is out of scope for GritQL, but this is a scenario we could likely support in our upcoming workflow engine + SDK. The syntax would look something like this:
grit.rust`sqlx::query("$query")`.each((binding, context) => {
const query = context.findVar("$query");
const formatted = $`sqlformat < ${query.text()}`.text();
query.replace(formatted);
}).run();
One of my pet peeves is formatting languages embedded in strings.
For example, with
sqlx
in rust:Or
jq
in the shell:There's currently no generalized tools for formatting this kind of strings, so you usually end up doing it manually.
But I've been thinking that
gritql
seems like the perfect tool for dealing with this problem. You could write patterns to extract these strings, define an external command to pipe the string to, then use output of the command for your needs.It could, for example, look like this: