PrimaryKey auto_increment
This commit is contained in:
parent
991b04580c
commit
71d0cde771
@ -26,6 +26,12 @@ pub enum PrimaryKey {
|
|||||||
Id,
|
Id,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
fn auto_increment() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||||
pub enum Relation {
|
pub enum Relation {
|
||||||
Fruit,
|
Fruit,
|
||||||
|
@ -27,6 +27,12 @@ pub enum PrimaryKey {
|
|||||||
FillingId,
|
FillingId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
fn auto_increment() -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||||
pub enum Relation {
|
pub enum Relation {
|
||||||
Cake,
|
Cake,
|
||||||
|
@ -26,6 +26,12 @@ pub enum PrimaryKey {
|
|||||||
Id,
|
Id,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
fn auto_increment() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||||
pub enum Relation {}
|
pub enum Relation {}
|
||||||
|
|
||||||
|
@ -28,6 +28,12 @@ pub enum PrimaryKey {
|
|||||||
Id,
|
Id,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
fn auto_increment() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||||
pub enum Relation {}
|
pub enum Relation {}
|
||||||
|
|
||||||
|
@ -45,8 +45,6 @@ pub fn expand_derive_primary_key(ident: Ident, data: Data) -> syn::Result<TokenS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl sea_orm::PrimaryKeyTrait for #ident {}
|
|
||||||
|
|
||||||
impl sea_orm::PrimaryKeyToColumn for #ident {
|
impl sea_orm::PrimaryKeyToColumn for #ident {
|
||||||
type Column = Column;
|
type Column = Column;
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
use crate::{Database, DeleteResult, EntityTrait, ExecErr, Iterable, PrimaryKeyToColumn, Value};
|
use crate::{
|
||||||
|
Database, DeleteResult, EntityTrait, ExecErr, Iterable, PrimaryKeyToColumn, PrimaryKeyTrait,
|
||||||
|
Value,
|
||||||
|
};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
@ -258,7 +261,7 @@ where
|
|||||||
let exec = E::insert(am).exec(db);
|
let exec = E::insert(am).exec(db);
|
||||||
let res = exec.await?;
|
let res = exec.await?;
|
||||||
// TODO: if the entity does not have auto increment primary key, then last_insert_id is a wrong value
|
// TODO: if the entity does not have auto increment primary key, then last_insert_id is a wrong value
|
||||||
if res.last_insert_id != 0 {
|
if <E::PrimaryKey as PrimaryKeyTrait>::auto_increment() && res.last_insert_id != 0 {
|
||||||
let find = E::find_by(res.last_insert_id).one(db);
|
let find = E::find_by(res.last_insert_id).one(db);
|
||||||
let res = find.await;
|
let res = find.await;
|
||||||
let model: Option<E::Model> = res.map_err(|_| ExecErr)?;
|
let model: Option<E::Model> = res.map_err(|_| ExecErr)?;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
use super::{ColumnTrait, IdenStatic, Iterable};
|
use super::{ColumnTrait, IdenStatic, Iterable};
|
||||||
|
|
||||||
pub trait PrimaryKeyTrait: IdenStatic + Iterable {}
|
pub trait PrimaryKeyTrait: IdenStatic + Iterable {
|
||||||
|
fn auto_increment() -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
pub trait PrimaryKeyToColumn {
|
pub trait PrimaryKeyToColumn {
|
||||||
type Column: ColumnTrait;
|
type Column: ColumnTrait;
|
||||||
|
@ -27,6 +27,12 @@ pub enum PrimaryKey {
|
|||||||
Id,
|
Id,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
fn auto_increment() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||||
pub enum Relation {
|
pub enum Relation {
|
||||||
Fruit,
|
Fruit,
|
||||||
|
@ -28,6 +28,12 @@ pub enum PrimaryKey {
|
|||||||
FillingId,
|
FillingId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
fn auto_increment() -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||||
pub enum Relation {
|
pub enum Relation {
|
||||||
Cake,
|
Cake,
|
||||||
|
@ -27,6 +27,12 @@ pub enum PrimaryKey {
|
|||||||
Id,
|
Id,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
fn auto_increment() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||||
pub enum Relation {}
|
pub enum Relation {}
|
||||||
|
|
||||||
|
@ -29,6 +29,12 @@ pub enum PrimaryKey {
|
|||||||
Id,
|
Id,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PrimaryKeyTrait for PrimaryKey {
|
||||||
|
fn auto_increment() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||||
pub enum Relation {}
|
pub enum Relation {}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user