#postgresql #serde-json #sqlx #newtype #pg-row #sqlx-pgrow-serde

kurtbuilds_sqlx_serde

serde-compatible newtype wrapper for sqlx::postgres::PgRow

4 releases

0.3.3 Oct 7, 2024
0.3.2 Sep 10, 2024
0.3.1 Sep 2, 2024
0.3.0 Sep 2, 2024

#643 in Encoding

Download history 292/week @ 2024-09-02 153/week @ 2024-09-09 63/week @ 2024-09-16 46/week @ 2024-09-23 19/week @ 2024-09-30 237/week @ 2024-10-07 76/week @ 2024-10-14 17/week @ 2024-10-21 71/week @ 2024-10-28 46/week @ 2024-11-04 22/week @ 2024-11-11 14/week @ 2024-11-18 27/week @ 2024-12-02

65 downloads per month

MIT license

19KB
260 lines

sqlx-pgrow-serde

Check lib.rs for tests, which should give you a clear idea how to use the crate.

async fn main() {
    let row: PgRow = conn.fetch_one("select 3.3").await.unwrap();
    // option 1 - use function calls
    let headers: Vec<String> = read_headers(&row);
    let row: Vec<serde_json::Value> = read_row(&row);
    // option 2 - serializes as a header -> value map
    let row = SerMapPgRow::from(row);
    let row: serde_json::Value = serde_json::to_value(&row).unwrap();
    // option 3 - serializes as a serde_json::Array
    let row = SerVecPgRow::from(row);
    let row: serde_json::Value = serde_json::to_value(&row).unwrap();
}

Look at the SerMapPgRow and SerVecPgRow structs if you want to use #[serialize_with(...)] on your structs.

Dependencies

~15–32MB
~508K SLoC