Fix for: boolean values converted to strings instead of numbers #20

Open
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+9 −3
Diff settings

Always

Just for now

View
@@ -27,7 +27,7 @@ exports.parse = function(attrs) {
// Convert to DynamoDB keys
exports.toKeys = function(keys) {
- if(_.isNumber(keys) || _.isString(keys)) {
+ if(_.isNumber(keys) || _.isBoolean(keys) || _.isString(keys)) {
return exports.stringify({"HashKeyElement" : keys});
} else if (keys.hash) {
return exports.stringify({"HashKeyElement" : keys.hash, "RangeKeyElement" : keys.range});
@@ -75,14 +75,14 @@ function typeIndicator(value) {
if(_.isArray(value)) {
return typeIndicator(_.first(value))+ "S";
} else {
- return _.isNumber(value) ? "N" : "S";
+ return _.isNumber(value) || _.isBoolean(value) ? "N" : "S";
}
};
function toString(value) {
if(_.isArray(value)) {
return value.map(toString);
- } else if(_.isNumber(value)) {
+ } else if(_.isNumber(value) || _.isBoolean(value)) {
return Number(value).toString();
} else if (value.toJSON) {
return value.toJSON();
View
@@ -18,6 +18,12 @@ describe('Types', function() {
converted.should.eql({"foo":{"N":"123"}});
});
+ it("converts boolean attribute", function() {
+ var converted = Types.stringify({foo : true});
+
+ converted.should.eql({"foo":{"N":"1"}});
+ });
+
it("converts string array", function() {
var converted = Types.stringify({foo : ["a", "b", "c"]});