我有一个索引数据库下表接受以下结构化 JSON 作为一行:
{
id : 1,
name : 'doc1',
createdDate : '2018-08-08'
}
我想计算表中每个可用日期的数量。 IE:groupby:日期然后计数。预期示例输出的格式为:
{
'2018-08-08' : 5,
'2018-08-18' : 19,
...
}
表包含大量记录。那么,如何使用Dexie高效地实现这一需求呢?
如果您索引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;
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)