pub trait FromQueryResult:
Sized
+ Send
+ Sync {
// Required method
fn from_query_result(row: &Row, prefix: &str) -> Result<Self>;
// Provided method
fn from_query_result_optional(
row: &Row,
prefix: &str,
) -> Result<Option<Self>> { ... }
}Expand description
A type that can be built from a result row.
Derived by DeriveEntityModel for models and by FromQueryResult for
custom projection structs; implemented here for tuples, read by
position, and for a JSON object, behind the with-json feature.
Required Methods§
Sourcefn from_query_result(row: &Row, prefix: &str) -> Result<Self>
fn from_query_result(row: &Row, prefix: &str) -> Result<Self>
Builds a value from row, reading columns named {prefix}{column}.
The prefix is empty for plain selects and A_ / B_ for the two
sides of a find_also_related query.
§Errors
Returns DbErr::Driver when a required column is missing from the
row or cannot be decoded as the field type.
Provided Methods§
Sourcefn from_query_result_optional(row: &Row, prefix: &str) -> Result<Option<Self>>
fn from_query_result_optional(row: &Row, prefix: &str) -> Result<Option<Self>>
Like from_query_result, but returns
Ok(None) when every column carrying prefix is NULL.
This is how the optional side of a LEFT JOIN is detected: a row
without a match has all of its B_ columns NULL, which would
otherwise fail to decode into non-nullable fields.
§Errors
Returns DbErr::Driver when a column is present but cannot be decoded.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl FromQueryResult for Value
Available on crate feature with-json only.Decodes a row into a JSON object keyed by the column names without
prefix.
impl FromQueryResult for Value
with-json only.Decodes a row into a JSON object keyed by the column names without
prefix.
Integers and reals become numbers, text a string, NULL null, and a
blob an array of byte values, since JSON has no binary type.