我正在尝试将以下内容优化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
) 或开始 ( ) (或两者) 的预订。arrival
from
to