[−][src]Trait sqlx::Row
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
Loading content...Required methods
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>,
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.
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>,
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>,
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.
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 theusize
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>,
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).