clarkie / dynogels

DynamoDB data mapper for node.js. Originally forked from https://github.com/ryanfitz/vogels
Other
490 stars 110 forks source link

Trying to scan #105

Closed sp90 closed 6 years ago

sp90 commented 7 years ago

Okay so i want to query by some values

Messages
  .scan()
  .startKey(lastKey)
  .limit(10)
  .where('message_subject_internal').contains(query)
  .exec(callback);

Lets say query is empty shouldn't the framework just not add the filter query that way i dont have to do all the cases in my route

Otherwise i can end up with some serious spagetti code?

cdhowie commented 6 years ago

You shouldn't need spaghetti code...

let scan = Messages
  .scan()
  .startKey(lastKey)
  .limit(10);

if (query && query.length) {
  scan = scan.where('message_subject_internal').contains(query);
}

scan.exec(callback);

This seems perfectly readable to me, and is a fairly standard way to conditionally build queries/scans.

sp90 commented 6 years ago

Thanks 👍