Struct sea_orm::entity::prelude::QueryResult
source · pub struct QueryResult { /* private fields */ }Expand description
Defines the result of a query operation on a Model
Implementations§
source§impl QueryResult
impl QueryResult
sourcepub fn try_get<T>(&self, pre: &str, col: &str) -> Result<T, DbErr>where
T: TryGetable,
pub fn try_get<T>(&self, pre: &str, col: &str) -> Result<T, DbErr>where
T: TryGetable,
Get a Row from a Column
Examples found in repository?
src/executor/paginator.rs (line 83)
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
pub async fn num_items(&self) -> Result<u64, DbErr> {
let builder = self.db.get_database_backend();
let stmt = builder.build(
SelectStatement::new()
.expr(Expr::cust("COUNT(*) AS num_items"))
.from_subquery(
self.query.clone().reset_limit().reset_offset().to_owned(),
Alias::new("sub_query"),
),
);
let result = match self.db.query_one(stmt).await? {
Some(res) => res,
None => return Ok(0),
};
let num_items = match builder {
DbBackend::Postgres => result.try_get::<i64>("", "num_items")? as u64,
_ => result.try_get::<i32>("", "num_items")? as u64,
};
Ok(num_items)
}sourcepub fn try_get_many<T>(&self, pre: &str, cols: &[String]) -> Result<T, DbErr>where
T: TryGetableMany,
pub fn try_get_many<T>(&self, pre: &str, cols: &[String]) -> Result<T, DbErr>where
T: TryGetableMany,
Perform query operations on multiple Columns
Examples found in repository?
src/executor/insert.rs (line 146)
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
async fn exec_insert<A, C>(
primary_key: Option<ValueTuple>,
statement: Statement,
db: &C,
) -> Result<InsertResult<A>, DbErr>
where
C: ConnectionTrait,
A: ActiveModelTrait,
{
type PrimaryKey<A> = <<A as ActiveModelTrait>::Entity as EntityTrait>::PrimaryKey;
type ValueTypeOf<A> = <PrimaryKey<A> as PrimaryKeyTrait>::ValueType;
let last_insert_id_opt = match db.support_returning() {
true => {
let cols = PrimaryKey::<A>::iter()
.map(|col| col.to_string())
.collect::<Vec<_>>();
let res = db.query_one(statement).await?.unwrap();
res.try_get_many("", cols.as_ref()).ok()
}
false => {
let last_insert_id = db.execute(statement).await?.last_insert_id();
ValueTypeOf::<A>::try_from_u64(last_insert_id).ok()
}
};
let last_insert_id = match primary_key {
Some(value_tuple) => FromValueTuple::from_value_tuple(value_tuple),
None => match last_insert_id_opt {
Some(last_insert_id) => last_insert_id,
None => return Err(DbErr::UnpackInsertId),
},
};
Ok(InsertResult { last_insert_id })
}Trait Implementations§
source§impl Debug for QueryResult
impl Debug for QueryResult
source§impl From<MySqlRow> for QueryResult
impl From<MySqlRow> for QueryResult
source§fn from(row: MySqlRow) -> QueryResult
fn from(row: MySqlRow) -> QueryResult
Converts to this type from the input type.
source§impl From<PgRow> for QueryResult
impl From<PgRow> for QueryResult
source§fn from(row: PgRow) -> QueryResult
fn from(row: PgRow) -> QueryResult
Converts to this type from the input type.
source§impl From<SqliteRow> for QueryResult
impl From<SqliteRow> for QueryResult
source§fn from(row: SqliteRow) -> QueryResult
fn from(row: SqliteRow) -> QueryResult
Converts to this type from the input type.