Skip to content

Instantly share code, notes, and snippets.

@RodH257
Created April 10, 2016 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RodH257/5cdb9670f65ba115707fa89f1168b98a to your computer and use it in GitHub Desktop.
Save RodH257/5cdb9670f65ba115707fa89f1168b98a to your computer and use it in GitHub Desktop.
Demonstration of Vogels issue saving dates inside objects inside arrays
const vogels = require('vogels');
const Joi = require('joi');
const AWS = require('aws-sdk');
// setup Vogels
vogels.log.level('debug');
vogels.AWS.config.update({
region: 'us-west-1',
});
AWS.config.update({
region: 'us-west-1',
});
const driver = new AWS.DynamoDB();
vogels.dynamoDriver(driver);
function insertByBothMethods() {
console.log('Inserting test data....');
// -- Perform Test
const docClient = new AWS.DynamoDB.DocumentClient();
const params = {
TableName: 'testcases',
Item: {
id: 'standard insert',
content: {
payments: {
manual_entries: [{
id: 'vogels',
date: '2015-02-01T00:00:00.000Z',
}],
},
},
},
};
console.log('Adding via AWS');
docClient.put(params, (err) => {
if (err) {
console.log(err);
} else {
console.log('done');
}
});
const TestCase = vogels.define('TestCase', {
hashKey: 'id',
timestamps: false,
schema: {
id: Joi.string(),
content: {
payments: {
manual_entries: Joi.array().items({
id: Joi.string().allow(null),
date: Joi.date(),
}),
},
},
},
});
console.log('Adding via Voels');
TestCase.create({
id: 'vogels insert',
content: {
payments: {
manual_entries: [{
id: 'vogels',
date: '2015-02-01T00:00:00.000Z',
}],
},
},
}, (err) => {
if (err) {
console.log(err);
} else {
console.log('done');
}
});
}
// -- Create Table
const tableParams = {
TableName: 'testcases',
KeySchema: [{
AttributeName: 'id',
KeyType: 'HASH',
}],
AttributeDefinitions: [{
AttributeName: 'id',
AttributeType: 'S',
}],
ProvisionedThroughput: {
ReadCapacityUnits: 5,
WriteCapacityUnits: 10,
},
};
console.log('setting up table for test...');
driver.createTable(tableParams, (err, data) => {
if (err) {
console.error('Unable to create table. Error JSON:', JSON.stringify(err, null, 2));
} else {
console.log('Created table. Table description JSON:', JSON.stringify(data, null, 2));
setTimeout(insertByBothMethods, 1000);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment