Macro light_magic::db

source ยท
macro_rules! db {
    (
        $(
            $table_ty:ident<$table:ty $( : $($derive:ident),* )?> => {
                $($field_name:ident : $field_ty:ty),*
            }
        ),* $(,)?
    ) => { ... };
    (@impls Table, $table_name:ident, $($field_name:ident : $field_ty:ty),*) => { ... };
    (@impls Custom, $table_name:ident, $($field_name:ident : $field_ty:ty),*) => { ... };
    (@expand_table_ty Table, $first_type:ty, $table_name:ident) => { ... };
    (@expand_table_ty Custom, $first_type:ty, $table_name:ident) => { ... };
    (@get_first_name $value:expr, $first_name:ident, $($rest_name:ident),*) => { ... };
    (@get_first_name $value:expr, $first_name:ident) => { ... };
    (@get_first_type $first_name:ident : $first_ty:ty, $($rest_name:ident : $rest_ty:ty),*) => { ... };
    (@get_first_type $first_name:ident : $first_ty:ty) => { ... };
}
Expand description

Creates the Database struct with the fitting logic. Use open for creating/opening one at a specified path or use open_in_memory to only use one in memory.

Lock the AtomicDatabase using read() / write() to access and change it values. The saving of changes will be applied after the used variables are dropped.

use light_magic::db;

db! {
    // `Table` is the identifier that this will use the builtin table type
    // `User` is the table name
    // `{...}` is the table data
    // the first field, like here `id`, is the `primary_key`
    Table<User> => { id: usize, name: String, kind: String },
    // to not use the builtin table type use `Custom` as the identifier of the table
    // using `:` after the table name you can add your own derives
    // like here `PartialEq`
    Custom<Criminal: PartialEq> => { user_name: String, entry: String }
}