Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split ModelV2 codegen in multiple submodules (part 2) #7269

Merged
merged 16 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions editoast/editoast_derive/src/modelv2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use syn::DeriveInput;

use args::ModelArgs;
use config::*;
use identifier::Identifier;
use identifier::RawIdentifier;

pub fn model(input: &DeriveInput) -> Result<TokenStream> {
let model_name = &input.ident;
Expand All @@ -34,7 +34,17 @@ pub fn model(input: &DeriveInput) -> Result<TokenStream> {
let changeset_builder = config.changeset_builder_impl_block();
let patch_builder = config.patch_builder_impl_block();

let model_impls = config.make_model_traits_impl();
let exist_impls = config.exists_impls();
let retrieve_impls = config.retrieve_impls();
let update_impls = config.update_impls();
let delete_static_impls = config.delete_static_impls();
let create_impl = config.create_impl();
let delete_impl = config.delete_impl();
let create_batch_impl = config.create_batch_impl();
let create_batch_with_key_impls = config.create_batch_with_key_impls();
let retrieve_batch_impls = config.retrieve_batch_impls();
let update_batch_impls = config.update_batch_impls();
let delete_batch_impls = config.delete_batch_impls();

Ok(quote! {
#model_impl
Expand All @@ -50,7 +60,17 @@ pub fn model(input: &DeriveInput) -> Result<TokenStream> {
#changeset_builder
#patch_builder

#model_impls
#(#exist_impls)*
#(#retrieve_impls)*
#(#update_impls)*
#(#delete_static_impls)*
#create_impl
#delete_impl
#create_batch_impl
#(#create_batch_with_key_impls)*
#(#retrieve_batch_impls)*
#(#update_batch_impls)*
#(#delete_batch_impls)*
})
}

Expand Down
56 changes: 28 additions & 28 deletions editoast/editoast_derive/src/modelv2/args.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::Identifier;
use super::RawIdentifier;
use darling::{
ast,
util::{self, PathList},
Expand All @@ -12,64 +12,64 @@ use proc_macro2::Span;
forward_attrs(allow, doc, cfg),
supports(struct_named)
)]
pub struct ModelArgs {
pub table: syn::Path,
pub(super) struct ModelArgs {
pub(super) table: syn::Path,
#[darling(default)]
pub row: GeneratedTypeArgs,
pub(super) row: GeneratedTypeArgs,
#[darling(default)]
pub changeset: GeneratedTypeArgs,
pub(super) changeset: GeneratedTypeArgs,
#[darling(multiple, rename = "identifier")]
pub identifiers: Vec<Identifier>,
pub(super) identifiers: Vec<RawIdentifier>,
#[darling(default)]
pub preferred: Option<Identifier>,
pub data: ast::Data<util::Ignored, ModelFieldArgs>,
pub(super) preferred: Option<RawIdentifier>,
pub(super) data: ast::Data<util::Ignored, ModelFieldArgs>,
}

#[derive(FromMeta, Default, Debug, PartialEq)]
pub struct GeneratedTypeArgs {
pub(super) struct GeneratedTypeArgs {
#[darling(default)]
pub type_name: Option<String>,
pub(super) type_name: Option<String>,
#[darling(default)]
pub derive: PathList,
pub(super) derive: PathList,
#[darling(default)]
pub public: bool,
pub(super) public: bool,
}

#[derive(FromField, Debug)]
#[darling(attributes(model), forward_attrs(allow, doc, cfg))]
pub struct ModelFieldArgs {
pub ident: Option<syn::Ident>,
pub ty: syn::Type,
pub(super) struct ModelFieldArgs {
pub(super) ident: Option<syn::Ident>,
pub(super) ty: syn::Type,
#[darling(default)]
pub builder_fn: Option<syn::Ident>,
pub(super) builder_fn: Option<syn::Ident>,
#[darling(default)]
pub column: Option<String>,
pub(super) column: Option<String>,
#[darling(default)]
pub builder_skip: bool,
pub(super) builder_skip: bool,
#[darling(default)]
pub identifier: bool,
pub(super) identifier: bool,
#[darling(default)]
pub preferred: bool,
pub(super) preferred: bool,
#[darling(default)]
pub primary: bool,
pub(super) primary: bool,
#[darling(default)]
pub json: bool,
pub(super) json: bool,
#[darling(default)]
pub geo: bool,
pub(super) geo: bool,
#[darling(default)]
pub to_string: bool,
pub(super) to_string: bool,
#[darling(default)]
pub to_enum: bool,
pub(super) to_enum: bool,
#[darling(default)]
pub remote: Option<syn::Type>,
pub(super) remote: Option<syn::Type>,
}

impl GeneratedTypeArgs {
pub fn ident(&self) -> syn::Ident {
pub(super) fn ident(&self) -> syn::Ident {
syn::Ident::new(self.type_name.as_ref().unwrap(), Span::call_site())
}

pub fn visibility(&self) -> syn::Visibility {
pub(super) fn visibility(&self) -> syn::Visibility {
if self.public {
syn::Visibility::Public(Default::default())
} else {
Expand Down
Loading
Loading