pouchDB retrieve allDocs original query -
i attempting load local pouchdb results website. once results loaded locally, don't want bother downloading them again.
to avoid this, list of files exist, , test see if i've loaded in past before fetching it.
function downloadfile($fname){ $query = { include_docs: false, attachments: false, startkey: ['run',$fname].join(','), endkey: ['run',$fname,'\uffff'].join(',') }; db.alldocs($query).then(function (result) { if ( result.rows.length !== 0 ) return; $url = './rundb/' + $fname + '/results.xml'; $.ajax({ url: $url, type: "get", datatype: "xml", contenttype: "text/xml", async: true, success: function (results,status,xhr) { app.parseresults($fname,results) } }); }).catch(function (err) { console.log(err); }); }
the problem having time downloadfile
get's called 100 times , alldocs
query returns something, no longer know original query returned no results.
is there way in pouchdb determine query parameters used produce given result set?
edit: while accepted answer, appears dumb question. experimentation (in browser) indicates $query
, $fname
contain correctly scoped value particular call initiated alldocs
call.
in other words, don't need anything, works. obviously, highly dependant on js implementation, therefore accepted answer better because explicit desired.
this not related pouchdb, solution can used sorts of similar cases.
the answer below assumes have valid promise
object hanging around.
function downloadfile($fname){ $query = { include_docs: false, attachments: false, startkey: ['run',$fname].join(','), endkey: ['run',$fname,'\uffff'].join(',') }; return promise.all([ $query, db.alldocs($query), ]).then(function (resp) { // you'll have query right here. var $query = resp[0] var result = resp[1] if ( result.rows.length !== 0 ) return; $url = './rundb/' + $fname + '/results.xml'; $.ajax({ url: $url, type: "get", datatype: "xml", contenttype: "text/xml", async: true, success: function (results,status,xhr) { app.parseresults($fname,results) } }); }).catch(function (err) { console.log(err); }); }
Comments
Post a Comment