我有一个IndexedDB表,它接受以下结构化JSON作为行:
{ id : 1, name : 'doc1', createdDate : '2018-08-08' }
我想在表中得到每个可用日期的计数。即:groupby:date then count。预期的示例输出格式为:
{ '2018-08-08' : 5, '2018-08-18' : 19, ... }
表中包含大量的记录。那么,如何使用Dexie高效地实现这一要求呢?
yrefmtwq1#
如果为createdDate编制索引,
const db = new Dexie("yourDB"); db.version(1).stores({ yourTable: "id, name, createdDate" });
然后,您可以执行以下操作:
const result = {} await db.yourTable.orderBy('createdDate').eachKey(date => { result[date] = (result[date] || 0) + 1; });
1条答案
按热度按时间yrefmtwq1#
如果为createdDate编制索引,
然后,您可以执行以下操作: