Skip to content

Instantly share code, notes, and snippets.

@Hmachalani
Created October 24, 2015 02:24
Show Gist options
  • Save Hmachalani/54cf258384d43ca295e0 to your computer and use it in GitHub Desktop.
Save Hmachalani/54cf258384d43ca295e0 to your computer and use it in GitHub Desktop.
Purchase Schema
var vogels = require('vogels'),
Joi = require('joi');
vogels.AWS.config.loadFromPath('./config.json');
var Purchase= vogels.define('Purchase', {
hashKey : 'uid',
rangeKey: 'tok',
// enable timestamps support
timestamps : true,
schema : {
uid : Joi.string().required(),
tok:Joi.string().required(),
rno: Joi.string(),
exp: Joi.date(),
pin: Joi.string(),
redURL:Joi.string(),
title: Joi.string().required(),
imgURL:Joi.string().required(),
sku:Joi.string().required(),
price:Joi.number().required(), //list price in USD?
oid:Joi.string().required(), //order_id
cost:Joi.number().required(), // cost to buy it in USD
info: Joi.object(), //all other data.
},
});
vogels.createTables({
'Purchase': {readCapacity: 5, writeCapacity: 5}, // note: doesn't support updating throughput
}, function (err) {
if(err) {
console.log('xxx - Error creating Purchase table', err);
} else {
console.log('...Purchase table is online');
}
});
Purchase.getPurchasesByUID=function(uid, cb)
{
Purchase.query(uid).select('tok, rno,exp').exec(cb);
}
module.exports=Purchase;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment