sqlx offline mode hashes the query SQL text in order to build keys for sqlx-data.json. I'm using raw multi-line string literals to help with readability:
sqlx::query!(r#"
SELECT …
"#, foo);
As a result, even a simple cargo run fmt can change the indent of the closing tag and add trailing whitespace, resulting in a different hash, resulting in a cache miss and having to rebuild the file (prepare).
I would suggest applying a .strip() on the query string before hashing. This would not introduce any non-determinism: no SQL dialect will have a behavioral difference caused by leading or trailing whitespace, aka. SELECT 1 and \n\n SELECT 1\n\t \t\n are identical.
Note: this won't solve the issue of eg. indenting the whole block of SQL, but I don't want to suggest dealing with this, because that'd risk affecting the SQL body. To be safe this would require being able to parse SQL, which is a non-goal of sqlx.
sqlx offline mode hashes the query SQL text in order to build keys for
sqlx-data.json
. I'm using raw multi-line string literals to help with readability:As a result, even a simple
cargo run fmt
can change the indent of the closing tag and add trailing whitespace, resulting in a different hash, resulting in a cache miss and having to rebuild the file (prepare
).I would suggest applying a
.strip()
on the query string before hashing. This would not introduce any non-determinism: no SQL dialect will have a behavioral difference caused by leading or trailing whitespace, aka.SELECT 1
and\n\n SELECT 1\n\t \t\n
are identical.Note: this won't solve the issue of eg. indenting the whole block of SQL, but I don't want to suggest dealing with this, because that'd risk affecting the SQL body. To be safe this would require being able to parse SQL, which is a non-goal of sqlx.