sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

Document usage of the purpose of aliases for commands like `COUNT` in sqlx::query!

Open s0lst1ce opened this issue 4 years ago • 1 comments

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?)

s0lst1ce avatar Aug 05 '21 15:08 s0lst1ce

Hey thanks for posting this question. I couldn't figure out how to get the count as an integer.

mike-lloyd03 avatar Aug 23 '22 06:08 mike-lloyd03