Closed csi-lk closed 8 years ago
Hi there, sorry if this is a silly question but i'm looking for a solution to do if statements on query function chains, I currently have it like this:
if(paginateKey){ Post.query(hashKey) .descending() .limit(10) .startKey(parseInt(paginateKey)) .exec(fn); } else { Post.query(hashKey) .descending() .limit(10) .exec(fn); }
Wondering if theres some sort of way to simplify it to something like:
Post.query(hashKey) .descending() .limit(10) paginateKey ? .startKey(parseInt(paginateKey)) : () .exec(fn);
My use case is a lot more complex than this, just put together the above as a simplistic example
Thanks :)
Figured it out by doing
var query = Post.query(hashKey).descending().limit(10) if(paginateKey) { query.startKey(paginateKey) } query.exec();
Happy to close this cheers
Hi there, sorry if this is a silly question but i'm looking for a solution to do if statements on query function chains, I currently have it like this:
Wondering if theres some sort of way to simplify it to something like:
My use case is a lot more complex than this, just put together the above as a simplistic example
Thanks :)