Skip to main content

table

Macro table 

Source
macro_rules! table {
    (
        $(#[$meta:meta])*
        $vis:vis struct $name:ident {
            $( $(#[$fmeta:meta])* $fvis:vis $field:ident : $ty:ty ),+ $(,)?
        }
        key = [ $( $key:ident ),* $(,)? ];
    ) => { ... };
}
Expand description

Declares a table once: the struct and its Table impl.

The schema and the values come from the same list of fields. Column names are the field names (r#type is the column type), and key fields must be KeyFields.

use fluidattacks_database_core_domain::cell::Numeric;
use fluidattacks_database_core_domain::table;

table! {
    #[derive(Debug, Clone)]
    pub struct Expense {
        pub id: i64,
        pub description: Option<String>,
        pub amount: Numeric<14, 2>,
    }
    key = [id];
}