1

我正在尝试将以下内容优化scans为单个scan(或query)。我看到的唯一方法是使用 DynamoDB使用OR比较器。我在我的应用程序中使用dynogels(fork of 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) 或开始 ( ) (或两者) 的预订。arrivalfromto

4

1 回答 1

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(或)只是想获得结果而不管whereor filterexpression

于 2017-04-24T13:28:45.357 回答