Crates.io | kurtbuilds_sqlx_serde |
lib.rs | kurtbuilds_sqlx_serde |
version | 0.3.3 |
source | src |
created_at | 2024-09-02 18:22:05.419698 |
updated_at | 2024-10-07 17:18:43.790999 |
description | serde-compatible newtype wrapper for sqlx::postgres::PgRow |
homepage | |
repository | https://github.com/kurtbuilds/sqlx-pgrow-serde |
max_upload_size | |
id | 1360916 |
size | 70,176 |
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.