Refactor ActiveModelTrait
This commit is contained in:
parent
a746f8b863
commit
2169d1284f
@ -36,8 +36,6 @@ pub fn expand_derive_active_model(ident: Ident, data: Data) -> syn::Result<Token
|
||||
#(pub #field: sea_orm::ActiveValue<#ty>),*
|
||||
}
|
||||
|
||||
impl sea_orm::ActiveModelOf<Entity> for ActiveModel {}
|
||||
|
||||
impl From<#ident> for ActiveModel {
|
||||
fn from(m: #ident) -> Self {
|
||||
Self {
|
||||
|
@ -44,12 +44,6 @@ where
|
||||
ActiveValue::unchanged(value)
|
||||
}
|
||||
|
||||
pub trait ActiveModelOf<E>
|
||||
where
|
||||
E: EntityTrait,
|
||||
{
|
||||
}
|
||||
|
||||
pub trait ActiveModelTrait: Clone + Debug + Default {
|
||||
type Entity: EntityTrait;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
ActiveModelOf, ActiveModelTrait, ColumnTrait, FromQueryResult, Insert, ModelTrait,
|
||||
ActiveModelTrait, ColumnTrait, FromQueryResult, Insert, ModelTrait,
|
||||
OneOrManyActiveModel, PrimaryKeyToColumn, PrimaryKeyTrait, QueryFilter, RelationBuilder,
|
||||
RelationTrait, RelationType, Select,
|
||||
};
|
||||
@ -98,7 +98,7 @@ pub trait EntityTrait: EntityName {
|
||||
|
||||
fn insert<A, C>(models: C) -> Insert<A>
|
||||
where
|
||||
A: ActiveModelTrait + ActiveModelOf<Self>,
|
||||
A: ActiveModelTrait<Entity = Self>,
|
||||
C: OneOrManyActiveModel<A>,
|
||||
{
|
||||
if C::is_one() {
|
||||
@ -112,14 +112,14 @@ pub trait EntityTrait: EntityName {
|
||||
|
||||
fn insert_one<A>(model: A) -> Insert<A>
|
||||
where
|
||||
A: ActiveModelTrait + ActiveModelOf<Self>,
|
||||
A: ActiveModelTrait<Entity = Self>,
|
||||
{
|
||||
Insert::new().one(model)
|
||||
}
|
||||
|
||||
fn insert_many<A, I>(models: I) -> Insert<A>
|
||||
where
|
||||
A: ActiveModelTrait + ActiveModelOf<Self>,
|
||||
A: ActiveModelTrait<Entity = Self>,
|
||||
I: IntoIterator<Item = A>,
|
||||
{
|
||||
Insert::new().many(models)
|
||||
|
@ -1,5 +1,5 @@
|
||||
pub use crate::{
|
||||
ActiveModelOf, ActiveModelTrait, ColumnTrait, ColumnType, DeriveActiveModel, DeriveColumn,
|
||||
ActiveModelTrait, ColumnTrait, ColumnType, DeriveActiveModel, DeriveColumn,
|
||||
DeriveEntity, DeriveModel, DerivePrimaryKey, EntityName, EntityTrait, EnumIter, Iden,
|
||||
IdenStatic, ModelTrait, PrimaryKeyToColumn, PrimaryKeyTrait, QueryFilter, QueryResult, Related,
|
||||
RelationDef, RelationTrait, Select, TypeErr, Value,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{ActiveModelOf, ActiveModelTrait, EntityTrait, Iterable, QueryTrait};
|
||||
use crate::{ActiveModelTrait, EntityTrait, Iterable, QueryTrait};
|
||||
use core::marker::PhantomData;
|
||||
use sea_query::{InsertStatement, IntoIden};
|
||||
|
||||
@ -12,18 +12,23 @@ where
|
||||
pub(crate) model: PhantomData<A>,
|
||||
}
|
||||
|
||||
impl<A> Default for Insert<A>
|
||||
where
|
||||
A: ActiveModelTrait
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl<A> Insert<A>
|
||||
where
|
||||
A: ActiveModelTrait,
|
||||
{
|
||||
pub fn new<E>() -> Self
|
||||
where
|
||||
E: EntityTrait,
|
||||
A: ActiveModelOf<E>,
|
||||
{
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
query: InsertStatement::new()
|
||||
.into_table(E::default().into_iden())
|
||||
.into_table(A::Entity::default().into_iden())
|
||||
.to_owned(),
|
||||
columns: Vec::new(),
|
||||
model: PhantomData,
|
||||
|
Loading…
x
Reference in New Issue
Block a user