Trait tokio_postgres_extractor::Columns
source · pub trait Columns {
type Columns: Unpin + Index<usize, Output = usize>;
// Required method
fn columns(row: &Row) -> Self::Columns;
}
Expand description
A type whose fields map to Postgres columns.
This trait is almost always derived with the Columns proc macro:
#[derive(Columns)]
struct User<'a> {
id: i32,
name: &'a str,
}
In this case the associated Columns
type is [usize; N]
where N
is the number of
fields.
Assume that a Row
was created from the following query:
select 'john' user, 123 balance, 1 id;
Then the implementation of Columns
for the type User
above should return [2, 0]
because the id
field maps to the third column and the name
field maps to the
first column.