pub trait TryGetableMany: Sized {
// Required methods
fn try_get_many(
res: &QueryResult,
pre: &str,
cols: &[String],
) -> Result<Self, TryGetError>;
fn try_get_many_by_index(res: &QueryResult) -> Result<Self, TryGetError>;
// Provided method
fn find_by_statement<C>(
stmt: Statement,
) -> SelectorRaw<SelectGetableValue<Self, C>>
where C: IntoEnumIterator + Iden { ... }
}
Expand description
An interface to get a tuple value from the query result
Required Methodsยง
Sourcefn try_get_many(
res: &QueryResult,
pre: &str,
cols: &[String],
) -> Result<Self, TryGetError>
fn try_get_many( res: &QueryResult, pre: &str, cols: &[String], ) -> Result<Self, TryGetError>
Get a tuple value from the query result with prefixed column name
Sourcefn try_get_many_by_index(res: &QueryResult) -> Result<Self, TryGetError>
fn try_get_many_by_index(res: &QueryResult) -> Result<Self, TryGetError>
Get a tuple value from the query result based on the order in the select expressions
Provided Methodsยง
Sourcefn find_by_statement<C>(
stmt: Statement,
) -> SelectorRaw<SelectGetableValue<Self, C>>where
C: IntoEnumIterator + Iden,
fn find_by_statement<C>(
stmt: Statement,
) -> SelectorRaw<SelectGetableValue<Self, C>>where
C: IntoEnumIterator + Iden,
use sea_orm::{entity::*, query::*, tests_cfg::cake, DeriveIden, EnumIter, TryGetableMany};
#[derive(EnumIter, DeriveIden)]
enum ResultCol {
Name,
NumOfCakes,
}
let res: Vec<(String, i32)> =
<(String, i32)>::find_by_statement::<ResultCol>(Statement::from_sql_and_values(
DbBackend::Postgres,
r#"SELECT "cake"."name", count("cake"."id") AS "num_of_cakes" FROM "cake""#,
[],
))
.all(&db)
.await?;
assert_eq!(
res,
[
("Chocolate Forest".to_owned(), 1),
("New York Cheese".to_owned(), 1),
]
);
assert_eq!(
db.into_transaction_log(),
[Transaction::from_sql_and_values(
DbBackend::Postgres,
r#"SELECT "cake"."name", count("cake"."id") AS "num_of_cakes" FROM "cake""#,
[]
),]
);
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.