Derive macros traits with crate name
This commit is contained in:
parent
90388a3523
commit
8d92e09858
@ -4,3 +4,4 @@ cp ../../src/tests_cfg/filling.rs src/example_filling.rs
|
||||
cp ../../src/tests_cfg/cake_filling.rs src/example_cake_filling.rs
|
||||
|
||||
sed -i 's/^use crate::/use sea_orm::/g' src/*.rs
|
||||
sed -i '/^use crate as sea_orm;/d' src/*.rs
|
@ -31,13 +31,13 @@ pub fn expend_derive_column(ident: Ident, data: Data) -> syn::Result<TokenStream
|
||||
.collect();
|
||||
|
||||
Ok(quote!(
|
||||
impl Iden for #ident {
|
||||
impl sea_orm::Iden for #ident {
|
||||
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
|
||||
write!(s, "{}", self.as_str()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
impl IdenStatic for #ident {
|
||||
impl sea_orm::IdenStatic for #ident {
|
||||
fn as_str(&self) -> &str {
|
||||
match self {
|
||||
#(Self::#variant => #name),*
|
||||
|
@ -26,15 +26,15 @@ pub fn expend_derive_entity(ident: Ident, attrs: Vec<Attribute>) -> syn::Result<
|
||||
};
|
||||
|
||||
Ok(quote!(
|
||||
impl EntityName for #ident {}
|
||||
impl sea_orm::EntityName for #ident {}
|
||||
|
||||
impl IdenStatic for #ident {
|
||||
impl sea_orm::IdenStatic for #ident {
|
||||
fn as_str(&self) -> &str {
|
||||
#entity_name
|
||||
}
|
||||
}
|
||||
|
||||
impl Iden for #ident {
|
||||
impl sea_orm::Iden for #ident {
|
||||
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
|
||||
write!(s, "{}", self.as_str()).unwrap();
|
||||
}
|
||||
|
@ -28,22 +28,22 @@ pub fn expend_derive_model(ident: Ident, data: Data) -> syn::Result<TokenStream>
|
||||
.collect();
|
||||
|
||||
Ok(quote!(
|
||||
impl ModelTrait for #ident {
|
||||
impl sea_orm::ModelTrait for #ident {
|
||||
type Column = Column;
|
||||
|
||||
fn get(&self, c: Self::Column) -> Value {
|
||||
fn get(&self, c: Self::Column) -> sea_orm::Value {
|
||||
match c {
|
||||
#(Self::Column::#name => self.#field.clone().into()),*
|
||||
}
|
||||
}
|
||||
|
||||
fn set(&mut self, c: Self::Column, v: Value) {
|
||||
fn set(&mut self, c: Self::Column, v: sea_orm::Value) {
|
||||
match c {
|
||||
#(Self::Column::#name => self.#field = v.unwrap()),*
|
||||
}
|
||||
}
|
||||
|
||||
fn from_query_result(row: &QueryResult, pre: &str) -> Result<Self, TypeErr> {
|
||||
fn from_query_result(row: &sea_orm::QueryResult, pre: &str) -> Result<Self, sea_orm::TypeErr> {
|
||||
Ok(Self {
|
||||
#(#field: row.try_get(pre, Self::Column::#name.as_str().into())?),*
|
||||
})
|
||||
|
@ -31,13 +31,13 @@ pub fn expend_derive_primary_key(ident: Ident, data: Data) -> syn::Result<TokenS
|
||||
.collect();
|
||||
|
||||
Ok(quote!(
|
||||
impl Iden for #ident {
|
||||
impl sea_orm::Iden for #ident {
|
||||
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
|
||||
write!(s, "{}", self.as_str()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
impl IdenStatic for #ident {
|
||||
impl sea_orm::IdenStatic for #ident {
|
||||
fn as_str(&self) -> &str {
|
||||
match self {
|
||||
#(Self::#variant => #name),*
|
||||
@ -45,9 +45,9 @@ pub fn expend_derive_primary_key(ident: Ident, data: Data) -> syn::Result<TokenS
|
||||
}
|
||||
}
|
||||
|
||||
impl PrimaryKeyTrait for #ident {}
|
||||
impl sea_orm::PrimaryKeyTrait for #ident {}
|
||||
|
||||
impl PrimaryKeyOfModel<Model> for #ident {
|
||||
impl sea_orm::PrimaryKeyOfModel<Model> for #ident {
|
||||
fn into_column(self) -> <Model as ModelTrait>::Column {
|
||||
match self {
|
||||
#(Self::#variant => Column::#variant),*
|
||||
|
@ -1,4 +1,5 @@
|
||||
use crate::entity::prelude::*;
|
||||
use crate as sea_orm;
|
||||
|
||||
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
||||
#[table = "cake"]
|
||||
|
@ -1,4 +1,5 @@
|
||||
use crate::entity::prelude::*;
|
||||
use crate as sea_orm;
|
||||
|
||||
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
||||
#[table = "cake_filling"]
|
||||
|
@ -1,4 +1,5 @@
|
||||
use crate::entity::prelude::*;
|
||||
use crate as sea_orm;
|
||||
|
||||
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
||||
#[table = "filling"]
|
||||
|
@ -1,4 +1,5 @@
|
||||
use crate::entity::prelude::*;
|
||||
use crate as sea_orm;
|
||||
|
||||
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
||||
#[table = "fruit"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user