Skip to content
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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/dynode/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions test/unit/types-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]});

Expand Down