macro_rules! key_schema {
{
$(#[$meta:meta])*
$ksname:ident {
type SortKey = $skty:ty;
type PartitionKey = $pkty:ty;
}
} => { ... };
{
$(#[$meta:meta])*
$ksname:ident {
type PartitionKey = $pkty:ty;
type SortKey = $skty:ty;
}
} => { ... };
{
$(#[$meta:meta])*
$ksname:ident {
type PartitionKey = $pkty:ty;
}
} => { ... };
($($tt:tt)*) => { ... };
}Expand description
Defines a key schema struct implementing KeySchema.
This is a lower-level macro used internally by table_definitions! and
index_definitions!. You can use it directly when you need a named key
schema type outside of a table or index definition.
Generates a pub struct that implements:
KeySchema— alwaysSimpleKeySchema— when onlyPartitionKeyis givenCompositeKeySchema— when bothPartitionKeyandSortKeyare given
§Syntax
Simple key (partition key only):
key_schema! {
MySchema {
type PartitionKey = MyPkAttr;
}
}Composite key (partition + sort key):
key_schema! {
MySchema {
type PartitionKey = MyPkAttr;
type SortKey = MySkAttr;
}
}The PartitionKey and SortKey fields may appear in either order.
The given types must implement AttributeDefinition and will
typically have been created using attribute_definitions!
§Examples
use dynamodb_facade::{key_schema, CompositeKeySchema, KeySchema, SimpleKeySchema};
key_schema! {
UserSchema {
type PartitionKey = PK;
type SortKey = SK;
}
}
key_schema! {
ConfigSchema {
type PartitionKey = PK;
}
}
fn _assert_composite<KS: CompositeKeySchema>() {}
fn _assert_simple<KS: SimpleKeySchema>() {}
_assert_composite::<UserSchema>();
_assert_simple::<ConfigSchema>();