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