Skip to content

Commit

Permalink
added feature flag for sea-orm iden dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
darkmmon committed Jul 11, 2023
1 parent 621f605 commit 2284bb3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ with-time = ["time"]
with-ipnetwork = ["ipnetwork"]
with-mac_address = ["mac_address"]
tests-cfg = []
sea-orm = []

[[test]]
name = "test-derive"
Expand Down
20 changes: 16 additions & 4 deletions sea-query-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ fn impl_iden_for_unit_struct(
ident: &proc_macro2::Ident,
table_name: &str,
) -> proc_macro2::TokenStream {
let flagged_path = if cfg!(feature = "sea-orm") {
quote!(sea_orm::sea_query)
} else {
quote!(sea_query)
};

let prepare = if must_be_valid_iden(table_name) {
quote! {
fn prepare(&self, s: &mut dyn ::std::fmt::Write, q: sea_query::Quote) {
fn prepare(&self, s: &mut dyn ::std::fmt::Write, q: #flagged_path::Quote) {
write!(s, "{}", q.left()).unwrap();
self.unquoted(s);
write!(s, "{}", q.right()).unwrap();
Expand All @@ -57,8 +63,9 @@ fn impl_iden_for_unit_struct(
} else {
quote! {}
};

quote! {
impl sea_query::Iden for #ident {
impl #flagged_path::Iden for #ident {
#prepare

fn unquoted(&self, s: &mut dyn ::std::fmt::Write) {
Expand Down Expand Up @@ -91,9 +98,14 @@ where
Err(e) => return e.to_compile_error(),
};

let flagged_path = if cfg!(feature = "sea-orm") {
quote!(sea_orm::sea_query)
} else {
quote!(sea_query)
};
let prepare = if is_all_valid {
quote! {
fn prepare(&self, s: &mut dyn ::std::fmt::Write, q: sea_query::Quote) {
fn prepare(&self, s: &mut dyn ::std::fmt::Write, q: #flagged_path::Quote) {
write!(s, "{}", q.left()).unwrap();
self.unquoted(s);
write!(s, "{}", q.right()).unwrap();
Expand All @@ -104,7 +116,7 @@ where
};

quote! {
impl sea_query::Iden for #ident {
impl #flagged_path::Iden for #ident {
#prepare

fn unquoted(&self, s: &mut dyn ::std::fmt::Write) {
Expand Down

0 comments on commit 2284bb3

Please sign in to comment.