launchbadge / sqlx

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite.
Apache License 2.0
13.29k stars 1.26k forks source link

Document code of `sqlx::query_as` has bugs. #3557

Open xuehaonan27 opened 1 week ago

xuehaonan27 commented 1 week ago

Bug Description

In the document example code of sqlx::query_as, there exists several bugs that I encountered when testing. query_as.rs: 230 mismatched bracket. query_as.rs: 230 move TIMESTAMP to TIMESTAMPTZ to match type time::OffsetDateTime. query_as.rs: 241, 251, 260 move i64 to i32 to match postgres type INT4.

Minimal Reproduction

Just run current code piece in document of query_as: https://docs.rs/sqlx/latest/sqlx/fn.query_as.html#example-map-rows-using-tuples

Info

benbot commented 1 week ago

I believe the Json example using query_as is also incorrect. It looks like macro returns Option<Json<T>> instead of Json<T> and Json<T> doesn't implement From<Option<Json<T>>>

https://docs.rs/sqlx/latest/sqlx/types/struct.Json.html

xuehaonan27 commented 1 week ago

I believe the Json example using query_as is also incorrect. It looks like macro returns Option<Json<T>> instead of Json<T> and Json<T> doesn't implement From<Option<Json<T>>>

https://docs.rs/sqlx/latest/sqlx/types/struct.Json.html

I will check it as well! Thank you very much!