Dynogels:使用OR比较查询

时间:2017-04-23 11:38:27

标签: javascript node.js amazon-dynamodb vogels dynogels

我正在尝试将以下mapObj.addListener('dragend', function () { var idleListener = mapObj.addListener('idle', function () { google.maps.event.removeListener(idleListener); console.log(mapObj.getCenter().lat()); console.log(mapObj.getCenter().lng()); }); }); 优化为单个scans(或scan)。我看到的唯一方法是使用use a OR comparator using DynamoDB。我在我的应用程序中使用querydynogels的分叉),但遗憾的是我不知道其中有任何vogels查询功能。



OR




建议的优化:



let arrivals = yield Reservation.scan()
  .where('room').equals(room)
  .where('arrival').between(from, to)
  .execAsync().then((reply) => reply.Items.map((item) => item.get()));

let departures = yield Reservation.scan()
  .where('room').equals(room)
  .where('departure').between(from, to)
  .execAsync().then((reply) => reply.Items.map((item) => item.get()));

let combined = arrivals.concat(departures);
return Promise.resolve(combined);




扫描系统会在指定的日期范围(return Reservation.scan() .where('room').equals(room) .where('arrival').between(from, to) .or.where('departure').between(from, to) .execAsync().then((reply) => reply.Items.map((item) => item.get()));departure)内获得结束(arrival)或开始(from)(或两者)的预订。

1 个答案:

答案 0 :(得分:3)

我认为可以使用filterexpression来实现。

使用filterexpression的示例代码: -

const scanItem = Reservation.scan().filterExpression('room = :idVal AND ((arrival BETWEEN :arrDateVal1 AND :arrDateVal2) OR (departure BETWEEN :depDateVal1 AND :depDateVal2)) ')
                .expressionAttributeValues({ ':idVal' : '2', ':arrDateVal1' : '21-APR-2017', ':arrDateVal2' : '23-APR-2017'
            ,':depDateVal1' : '21-APR-2017', ':depDateVal2' : '23-APR-2017'});                

scanItem.exec((err, result) => {if(!err) {console.log(JSON.stringify(result,undefined, 2))}});

注意: -

不确定是否要专门使用where而不是filterexpression(或)只是想要实现结果,而不管wherefilterexpression