如何使用父实体的元数据来构造DynamoDB表

时间:2019-01-04 01:22:18

标签: amazon-dynamodb

我正在使用DynamoDB作为后端构建Rest API。

我有两个相互关联的实体:ProjectVersion,关系是:Project可以有多个Versions

我有2个端点:

项目/ {项目}

返回Project,并嵌套所有Versions

响应如下:

{
    "name": "php",
    "abandoned": false,
    "versions": { ... }
}

projects / {project}?version = {version}

为指定项目返回一个Version

响应如下:

{
    "version": "5.3",
    "long_term_support": false,
    "support_ends": "2011-06-30",
    "security_ends": "2012-06-30"
}

我当前的表定义如下:

{
    "Table": {
        "AttributeDefinitions": [
            {
                "AttributeName": "name",
                "AttributeType": "S"
            },
            {
                "AttributeName": "version",
                "AttributeType": "S"
            }
        ],
        "TableName": "projects",
        "KeySchema": [
            {
                "AttributeName": "name",
                "KeyType": "HASH"
            },
            {
                "AttributeName": "version",
                "KeyType": "RANGE"
            }
        ],
        "TableStatus": "ACTIVE",
        "CreationDateTime": 1546603531.869,
        "ProvisionedThroughput": {
            "NumberOfDecreasesToday": 0,
            "ReadCapacityUnits": 0,
            "WriteCapacityUnits": 0
        },
        "TableSizeBytes": 104,
        "ItemCount": 4,
        "TableArn": "arn:aws:dynamodb:xxx",
        "TableId": "xxx"
    }
}

问题是,这种结构是否适合我的用例?我对如何实际构建项目(而非版本)特定元数据感到困惑。假设我有一个属性Project.IsAbandoned,该行将声明该项目已被放弃。由于version是排序键,因此我必须提出一个常量(比如说0),该常量应具有IsAbandoned之类的所有元数据,以便在迭代之前正确填充Project通过实际的Versions

0 个答案:

没有答案