IndexedDB getAll() 排序

IndexedDB getAll() ordering

我正在使用 getAll() 方法从数据库中获取所有项目。

db.transaction('history', 'readonly').objectStore('history').getAll().onsuccess = ...

我的ObjectStore定义为:

db.createObjectStore('history', { keyPath: 'id', autoIncrement: true });

我可以指望我得到的物品的顺序吗?它们总是按主键排序吗id
(或者有明确指定排序的方法吗?)

我在官方找不到任何关于订购的信息docs

如果文档没有帮助,请查阅规范:

  1. getAll指的是"steps for retrieving multiple referenced values"
  2. the retrieval steps参考"first count records in index"
  3. the specification of index 包含以下段落:

    The records in an index are always sorted according to the record's key. However unlike object stores, a given index can contain multiple records with the same key. Such records are additionally sorted according to the index's record's value (meaning the key of the record in the referenced object store).

倒读:索引已排序。 getAll 检索索引的前 N ​​个,即它是 order-preserving。因此结果本身应该保留排序顺序。