[][src]Trait tokio_pg_mapper::FromTokioPostgresRow

pub trait FromTokioPostgresRow: Sized {
    fn from_row(row: TokioRow) -> Result<Self, Error>;
fn from_row_ref(row: &TokioRow) -> Result<Self, Error>;
fn sql_table() -> String;
fn sql_fields() -> String;
fn sql_table_fields() -> String; }

Trait containing various methods for converting from a tokio-postgres Row to a mapped type.

When using the pg_mapper_derive crate's TokioPostgresMapper proc-macro, this will automatically be implemented on types.

The [from_row] method exists for consuming a Row - useful for iterator mapping - while [from_row_ref] exists for borrowing a Row.

Required methods

fn from_row(row: TokioRow) -> Result<Self, Error>

Converts from a tokio-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::Conversion if there was an error converting the row column to the requested type.

fn from_row_ref(row: &TokioRow) -> Result<Self, Error>

Converts from a tokio-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::Conversion if there was an error converting the row column into 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, excluding table name prefix.

Example:

The following will return the String " id, 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>,
    }

fn sql_table_fields() -> String

Get a list of the field names, including table name prefix.

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>,
    }
Loading content...

Implementors

Loading content...