sql_from_models_proc_macro/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
mod migration_generation;
// mod getters;
mod model;
mod prelude;
use migration_generation::*;
use model::*;
use prelude::*;

#[proc_macro_derive(Model, attributes(model, primary_key, foreign_key, unique, default))]
pub fn model(input: TokenStream) -> TokenStream {
    let derive = parse_macro_input!(input as Model);

    let migrations = generate_migration(&derive.name);
    let template = quote! {
        #derive
        #migrations
    };
    template.into()
}