Skip to content

Commit

Permalink
revert: Again.
Browse files Browse the repository at this point in the history
Refs: 9bac6e9
  • Loading branch information
langyo committed Oct 28, 2023
1 parent 9bac6e9 commit 151eb1d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/database/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl From<ExecResult> for ProxyExecResult {
#[cfg(feature = "sqlx-mysql")]
ExecResultHolder::SqlxMySql(result) => {
ProxyExecResult::Inserted(vec![ProxyExecResultIdType::Integer(
result.last_insert_id().unwrap_or(0),
result.last_insert_id(),
)])
}
#[cfg(feature = "sqlx-postgres")]
Expand Down
43 changes: 38 additions & 5 deletions src/executor/insert.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
error::*, ActiveModelTrait, ColumnTrait, ConnectionTrait, EntityTrait, Insert, IntoActiveModel,
Iterable, PrimaryKeyToColumn, PrimaryKeyTrait, SelectModel, SelectorRaw, Statement, TryFromU64,
TryInsert,
error::*, ActiveModelTrait, ColumnTrait, ConnectionTrait, EntityTrait, ExecResultHolder,
Insert, IntoActiveModel, Iterable, PrimaryKeyToColumn, PrimaryKeyTrait, ProxyExecResult,
ProxyExecResultIdType, SelectModel, SelectorRaw, Statement, TryFromU64, TryInsert,
};
use sea_query::{Expr, FromValueTuple, Iden, InsertStatement, IntoColumnRef, Query, ValueTuple};
use std::{future::Future, marker::PhantomData};
Expand Down Expand Up @@ -241,8 +241,41 @@ where
if res.rows_affected() == 0 {
return Err(DbErr::RecordNotInserted);
}
let last_insert_id = res.last_insert_id();
ValueTypeOf::<A>::try_from_u64(last_insert_id).map_err(|_| DbErr::UnpackInsertId)?
match res.result {
ExecResultHolder::Proxy(val) => match val {
ProxyExecResult::Empty | ProxyExecResult::Conflicted => {
return Err(DbErr::RecordNotInserted);
}
ProxyExecResult::Inserted(val) => {
match val.last().ok_or(DbErr::UnpackInsertId)? {
ProxyExecResultIdType::Integer(val) => {
ValueTypeOf::<A>::try_from_u64(*val)
.map_err(|_| DbErr::UnpackInsertId)?
}
ProxyExecResultIdType::String(val) => {
ValueTypeOf::<A>::from_value_tuple(ValueTuple::One(
sea_query::Value::String(Some(Box::new(val.to_owned()))),
))
}
ProxyExecResultIdType::Uuid(val) => {
ValueTypeOf::<A>::from_value_tuple(ValueTuple::One(
sea_query::Value::Uuid(Some(Box::new(val.to_owned()))),
))
}
ProxyExecResultIdType::Bytes(val) => {
ValueTypeOf::<A>::from_value_tuple(ValueTuple::One(
sea_query::Value::Bytes(Some(Box::new(val.to_owned()))),
))
}
}
}
},
_ => {
let last_insert_id = res.last_insert_id();
ValueTypeOf::<A>::try_from_u64(last_insert_id)
.map_err(|_| DbErr::UnpackInsertId)?
}
}
}
};

Expand Down

0 comments on commit 151eb1d

Please sign in to comment.