entity-schema-dynamodb
v0.0.0-development
Published
Manage DynamoDB from JSON API entity schemas
Downloads
2
Maintainers
Readme
entity-schema-dynamodb
entity-schema-dynamodb utilizes entitys-schema to wrap the DynamoDB class in the AWS SDK allowing you to easily manage DynamoDB tables from an entity schema.
Installation
yarn add entity-schema-dynamodb
or npm i --save entity-schema-dynamodb
Usage
Create/Delete a table
const { Table } = require('entity-schema-dynamodb');
const rawSchema = require('./schema/person.json');
const personTable = new Table(
// table name
'person',
// raw schema json
rawSchema,
// configuration
{
// The sort key is also called a "RANGE" key by the AWS API. It makes up the
// primary key on your table in combination with the "HASH" key which will
// always be "id" in your entity schema.
sortKey: 'age',
// Configuration for entity-schema.
schemaConfig: { deref: { baseFolder: "./schema" } },
// AWS configuration. Unless overridden here, AWS will use your active AWS
// CLI credentials profile.
awsConfig: { region: 'us-east-2' }
}
);
// Create a table.
personTable.create()
.then((res) => {
// Congratulations! You created a table. The "res" variable is the same
// object as would be returned by the AWS SDK.
})
.catch((err) => {
// catch any error returned by the AWS SDK.
});
// Delete a table.
personTable.delete()
.then((res) => {
// Whoa there! Hope you knew what you were doing because you just deleted a
// table. The "res" variable is the same object as would be returned by the
// AWS SDK.
})
.catch((err) => {
// catch any error returned by the AWS SDK.
});