Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

getItem: if item not found, res is null

  • Loading branch information...
commit 358ff1fbc81b22fae326de7f71e0e41c9c2cbc3e 1 parent 7af6821
Richard Rodger authored
Showing with 15 additions and 5 deletions.
  1. +8 −3 lib/simpledb.js
  2. +1 −1  package.json
  3. +6 −1 test/simpledb.test.js
11 lib/simpledb.js
View
@@ -77,7 +77,7 @@ exports.expbackoff = function(fn,statuscb,maxtry,expbase,delaymin,delayscale,ran
function arrayify(arrQ) {
- return Array.isArray(arrQ) ? arrQ : [arrQ]
+ return !!arrQ ? Array.isArray(arrQ) ? arrQ : [arrQ] : []
}
@@ -401,11 +401,16 @@ exports.SimpleDB = function(opts,logger) {
var q = {DomainName:domain,ItemName:itemname,ConsistentRead:''+opts.consistent}
applyoverride(q,override)
+
+ // res is null if not found
makereq(act,q,function(err,res,meta){
var out = null
if( !err ) {
- out = {$ItemName:itemname}
- getattrs(out,arrayify(res.GetAttributesResult.Attribute),asarrays)
+ attrs = arrayify(res.GetAttributesResult.Attribute)
+ if( 0 < attrs.length ) {
+ out = {$ItemName:itemname}
+ getattrs(out,attrs,asarrays)
+ }
}
callback(err,out,meta)
})
2  package.json
View
@@ -2,7 +2,7 @@
"name": "simpledb",
"description": "An Amazon AWS SimpleDB library for Node.js that is user-friendly and fault-tolerant",
"keywords": ['amazon','aws','simpledb','database','wrapper','api'],
- "version": "0.0.1",
+ "version": "0.0.2dev",
"homepage": "https://github.com/rjrodger/simpledb",
"author": "Richard Rodger <richard@ricebridge.com> (http://richardrodger.com/)",
"contributors": [
7 test/simpledb.test.js
View
@@ -217,6 +217,11 @@ module.exports = {
debugres(err,res,meta)
assert.isNull(err)
+ ;sdb.getItem('simpledbtest','not-an-item',function(err,res,meta){
+ debugres(err,res,meta)
+ assert.isNull(err)
+ assert.isNull(res)
+
;sdb.getItem('simpledbtest','item1',function(err,res,meta){
debugres(err,res,meta)
assert.isNull(err)
@@ -284,7 +289,7 @@ module.exports = {
debugres(err,res,meta)
assert.isNotNull(err)
- }) }) }) }) }) }) }) }) }) }) }) }) })
+ }) }) }) }) }) }) }) }) }) }) }) }) }) })
},
example: function() {
Please sign in to comment.
Something went wrong with that request. Please try again.