bottle_orm_macro/lib.rs
1use proc_macro::TokenStream;
2use syn::{parse_macro_input, DeriveInput};
3
4mod types;
5mod derive_model;
6
7/// Derives the `Model` trait for a struct.
8///
9/// This macro inspects the struct fields and generates the necessary code to map it to a database table.
10/// It supports customization via the `#[orm(...)]` attribute.
11///
12/// # Supported Attributes
13///
14/// * `primary_key`: Marks the field as a primary key.
15/// * `unique`: Adds a UNIQUE constraint.
16/// * `index`: Creates a database index.
17/// * `create_time`: Sets default value to CURRENT_TIMESTAMP.
18/// * `size = N`: Sets column size (VARCHAR(N)).
19/// * `foreign_key = "Table::Column"`: Defines a Foreign Key.
20#[proc_macro_derive(Model, attributes(orm))]
21pub fn model_derive(input: TokenStream) -> TokenStream {
22 let ast = parse_macro_input!(input as DeriveInput);
23 let expanded = derive_model::expand(ast);
24 TokenStream::from(expanded)
25}