#sql #table #definition #macro #helper #fields #sql-macros

macro sql-table-macros

Helper macros to generate SQL table definitions

2 releases

new 0.1.2 Nov 16, 2024
0.1.1 Nov 16, 2024
0.1.0 Nov 16, 2024

#974 in Rust patterns

Download history 247/week @ 2024-11-13

247 downloads per month

MIT license

6KB
68 lines

sql-table-macros

Helper macros to auto add sql table common fields to struct definition

Example

#![allow(dead_code)]
use sql_table_macros::table_common_fields;

type Id = u64;

#[table_common_fields(Id, std::time::Duration)]
#[derive(Default, Debug)]
struct User {
    id: String,
    name: String,
}

fn main() {
    let user = User::default();
    assert_eq!(
        format!("{user:?}"),
        r#"User { id: "", name: "", created_by: 0, updated_by: 0, created_at: 0ns, updated_at: 0ns, is_deleted: false }"#
    );
}

Dependencies

~2MB
~46K SLoC