-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert objects to DynamoDB Maps for storage #92
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,9 @@ function valueToObject(value) { | |
return {N: String(value)} | ||
default: | ||
if (Array.isArray(value)) { | ||
if (value.length == 0) | ||
return {L: []} | ||
|
||
var firstItemType = typeof value[0] | ||
|
||
// check that all of the items are of the same type; that of the first element's | ||
|
@@ -108,9 +111,13 @@ function valueToObject(value) { | |
} | ||
|
||
return {NS: numArray} | ||
} else if (firstItemType === "object") { | ||
return {L: value.map(valueToObject)} | ||
} else { | ||
throw new Error('Invalid dynamo set value. Type: ' + firstItemType + ', Value: ' + value[0]) | ||
} | ||
} else if (typeof value == "object") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we move this condition to the top level switch? |
||
return {M: packObjectOrArray(value)} | ||
} else { | ||
// TODO(nick): I'm pretty sure this should be an error. But there is a bunch | ||
// of code relying on this behavior, so just log the error for now and | ||
|
@@ -139,7 +146,7 @@ function objectToType(obj) { | |
* Convert a Dynamo AttributeValue to a javascript primitive value | ||
* | ||
* @param {!AWSAttributeValue} obj | ||
* @return {string|number|Array.<string>|Array.<number>|boolean} a javascript primitive value | ||
* @return {string|number|Array.<string>|Array.<number>|boolean|Object} a javascript primitive value | ||
*/ | ||
function objectToValue(obj) { | ||
switch (objectToType(obj)) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ | |
"dependencies": { | ||
"kew": "0.7.0", | ||
"typ": "0.6.3", | ||
"aws-sdk": "2.2.47" | ||
"aws-sdk": "2.5.1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a reason here why we're updating the sdk? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apologies, but this is something I did 2 years ago while implementing something for a former client, and I don't honestly recall the context here. If this PR is useful to others I can try and setup something to test it with the previous aws-sdk and see what happens, but I cannot promise when I will have time to do so. Please consider this a response to all three of your questions. |
||
}, | ||
"devDependencies": { | ||
"closure-npc": "0.1.3", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are the implications here if the type of this list isn't of attributes?