Permalink
Browse files

removing empty string values before making put item request

  • Loading branch information...
Ryan Fitzgerald
Ryan Fitzgerald committed Apr 30, 2012
1 parent 0b19124 commit 470aa254435fb1bd47c1033488036b489516c2a0
Showing with 18 additions and 4 deletions.
  1. +1 −1 lib/dynode/client.js
  2. +2 −2 lib/dynode/types.js
  3. +1 −1 package.json
  4. +8 −0 test/integration/dynode-test.js
  5. +6 −0 test/unit/types-test.js
View
@@ -239,7 +239,7 @@ Client.prototype.truncate = function(tableName, options, cb) {
batchWrites.push(async.apply(self.batchWriteItem.bind(self), writes));
}
- async.parallel(batchWrites, cb);
+ async.series(batchWrites, cb);
});
});
};
View
@@ -6,7 +6,7 @@ exports.stringify = function(attrs) {
_.each(attrs, function(value, key) {
var attr = {};
- if(!_.isUndefined(value) && !_.isNull(value) && !isEmptyArray(value)) {
+ if(!_.isUndefined(value) && !_.isNull(value) && !isEmptyArray(value) && value != '') {
attr[typeIndicator(value)] = toString(value);
result[key] = attr;
}
@@ -94,7 +94,7 @@ function toString(value) {
};
function isEmptyArray(obj) {
- return _.isArray(obj) && _.isEmpty(obj);
+ return _.isArray(obj) && _.isEmpty(_.compact(obj));
};
function valueFromHash(obj) {
View
@@ -1,7 +1,7 @@
{
"name": "dynode",
"description": "node.js client for Amazon's DynamoDB",
- "version": "0.4.8",
+ "version": "0.4.9",
"author": "Ryan Fitzgerald <ryan@codebrewstudios.com>",
"repository": {
"type": "git",
@@ -46,6 +46,14 @@ describe('Dynode Integration Tests', function() {
done(err);
});
});
+
+ it('should create item without empty string attributes', function(done) {
+ dynode.putItem("TestTable", {id : "more", name :"", strings: [""] }, function(err, resp) {
+ should.not.exist(err);
+ console.log(resp);
+ done(err);
+ });
+ });
});
describe("Get Item", function() {
View
@@ -43,6 +43,12 @@ describe('Types', function() {
converted.should.eql({"foo":{"S":date.toJSON()}});
});
+ it("remove empty string values", function() {
+ var converted = Types.stringify({foo : "Bar", name : "", args : ['']});
+
+ converted.should.eql({"foo":{"S":"Bar"}});
+ });
+
});
describe("toKeys", function() {

0 comments on commit 470aa25

Please sign in to comment.