pub trait FromQueryResult: Sized {
// Required method
fn from_query_result(res: &QueryResult, pre: &str) -> Result<Self, DbErr>;
// Provided methods
fn from_query_result_optional(
res: &QueryResult,
pre: &str,
) -> Result<Option<Self>, DbErr> { ... }
fn from_query_result_nullable(
res: &QueryResult,
pre: &str,
) -> Result<Self, TryGetError> { ... }
fn find_by_statement(stmt: Statement) -> SelectorRaw<SelectModel<Self>> { ... }
}Expand description
A Trait for implementing a QueryResult
Required Methods§
Sourcefn from_query_result(res: &QueryResult, pre: &str) -> Result<Self, DbErr>
fn from_query_result(res: &QueryResult, pre: &str) -> Result<Self, DbErr>
Instantiate a Model from a QueryResult
NOTE: Please also override from_query_result_nullable when manually implementing.
The future default implementation will be along the lines of:
ⓘ
fn from_query_result(res: &QueryResult, pre: &str) -> Result<Self, DbErr> {
(Self::from_query_result_nullable(res, pre)?)
}Provided Methods§
Sourcefn from_query_result_optional(
res: &QueryResult,
pre: &str,
) -> Result<Option<Self>, DbErr>
fn from_query_result_optional( res: &QueryResult, pre: &str, ) -> Result<Option<Self>, DbErr>
Transform the error from instantiating a Model from a QueryResult and converting it to an Option
Sourcefn from_query_result_nullable(
res: &QueryResult,
pre: &str,
) -> Result<Self, TryGetError>
fn from_query_result_nullable( res: &QueryResult, pre: &str, ) -> Result<Self, TryGetError>
Transform the error from instantiating a Model from a QueryResult and converting it to an Option
NOTE: This will most likely stop being a provided method in the next major version!
Sourcefn find_by_statement(stmt: Statement) -> SelectorRaw<SelectModel<Self>>
fn find_by_statement(stmt: Statement) -> SelectorRaw<SelectModel<Self>>
use sea_orm::{FromQueryResult, query::*};
#[derive(Debug, PartialEq, FromQueryResult)]
struct SelectResult {
name: String,
num_of_cakes: i32,
}
let res: Vec<SelectResult> = SelectResult::find_by_statement(Statement::from_sql_and_values(
DbBackend::Postgres,
r#"SELECT "name", COUNT(*) AS "num_of_cakes" FROM "cake" GROUP BY("name")"#,
[],
))
.all(&db)
?;
assert_eq!(
res,
[SelectResult {
name: "Chocolate Forest".to_owned(),
num_of_cakes: 2,
},]
);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<T: FromQueryResult> FromQueryResult for Option<T>
impl<T: FromQueryResult> FromQueryResult for Option<T>
fn from_query_result(res: &QueryResult, pre: &str) -> Result<Self, DbErr>
fn from_query_result_optional( res: &QueryResult, pre: &str, ) -> Result<Option<Self>, DbErr>
fn from_query_result_nullable( res: &QueryResult, pre: &str, ) -> Result<Self, TryGetError>
Implementors§
impl FromQueryResult for JsonValue
Available on crate feature
with-json only.impl FromQueryResult for sea_orm::rbac::entity::permission::Model
Available on crate feature
rbac only.impl FromQueryResult for sea_orm::rbac::entity::resource::Model
Available on crate feature
rbac only.impl FromQueryResult for sea_orm::rbac::entity::role::Model
Available on crate feature
rbac only.impl FromQueryResult for sea_orm::rbac::entity::role_hierarchy::Model
Available on crate feature
rbac only.impl FromQueryResult for sea_orm::rbac::entity::role_permission::Model
Available on crate feature
rbac only.impl FromQueryResult for sea_orm::rbac::entity::user_override::Model
Available on crate feature
rbac only.impl FromQueryResult for sea_orm::rbac::entity::user_role::Model
Available on crate feature
rbac only.