macro_rules! table_definitions {
{
$(
$(#[$meta:meta])*
$table:ident {
$(type $ident_before:ident = $identty_before:ty;)*
fn $table_name_fct:ident() -> String $table_name:block
$(type $ident_after:ident = $identty_after:ty;)*
}
)+
} => { ... };
($($tt:tt)*) => { ... };
}Expand description
Defines one or more DynamoDB table zero-sized types implementing
TableDefinition.
Each definition generates a pub struct with an internal key schema and
a table_name() function. The key schema is derived from the type
declarations:
type PartitionKey = ...only →SimpleKeySchematype PartitionKey = ...+type SortKey = ...→CompositeKeySchema
Multiple table definitions can appear in a single invocation.
§Syntax
table_definitions! {
[doc comments and attributes]
TableName {
type PartitionKey = PkAttr;
type SortKey = SkAttr; // optional
fn table_name() -> String { ... }
}
...
}§Examples
use dynamodb_facade::table_definitions;
table_definitions! {
/// The platform mono-table with composite key (PK + SK).
LearningTable {
type PartitionKey = PK;
type SortKey = SK;
fn table_name() -> String {
std::env::var("TABLE_NAME").unwrap_or_else(|_| "learning".to_owned())
}
}
}
use dynamodb_facade::TableDefinition;
assert_eq!(LearningTable::table_name(), "learning");