Convert Javascript objects / JSON files into DynamoDB record formatting. Facilitates putItem or batchWriteItem requests, including batch sizing. It also shows how to convert DynamoDB records into JS objects.
npm install dynamodb-converter
const ddbConverter = require('../dynamodb-converter')
const obj = {
userId: 1,
id: 1,
title: 'delectus aut autem',
completed: false
}
console.log(converted)
Output:
{
userId: {
N: '1'
},
id: {
N: '1'
},
title: {
S: 'delectus aut autem'
},
completed: {
BOOL: false
}
}
JavaScript object -> DyanmoDB record. Optional UUID (default=false).
.convert(object, uuid)
From:
{ userID: 1 }
To:
{
userId: {
N: '1'
}
}
DynamoDB record --> Javascript object.
.unconvert(object)
From:
{
userId: {
N: '1'
}
}
To:
{ userID: 1 }
JavaScript object -> DyanmoDB record BatchItemWrite. Optional UUID (default=false).
.convertArray(array, 'TABLE-NAME', uuid)
From:
[{ userID: 1, name: "Julia" }, {userID: 2, name: "Niko" }]
To:
{
RequestItems: {
"yourTableName": [
{
"PutRequest": {
"Item": {
"userID": {
"S": "1"
},
"name": {
"S": "Julia"
}
}
}
},
{
"PutRequest": {
"Item": {
"userID": {
"S": "2"
},
"name": {
"S": "Niko"
}
}
}
}
]
}
}
Creating array chunks to meet DyanmoDB 25 record insertion cap. batchSize defaults at 25, but can be customized.
.batch(array, batchSize)
Reading & Writing to Dynamo (with optional UUID)
- JS object --> DyanmoDB record (PutItem)
- DynamoDB record --> JS object
- BatchItemWrite from Array
- BatchItemWrite from File