如何基于Dynamose Schema从NoSQL Workbench获取DynamoDB数据模型?

问题描述 投票:0回答:1

我正在使用 Dynamose 库方法并自动生成具有当前架构的数据库表,但是我无法在 AWS 中创建 DynamoDB 数据模型,我验证了可视化工具,该表不存在,我想知道是否可以获取数据模型或仅定义何时连接。

这是架构:

import { Schema } from 'dynamoose';

export const NotificationSchema = new Schema({
  id: {
    type: String,
    hashKey: true,
  },
  targetId: {
    type: String,
    index: {
      type: 'global',
      rangeKey: 'status',
    },
  },
  userId: {
    type: String,
    index: {
      type: 'global',
      rangeKey: 'status',
    },
  },
  content: {
    type: String,
  },
  status: {
    type: String,
  },
  createAt: {
    type: String,
  },
});

这是工作台中的元数据:

但元数据未显示

content
属性。

{
  "AttributeDefinitions": [
    {
      "AttributeName": "id",
      "AttributeType": "S"
    },
    {
      "AttributeName": "targetId",
      "AttributeType": "S"
    },
    {
      "AttributeName": "userId",
      "AttributeType": "S"
    },
    {
      "AttributeName": "status",
      "AttributeType": "S"
    }
  ],
  "TableName": "aws-nestjs-starter-dev-notification-table",
  "KeySchema": [
    {
      "AttributeName": "id",
      "KeyType": "HASH"
    }
  ],
  "TableStatus": "ACTIVE",
  "CreationDateTime": {},
  "ProvisionedThroughput": {
    "LastIncreaseDateTime": {},
    "LastDecreaseDateTime": {},
    "NumberOfDecreasesToday": 0,
    "ReadCapacityUnits": 1,
    "WriteCapacityUnits": 1
  },
  "TableSizeBytes": 381,
  "ItemCount": 4,
  "TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/aws-nestjs-starter-dev-notification-table",
  "GlobalSecondaryIndexes": [
    {
      "IndexName": "targetIdGlobalIndex",
      "KeySchema": [
        {
          "AttributeName": "targetId",
          "KeyType": "HASH"
        },
        {
          "AttributeName": "status",
          "KeyType": "RANGE"
        }
      ],
      "Projection": {
        "ProjectionType": "ALL"
      },
      "IndexStatus": "ACTIVE",
      "ProvisionedThroughput": {
        "ReadCapacityUnits": 1,
        "WriteCapacityUnits": 1
      },
      "IndexSizeBytes": 378,
      "ItemCount": 3,
      "IndexArn": "arn:aws:dynamodb:ddblocal:000000000000:table/aws-nestjs-starter-dev-notification-table/index/targetIdGlobalIndex"
    },
    {
      "IndexName": "userIdGlobalIndex",
      "KeySchema": [
        {
          "AttributeName": "userId",
          "KeyType": "HASH"
        },
        {
          "AttributeName": "status",
          "KeyType": "RANGE"
        }
      ],
      "Projection": {
        "ProjectionType": "ALL"
      },
      "IndexStatus": "ACTIVE",
      "ProvisionedThroughput": {
        "ReadCapacityUnits": 1,
        "WriteCapacityUnits": 1
      },
      "IndexSizeBytes": 378,
      "ItemCount": 3,
      "IndexArn": "arn:aws:dynamodb:ddblocal:000000000000:table/aws-nestjs-starter-dev-notification-table/index/userIdGlobalIndex"
    }
  ]
}

我需要在可视化工具上验证此表或获取 json 导出,我使用命令创建了一个音乐表,并且可以在可视化工具中看到,我想要这种格式:

{
  "ModelName": "Music Library Data Model",
  "ModelMetadata": {
    "Author": "Amazon Web Services, Inc.",
    "DateCreated": "Sep 05, 2019, 11:50 AM",
    "DateLastModified": "Jun 30, 2023, 02:19 AM",
    "Description": "This data model represents an Amazon DynamoDB schema for a music library application ",
    "Version": "3.0",
    "AWSService": "Amazon DynamoDB"
  },
  "DataModel": [
    {
      "TableName": "Songs",
      "KeyAttributes": {
        "PartitionKey": {
          "AttributeName": "Id",
          "AttributeType": "S"
        },
        "SortKey": {
          "AttributeName": "Metadata",
          "AttributeType": "S"
        }
      },
      "NonKeyAttributes": [
        {
          "AttributeName": "DownloadMonth",
          "AttributeType": "S"
        },
        {
          "AttributeName": "TotalDownloadsInMonth",
          "AttributeType": "S"
        },
        {
          "AttributeName": "Title",
          "AttributeType": "S"
        },
        {
          "AttributeName": "Artist",
          "AttributeType": "S"
        },
        {
          "AttributeName": "TotalDownloads",
          "AttributeType": "S"
        },
        {
          "AttributeName": "DownloadTimestamp",
          "AttributeType": "S"
        }
      ],
      "TableFacets": [
        {
          "FacetName": "SongDetails",
          "KeyAttributeAlias": {
            "PartitionKeyAlias": "SongId",
            "SortKeyAlias": "Metadata"
          },
          "NonKeyAttributes": [
            "Title",
            "Artist",
            "TotalDownloads"
          ],
          "TableData": [
            {
              "Id": {
                "S": "1"
              },
              "Metadata": {
                "S": "Details"
              },
              "Title": {
                "S": "Wild Love"
              },
              "Artist": {
                "S": "Argyboots"
              },
              "TotalDownloads": {
                "S": "3"
              }
            },
            {
              "Id": {
                "S": "2"
              },
              "Metadata": {
                "S": "Details"
              },
              "Title": {
                "S": "Example Song Title"
              },
              "Artist": {
                "S": "Jorge Souza"
              },
              "TotalDownloads": {
                "S": "4"
              }
            }
          ],
          "DataAccess": {
            "MySql": {}
          }
        },
        {
          "FacetName": "Downloads",
          "KeyAttributeAlias": {
            "PartitionKeyAlias": "SongId",
            "SortKeyAlias": "Metadata"
          },
          "NonKeyAttributes": [
            "DownloadTimestamp"
          ],
          "TableData": [
            {
              "Id": {
                "S": "1"
              },
              "Metadata": {
                "S": "Dld-9349823681"
              },
              "DownloadTimestamp": {
                "S": "2018-01-01T00:00:07"
              }
            },
            {
              "Id": {
                "S": "1"
              },
              "Metadata": {
                "S": "Dld-9349823682"
              },
              "DownloadTimestamp": {
                "S": "2018-01-01T00:01:08"
              }
            },
            {
              "Id": {
                "S": "1"
              },
              "Metadata": {
                "S": "Dld-9349823683"
              },
              "DownloadTimestamp": {
                "S": "2018-01-01T00:20:10"
              }
            },
            {
              "Id": {
                "S": "2"
              },
              "Metadata": {
                "S": "Dld-9349823684"
              },
              "DownloadTimestamp": {
                "S": "2018-01-02T00:00:00"
              }
            },
            {
              "Id": {
                "S": "2"
              },
              "Metadata": {
                "S": "Dld-9349823685"
              },
              "DownloadTimestamp": {
                "S": "2018-01-03T00:00:02"
              }
            },
            {
              "Id": {
                "S": "2"
              },
              "Metadata": {
                "S": "Dld-9349836234"
              },
              "DownloadTimestamp": {
                "S": "2018-01-04T01:00:03"
              }
            },
            {
              "Id": {
                "S": "2"
              },
              "Metadata": {
                "S": "Dld-9349823686"
              },
              "DownloadTimestamp": {
                "S": "2018-01-05T01:10:03"
              }
            }
          ],
          "DataAccess": {
            "MySql": {}
          }
        }
      ],
      "LocalSecondaryIndexes": [],
      "GlobalSecondaryIndexes": [
        {
          "IndexName": "DownloadsByMonth",
          "KeyAttributes": {
            "PartitionKey": {
              "AttributeName": "DownloadMonth",
              "AttributeType": "S"
            },
            "SortKey": {
              "AttributeName": "TotalDownloadsInMonth",
              "AttributeType": "S"
            }
          },
          "Projection": {
            "ProjectionType": "ALL"
          }
        }
      ],
      "TableData": [
        {
          "Id": {
            "S": "1"
          },
          "Metadata": {
            "S": "Month-01-2018"
          },
          "DownloadMonth": {
            "S": "01-2018"
          },
          "TotalDownloadsInMonth": {
            "S": "3"
          }
        },
        {
          "Id": {
            "S": "2"
          },
          "Metadata": {
            "S": "Month-01-2018"
          },
          "DownloadMonth": {
            "S": "01-2018"
          },
          "TotalDownloadsInMonth": {
            "S": "4"
          }
        }
      ],
      "DataAccess": {
        "MySql": {}
      },
      "BillingMode": "PROVISIONED",
      "ProvisionedCapacitySettings": {
        "ProvisionedThroughput": {
          "ReadCapacityUnits": 5,
          "WriteCapacityUnits": 5
        },
        "AutoScalingRead": {
          "ScalableTargetRequest": {
            "MinCapacity": 1,
            "MaxCapacity": 10,
            "ServiceRole": "AWSServiceRoleForApplicationAutoScaling_DynamoDBTable"
          },
          "ScalingPolicyConfiguration": {
            "TargetValue": 70
          }
        },
        "AutoScalingWrite": {
          "ScalableTargetRequest": {
            "MinCapacity": 1,
            "MaxCapacity": 10,
            "ServiceRole": "AWSServiceRoleForApplicationAutoScaling_DynamoDBTable"
          },
          "ScalingPolicyConfiguration": {
            "TargetValue": 70
          }
        }
      }
    }
  ]
}

使用以下命令我得到这个:

λ aws dynamodb describe-table --table-name aws-nestjs-starter-dev-notification-table --endpoint-url http://localhost:8000

{
    "Table": {
        "AttributeDefinitions": [
            {
                "AttributeName": "id",
                "AttributeType": "S"
            },
            {
                "AttributeName": "targetId",
                "AttributeType": "S"
            },
            {
                "AttributeName": "userId",
                "AttributeType": "S"
            },
            {
                "AttributeName": "status",
                "AttributeType": "S"
            }
        ],
        "TableName": "aws-nestjs-starter-dev-notification-table",
        "KeySchema": [
            {
                "AttributeName": "id",
                "KeyType": "HASH"
            }
        ],

缺少内容属性。

amazon-web-services amazon-dynamodb datamodel dynamoose
1个回答
0
投票

Dynamoose 存储整个架构,并使用架构到对象映射。 DynamoDB 是一种无服务器服务,忽略非关键属性。

您最关心的是

content
不是您官方 DynamoDB 架构的一部分,因此,它是一个非关键属性。

© www.soinside.com 2019 - 2024. All rights reserved.