Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kurtbuilds/sqlx_serde
serde-compatible newtype wrapper for sqlx::postgres::{PgRow, PgValueRef}
https://github.com/kurtbuilds/sqlx_serde
Last synced: 25 days ago
JSON representation
serde-compatible newtype wrapper for sqlx::postgres::{PgRow, PgValueRef}
- Host: GitHub
- URL: https://github.com/kurtbuilds/sqlx_serde
- Owner: kurtbuilds
- Created: 2023-03-06T05:29:31.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-10-07T17:18:41.000Z (about 1 month ago)
- Last Synced: 2024-10-07T17:21:03.617Z (about 1 month ago)
- Language: Rust
- Homepage: https://docs.rs/sqlx-pgrow-serde
- Size: 13.7 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sqlx_serde
Check lib.rs for tests, which should give you a clear idea how to use the crate.
```rust
async fn main() {
let row: PgRow = conn.fetch_one("select 3.3").await.unwrap();
// option 1 - use function calls
let headers: Vec = read_headers(&row);
let row: Vec = 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.