#row #postgresql #derive

pg_mapper

derive TryFrom<tokio_postgres::Row>

3个不稳定版本

0.2.1 2022年3月10日
0.2.0 2022年2月6日
0.1.0 2021年12月27日

#64#row

Download history 3/week @ 2024-03-11 2/week @ 2024-03-25 51/week @ 2024-04-01 9/week @ 2024-05-20 23/week @ 2024-06-10 32/week @ 2024-06-17 35/week @ 2024-06-24

90 每月下载量
用于 inline-sql

MIT 许可证

6KB
89 代码行

#[derive(TryFromRow)]

文档 | Crates.io

示例

/// This will try to get each column value by name.
#[derive(pg_mapper::TryFromRow)]
struct User {
    email: String,
    password_digest: String,
}

/// This will try to get each column value by index.
#[derive(pg_mapper::TryFromRow)]
struct Point(i32, i32, i32);

生成

impl TryFrom<tokio_postgres::Row> for User {
    type Error = tokio_postgres::Error;
    fn try_from(row: tokio_postgres::Row) -> Result<Self, Self::Error> {
        Ok(Self {
            email: row.try_get("email")?,
            password_digest: row.try_get("password_digest")?,
        })
    }
}

impl TryFrom<tokio_postgres::Row> for Point {
    type Error = tokio_postgres::Error;
    fn try_from(row: tokio_postgres::Row) -> Result<Self, Self::Error> {
        Ok(Self(row.try_get(0)?, row.try_get(1)?, row.try_get(2)?))
    }
}

依赖

~1.5MB
~34K SLoC