[−][src]Trait postgres_mapper::FromPostgresRow
Trait containing various methods for converting from a postgres Row to a mapped type.
When using the postgres_mapper_derive
crate's PostgresMapper
proc-macro,
this will automatically be implemented on types.
The [from_postgres_row
] method exists for consuming a Row
- useful for
iterator mapping - while [from_postgres_row_ref
] exists for borrowing a
Row
.
Required methods
fn from_postgres_row(row: PostgresRow) -> Result<Self, Error>
Converts from a postgres Row
into a mapped type, consuming the given
Row
.
Errors
Returns Error::ColumnNotFound
if the column in a mapping was not
found.
Returns Error::Postgres
if there was an error converting the row
column to the requested type.
fn from_postgres_row_ref(row: &PostgresRow) -> Result<Self, Error>
Converts from a postgres
Row
into a mapped type, borrowing the given
Row
.
Errors
Returns Error::ColumnNotFound
if the column in a mapping was not
found.
Returns Error::Postgres
if there was an error converting the row
column to the requested type.
fn sql_table() -> String
Get the name of the annotated sql table name.
Example:
The following will return the String " user ". Note the extra spaces on either side to avoid incorrect formatting.
#[derive(PostgresMapper)] #[pg_mapper(table = "user")] pub struct User { pub id: i64, pub email: Option<String>, }
fn sql_fields() -> String
Get a list of the field names which can be used to construct a SQL query.
We also expect an attribute tag #[pg_mapper(table = "foo")] so that a scoped list of fields can be generated.
Example:
The following will return the String " user.id, user.email ". Note the extra spaces on either side to avoid incorrect formatting.
#[derive(PostgresMapper)] #[pg_mapper(table = "user")] pub struct User { pub id: i64, pub email: Option<String>, }