Struct sea_orm::ExecResult
source · pub struct ExecResult { /* private fields */ }Expand description
Defines the result of executing an operation
Implementations§
source§impl ExecResult
impl ExecResult
sourcepub fn last_insert_id(&self) -> u64
pub fn last_insert_id(&self) -> u64
Get the last id after AUTOINCREMENT is done on the primary key
Examples found in repository?
src/executor/insert.rs (line 149)
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 })
}sourcepub fn rows_affected(&self) -> u64
pub fn rows_affected(&self) -> u64
Get the number of rows affedted by the operation
Examples found in repository?
More examples
src/executor/update.rs (line 144)
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
async fn exec_update<C>(
statement: Statement,
db: &C,
check_record_exists: bool,
) -> Result<UpdateResult, DbErr>
where
C: ConnectionTrait,
{
let result = db.execute(statement).await?;
if check_record_exists && result.rows_affected() == 0 {
return Err(DbErr::RecordNotFound(
"None of the database rows are affected".to_owned(),
));
}
Ok(UpdateResult {
rows_affected: result.rows_affected(),
})
}Trait Implementations§
source§impl Debug for ExecResult
impl Debug for ExecResult
source§impl From<MySqlQueryResult> for ExecResult
impl From<MySqlQueryResult> for ExecResult
source§fn from(result: MySqlQueryResult) -> ExecResult
fn from(result: MySqlQueryResult) -> ExecResult
Converts to this type from the input type.
source§impl From<PgQueryResult> for ExecResult
impl From<PgQueryResult> for ExecResult
source§fn from(result: PgQueryResult) -> ExecResult
fn from(result: PgQueryResult) -> ExecResult
Converts to this type from the input type.
source§impl From<SqliteQueryResult> for ExecResult
impl From<SqliteQueryResult> for ExecResult
source§fn from(result: SqliteQueryResult) -> ExecResult
fn from(result: SqliteQueryResult) -> ExecResult
Converts to this type from the input type.