macro_rules! table {
(
$table_name:ident ($first_pk:ident, $($rest_pk:ident),+ $(,)?) {
$($col_name:ident -> $col_type:tt),* $(,)?
}
) => { ... };
(
$table_name:ident ($pk:ident) {
$($col_name:ident -> $col_type:tt),* $(,)?
}
) => { ... };
(@resolve_column_type $type:ident) => { ... };
(@resolve_column_type Custom($rust_type:ty, $type_name:expr)) => { ... };
(@resolve_column_type $type_name:expr) => { ... };
(@column_type $type:ident) => { ... };
(@column_type Custom($rust_type:ty, $type_name:expr)) => { ... };
(@rust_type $type:ident) => { ... };
(@rust_type Custom($rust_type:ty, $type_name:expr)) => { ... };
(@ddl_columns $first_col:ident -> Custom($rust_type:ty, $type_name:expr)) => { ... };
(@ddl_columns $first_col:ident -> $first_type:ident) => { ... };
(@ddl_columns $first_col:ident -> $first_type:ident, $($rest_col:ident -> $rest_type:tt),*) => { ... };
(@ddl_columns $first_col:ident -> Custom($rust_type:ty, $type_name:expr), $($rest_col:ident -> $rest_type:tt),*) => { ... };
(@sql_type $type:ident) => { ... };
(@sql_type Custom($rust_type:ty, $type_name:expr)) => { ... };
(@pk_columns $first_pk:ident) => { ... };
(@pk_columns $first_pk:ident, $($rest_pk:ident),+) => { ... };
(@pk_string $first_pk:ident) => { ... };
(@pk_string $first_pk:ident, $($rest_pk:ident),+) => { ... };
}Expand description
Macro for defining database tables
ยงExample
use ignis_db::table;
table! {
users (id) {
id -> Int4,
email -> Varchar,
created_at -> Timestamptz,
}
}
// Then use builder pattern for constraints:
users::configure(|t| {
if let Some(email_col) = t.column("email") {
email_col.set_not_null().set_unique();
}
if let Some(name_col) = t.column("name") {
name_col.set_not_null();
}
t
});