Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bytebaker/from-psqlrow-rs
https://github.com/bytebaker/from-psqlrow-rs
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/bytebaker/from-psqlrow-rs
- Owner: ByteBaker
- License: mit
- Created: 2023-09-27T17:47:26.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-21T02:54:41.000Z (about 1 year ago)
- Last Synced: 2023-10-21T03:25:51.204Z (about 1 year ago)
- Language: Rust
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# from-psql-row
_A simple crate to convert from [tokio_postgres::Row](https://docs.rs/tokio-postgres/latest/tokio_postgres/row/struct.Row.html) to a struct_. It's practically like [serde_postgres](https://docs.rs/serde_postgres/latest/serde_postgres/), except **dumber**, and **simpler**.
---
**What does it do?**
Nothing fancy, just creates an `impl TryFrom for MyStruct` if `MyStruct` is what you started with.
**Why should I use this, if `serde_postgres` is available?**
Because it's so SIMPLE. `serde_postgres` needs your struct to have `#[derive(Deserialize)]`, meaning `serde` is needed. If for some reason all you want is to create a struct from `Row` without having to manually populate fields using `row.get::<_, T>("columnName")` for each column, while avoiding `serde` (and keeping a minimal dependency footprint), you're in the right place.
#### Features
- First off, the `impl`. (Duh!)
- Works for any data type that implements [tokio_postgres::FromSql](https://docs.rs/tokio-postgres/latest/tokio_postgres/types/trait.FromSql.html) trait.
- Can handle fields with reserved keyword names. E.g., `r#type` maps to column "**type**" inside the `Row`.
- Struct fields can be aliased to different column names. E.g., `user_name` can be aliased to column `user`. Check usage.#### Usage
```rust
use from_psql_row::FromPsql;#[derive(FromPsql)]
struct MyStruct {
#[sqlfield("userId")] // Maps to column 'userId', not 'user_name'
user_name: Uuid,
r#type: Option, // Maps to column 'type'
age: u8,
}
```
---
To use it in your project, run
```
cargo add from-psql-row --git https://github.com/ByteBaker/from-psqlrow-rs
```
or just add the following line to your `Cargo.toml`
```toml
from-psql-row = { version = "0.1.0", git = "https://github.com/ByteBaker/from-psqlrow-rs" }
```