[][src]Trait sqlx::Row

pub trait Row<'c>: Sealed + Unpin + Send + Sync {
    type Database: Database;
    fn len(&self) -> usize;

    fn is_empty(&self) -> bool { ... }
fn get<T, I>(&self, index: I) -> T
    where
        I: ColumnIndex<'c, Self>,
        T: Type<Self::Database> + Decode<'c, Self::Database>
, { ... }
fn get_unchecked<T, I>(&self, index: I) -> T
    where
        I: ColumnIndex<'c, Self>,
        T: Type<Self::Database> + Decode<'c, Self::Database>
, { ... }
fn try_get<T, I>(&self, index: I) -> Result<T, Error>
    where
        I: ColumnIndex<'c, Self>,
        T: Type<Self::Database> + Decode<'c, Self::Database>
, { ... }
fn try_get_unchecked<T, I>(&self, index: I) -> Result<T, Error>
    where
        I: ColumnIndex<'c, Self>,
        T: Type<Self::Database> + Decode<'c, Self::Database>
, { ... } }

Represents a single row from the database.

Applications should not generally need to use this trait. Values of this trait are only encountered when manually implementing FromRow (as opposed to deriving) or iterating a Cursor (returned from Query::fetch).

This trait is sealed and cannot be implemented for types outside of SQLx.

Associated Types

type Database: Database

The Database this Row is implemented for.

Loading content...

Required methods

fn len(&self) -> usize

Returns the number of columns in this row.

Loading content...

Provided methods

fn is_empty(&self) -> bool

Returns true if this row has no columns.

fn get<T, I>(&self, index: I) -> T where
    I: ColumnIndex<'c, Self>,
    T: Type<Self::Database> + Decode<'c, Self::Database>, 

Index into the database row and decode a single value.

A string index can be used to access a column by name and a usize index can be used to access a column by position.

ⓘThis example is not tested
let id: i32 = row.get("id"); // a column named "id"
let name: &str = row.get(1); // the second column in the result

Panics

Panics if the column does not exist or its value cannot be decoded into the requested type. See try_get for a non-panicking version.

fn get_unchecked<T, I>(&self, index: I) -> T where
    I: ColumnIndex<'c, Self>,
    T: Type<Self::Database> + Decode<'c, Self::Database>, 

Index into the database row and decode a single value.

See try_get_unchecked.

fn try_get<T, I>(&self, index: I) -> Result<T, Error> where
    I: ColumnIndex<'c, Self>,
    T: Type<Self::Database> + Decode<'c, Self::Database>, 

Index into the database row and decode a single value.

A string index can be used to access a column by name and a usize index can be used to access a column by position.

ⓘThis example is not tested
let id: i32 = row.try_get("id")?; // a column named "id"
let name: &str = row.try_get(1)?; // the second column in the result

Errors

  • ColumnNotFound if the column by the given name was not found.
  • ColumnIndexOutOfBounds if the usize index was greater than the number of columns in the row.
  • Decode if the value could not be decoded into the requested type.

fn try_get_unchecked<T, I>(&self, index: I) -> Result<T, Error> where
    I: ColumnIndex<'c, Self>,
    T: Type<Self::Database> + Decode<'c, Self::Database>, 

Index into the database row and decode a single value.

Unlike try_get, this method does not check that the type being returned from the database is compatible with the Rust type and just blindly tries to decode the value. An example of where this could be useful is decoding a Postgres enumeration as a Rust string (instead of deriving a new Rust enum).

Loading content...

Implementors

impl<'c> Row<'c> for MySqlRow<'c>[src]

type Database = MySql

impl<'c> Row<'c> for PgRow<'c>[src]

type Database = Postgres

impl<'c> Row<'c> for SqliteRow<'c>[src]

type Database = Sqlite

Loading content...