Permalink
Browse files

automatically adding the maxlimit to the query if nolimit is set

  • Loading branch information...
1 parent 0681b64 commit 33bbdb89f2642cb1f77b665d357e83c4bd8b58fd @tracend tracend committed May 29, 2013
Showing with 7 additions and 3 deletions.
  1. +7 −3 lib/simpledb.js
View
10 lib/simpledb.js
@@ -48,7 +48,6 @@ exports.expbackoff = function(fn,statuscb,maxtry,expbase,delaymin,delayscale,ran
delaymin = null == delaymin ? 0 : delaymin
delayscale = null == delayscale ? 100 : delayscale
randomdelay = null == randomdelay ? true : randomdelay
- maxlimit = 2500
function retry(tryI,last,delay) {
try {
@@ -120,6 +119,7 @@ exports.SimpleDB = function(opts,logger) {
// TODO - get aws-lib to support port
awsopts.port = null == opts.port ? 80 : opts.port
awsopts.nolimit = null == opts.nolimit ? false : opts.nolimit
+ awsopts.maxlimit= 2500 // this is set by the AWS service: http://docs.aws.amazon.com/AmazonSimpleDB/latest/DeveloperGuide/SDBLimits.html
var results = []
@@ -153,7 +153,8 @@ exports.SimpleDB = function(opts,logger) {
if( !err ) {
results = results.concat( res.SelectResult.Item )
- if( awsopts.nolimit && res.SelectResult.Item && ( res.SelectResult.Item.length == maxlimit ) && res.SelectResult.NextToken){
+ // optionally make subsequent requests for queries over the max limit
+ if( awsopts.nolimit && res.SelectResult.Item && ( res.SelectResult.Item.length == awsopts.maxlimit ) && res.SelectResult.NextToken){
// get the next batch of results
q.NextToken = res.SelectResult.NextToken
makereq(act,q,callback)
@@ -511,7 +512,10 @@ exports.SimpleDB = function(opts,logger) {
arg = arg.replace(/'/g,"''")
query = query.replace(/\?/,arg)
})
-
+ // automatically add the limit if nolimit option is selected
+ if( awsopts.nolimit && query.indexOf(" limit ") == -1){
+ query += " limit "+ awsopts.maxlimit;
+ }
var asarrays = getoverride(override).$AsArrays
var act = 'Select'
var q = {SelectExpression:query,ConsistentRead:''+opts.consistent}

0 comments on commit 33bbdb8

Please sign in to comment.