fletch_orm_macros/lib.rs
1//! Procedural macros for the Fletch database toolkit.
2//!
3//! Provides `#[derive(Entity)]` to generate `fletch_orm::Entity` trait
4//! implementations from annotated structs.
5
6mod crate_path;
7mod entity;
8
9use proc_macro::TokenStream;
10
11/// Derive macro to generate `fletch_orm::Entity` trait implementation.
12///
13/// # Struct Attributes
14///
15/// - `#[fletch(table = "table_name")]`: Override the table name
16/// (default: `snake_case` pluralized struct name).
17///
18/// # Field Attributes
19///
20/// - `#[fletch(id)]`: Mark the primary key field (required, exactly one).
21/// - `#[fletch(skip)]`: Exclude a field from persistence.
22/// - `#[fletch(rename = "col_name")]`: Override the column name.
23///
24/// # Example
25///
26/// ```ignore
27/// #[derive(Entity)]
28/// #[fletch(table = "users")]
29/// pub struct User {
30/// #[fletch(id)]
31/// pub id: i64,
32/// pub name: String,
33/// #[fletch(skip)]
34/// pub cached_display: String,
35/// }
36/// ```
37#[proc_macro_derive(Entity, attributes(fletch))]
38pub fn derive_entity(input: TokenStream) -> TokenStream {
39 let input = syn::parse_macro_input!(input as syn::DeriveInput);
40 entity::expand_entity(input).into()
41}