sqlx
sqlx copied to clipboard
Document usage of the purpose of aliases for commands like `COUNT` in sqlx::query!
The issue
When using a function such as COUNT it is useful to add an alias in order to access it as a field on the anonymous struct returned by query!. However this may be hard to figure out for beginners. I believe that hinting it away in the documentation would help out.
Example
I personally first encountered the issue with a query like this one:
query_scalar!(
r#"SELECT COUNT(sentence) as "count!" FROM slaps WHERE guild=$1 AND offender=$2"#,
guild,
offender,
)
.fetch_one(conn)
.await?)
Hey thanks for posting this question. I couldn't figure out how to get the count as an integer.