WIP
This commit is contained in:
parent
3bada7fbc3
commit
752cc4a44e
@ -1,11 +1,21 @@
|
|||||||
use super::{ColumnTrait, IdenStatic, Iterable};
|
use super::{ColumnTrait, IdenStatic, Iterable};
|
||||||
use crate::TryGetable;
|
use crate::TryGetable;
|
||||||
use sea_query::IntoValueTuple;
|
use sea_query::IntoValueTuple;
|
||||||
use std::fmt::{Debug, Display};
|
use std::{
|
||||||
|
fmt::{Debug, Display},
|
||||||
|
str::FromStr,
|
||||||
|
};
|
||||||
|
|
||||||
//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 + Default + Debug + Display + PartialEq + IntoValueTuple + TryGetable;
|
type ValueType: Sized
|
||||||
|
+ Default
|
||||||
|
+ Debug
|
||||||
|
+ Display
|
||||||
|
+ PartialEq
|
||||||
|
+ IntoValueTuple
|
||||||
|
+ TryGetable
|
||||||
|
+ FromStr;
|
||||||
|
|
||||||
fn auto_increment() -> bool;
|
fn auto_increment() -> bool;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use crate::TryGetable;
|
use crate::TryGetable;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ExecResult {
|
pub struct ExecResult {
|
||||||
@ -22,14 +23,15 @@ pub(crate) enum ExecResultHolder {
|
|||||||
impl ExecResult {
|
impl ExecResult {
|
||||||
pub fn last_insert_id<T>(&self) -> T
|
pub fn last_insert_id<T>(&self) -> T
|
||||||
where
|
where
|
||||||
T: TryGetable + Default,
|
T: TryGetable + Default + FromStr,
|
||||||
{
|
{
|
||||||
match &self.result {
|
match &self.result {
|
||||||
#[cfg(feature = "sqlx-mysql")]
|
#[cfg(feature = "sqlx-mysql")]
|
||||||
ExecResultHolder::SqlxMySql(result) => {
|
ExecResultHolder::SqlxMySql(result) => result
|
||||||
// result.last_insert_id()
|
.last_insert_id()
|
||||||
T::default()
|
.to_string()
|
||||||
}
|
.parse()
|
||||||
|
.unwrap_or_default(),
|
||||||
#[cfg(feature = "sqlx-postgres")]
|
#[cfg(feature = "sqlx-postgres")]
|
||||||
ExecResultHolder::SqlxPostgres(result) => {
|
ExecResultHolder::SqlxPostgres(result) => {
|
||||||
res.try_get("", "last_insert_id").unwrap_or_default()
|
res.try_get("", "last_insert_id").unwrap_or_default()
|
||||||
@ -40,15 +42,15 @@ impl ExecResult {
|
|||||||
if last_insert_rowid < 0 {
|
if last_insert_rowid < 0 {
|
||||||
panic!("negative last_insert_rowid")
|
panic!("negative last_insert_rowid")
|
||||||
} else {
|
} else {
|
||||||
// last_insert_rowid
|
last_insert_rowid.to_string().parse().unwrap_or_default()
|
||||||
T::default()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(feature = "mock")]
|
#[cfg(feature = "mock")]
|
||||||
ExecResultHolder::Mock(result) => {
|
ExecResultHolder::Mock(result) => result
|
||||||
// result.last_insert_id
|
.last_insert_id
|
||||||
T::default()
|
.to_string()
|
||||||
}
|
.parse()
|
||||||
|
.unwrap_or_default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use sea_orm::{entity::*, DbConn, InsertResult};
|
use sea_orm::{entity::*, DbConn};
|
||||||
|
|
||||||
pub use super::common::bakery_chain::*;
|
pub use super::common::bakery_chain::*;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user