-
-
Save ryanfitz/627e91f3562a8c2c97a8 to your computer and use it in GitHub Desktop.
Purchase Schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
.expressionAttributeNames({ '#t' : 'tok', '#r' : 'rno', '#e' : 'exp'}) | |
.projectionExpression('#t, #r, #e') | |
.exec(cb); | |
} | |
module.exports=Purchase; |
I wanted to show you how to use expressionAttributeNames. With this now you can use attribute names such as 'token'. The reserved words list, which DynamoDB introduced relatively recently, has around 1000 words and matches many common attribute names.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting, why not use:
Purchase
.query(uid)
.attributes(['uid','tok', 'rno', 'exp', 'pin', 'redURL', 'title', 'imgURL', 'sku', 'price', 'oid'])
.exec(cb);