WIP (workflow will fail)
This commit is contained in:
parent
a49f880f4f
commit
d14322ad75
@ -28,7 +28,7 @@ pub enum PrimaryKey {
|
||||
}
|
||||
|
||||
impl PrimaryKeyTrait for PrimaryKey {
|
||||
type ValueType = i32;
|
||||
type ValueType = (i32, i32);
|
||||
|
||||
fn auto_increment() -> bool {
|
||||
false
|
||||
|
@ -30,7 +30,7 @@ pub enum PrimaryKey {
|
||||
}
|
||||
|
||||
impl PrimaryKeyTrait for PrimaryKey {
|
||||
type ValueType = i32;
|
||||
type ValueType = (i32, i32);
|
||||
|
||||
fn auto_increment() -> bool {
|
||||
false
|
||||
|
@ -225,16 +225,14 @@ where
|
||||
if <E::PrimaryKey as PrimaryKeyTrait>::auto_increment()
|
||||
&& res.last_insert_id != <E::PrimaryKey as PrimaryKeyTrait>::ValueType::default()
|
||||
{
|
||||
let last_insert_id = res.last_insert_id.to_string();
|
||||
let find = E::find_by_id(res.last_insert_id).one(db);
|
||||
let found = find.await;
|
||||
let model: Option<E::Model> = found?;
|
||||
match model {
|
||||
Some(model) => Ok(model.into_active_model()),
|
||||
None => Err(DbErr::Exec(format!(
|
||||
"Failed to find inserted item: {} {}",
|
||||
"Failed to find inserted item: {}",
|
||||
E::default().to_string(),
|
||||
last_insert_id
|
||||
))),
|
||||
}
|
||||
} else {
|
||||
|
@ -1,17 +1,16 @@
|
||||
use super::{ColumnTrait, IdenStatic, Iterable};
|
||||
use crate::{TryFromU64, TryGetable};
|
||||
use crate::{TryFromU64, TryGetableMany};
|
||||
use sea_query::IntoValueTuple;
|
||||
use std::fmt::{Debug, Display};
|
||||
use std::fmt::Debug;
|
||||
|
||||
//LINT: composite primary key cannot auto increment
|
||||
pub trait PrimaryKeyTrait: IdenStatic + Iterable {
|
||||
type ValueType: Sized
|
||||
+ Default
|
||||
+ Debug
|
||||
+ Display
|
||||
+ PartialEq
|
||||
+ IntoValueTuple
|
||||
+ TryGetable
|
||||
+ TryGetableMany
|
||||
+ TryFromU64;
|
||||
|
||||
fn auto_increment() -> bool;
|
||||
|
@ -17,10 +17,8 @@ pub(crate) enum QueryResultRow {
|
||||
Mock(crate::MockRow),
|
||||
}
|
||||
|
||||
pub trait TryGetable {
|
||||
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, DbErr>
|
||||
where
|
||||
Self: Sized;
|
||||
pub trait TryGetable: Sized {
|
||||
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, DbErr>;
|
||||
}
|
||||
|
||||
// QueryResult //
|
||||
@ -406,6 +404,72 @@ impl TryGetable for Option<Decimal> {
|
||||
#[cfg(feature = "with-uuid")]
|
||||
try_getable_all!(uuid::Uuid);
|
||||
|
||||
// TryGetableMany //
|
||||
|
||||
pub trait TryGetableMany: Sized {
|
||||
fn try_get_many(res: &QueryResult, pre: &str, cols: &[String]) -> Result<Self, DbErr>;
|
||||
}
|
||||
|
||||
impl<T> TryGetableMany for T
|
||||
where
|
||||
T: TryGetable,
|
||||
{
|
||||
fn try_get_many(res: &QueryResult, pre: &str, cols: &[String]) -> Result<Self, DbErr> {
|
||||
let expect_len = 1;
|
||||
if cols.len() < expect_len {
|
||||
return Err(DbErr::Query(format!(
|
||||
"Expect {} column names supplied but got slice of length {}",
|
||||
expect_len,
|
||||
cols.len()
|
||||
)));
|
||||
}
|
||||
T::try_get(res, pre, &cols[0])
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> TryGetableMany for (T, T)
|
||||
where
|
||||
T: TryGetable,
|
||||
{
|
||||
fn try_get_many(res: &QueryResult, pre: &str, cols: &[String]) -> Result<Self, DbErr> {
|
||||
let expect_len = 2;
|
||||
if cols.len() < expect_len {
|
||||
return Err(DbErr::Query(format!(
|
||||
"Expect {} column names supplied but got slice of length {}",
|
||||
expect_len,
|
||||
cols.len()
|
||||
)));
|
||||
}
|
||||
Ok((
|
||||
T::try_get(res, pre, &cols[0])?,
|
||||
T::try_get(res, pre, &cols[1])?,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> TryGetableMany for (T, T, T)
|
||||
where
|
||||
T: TryGetable,
|
||||
{
|
||||
fn try_get_many(res: &QueryResult, pre: &str, cols: &[String]) -> Result<Self, DbErr> {
|
||||
let expect_len = 3;
|
||||
if cols.len() < expect_len {
|
||||
return Err(DbErr::Query(format!(
|
||||
"Expect {} column names supplied but got slice of length {}",
|
||||
expect_len,
|
||||
cols.len()
|
||||
)));
|
||||
}
|
||||
Ok((
|
||||
T::try_get(res, pre, &cols[0])?,
|
||||
T::try_get(res, pre, &cols[1])?,
|
||||
T::try_get(res, pre, &cols[2])?,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
// TryFromU64 //
|
||||
|
||||
pub trait TryFromU64: Sized {
|
||||
fn try_from_u64(n: u64) -> Result<Self, DbErr>;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ pub enum PrimaryKey {
|
||||
}
|
||||
|
||||
impl PrimaryKeyTrait for PrimaryKey {
|
||||
type ValueType = i32;
|
||||
type ValueType = (i32, i32);
|
||||
|
||||
fn auto_increment() -> bool {
|
||||
false
|
||||
|
@ -35,7 +35,7 @@ pub enum PrimaryKey {
|
||||
}
|
||||
|
||||
impl PrimaryKeyTrait for PrimaryKey {
|
||||
type ValueType = i32;
|
||||
type ValueType = (i32, i32);
|
||||
|
||||
fn auto_increment() -> bool {
|
||||
false
|
||||
|
@ -28,7 +28,7 @@ pub enum PrimaryKey {
|
||||
}
|
||||
|
||||
impl PrimaryKeyTrait for PrimaryKey {
|
||||
type ValueType = i32;
|
||||
type ValueType = (i32, i32);
|
||||
|
||||
fn auto_increment() -> bool {
|
||||
false
|
||||
|
Loading…
x
Reference in New Issue
Block a user