【问题标题】:Table not included in parent transaction - Dexie表未包含在父事务中 - Dexie
【发布时间】:2020-06-29 15:51:19
【问题描述】:

我已经编写了几个函数来使用 Dexie 包装器来操作 indexedDB 中的数据。这是更新方法:

updateRow(documentId, rowId, row) {
        this.db.transaction('rw', this.db.tableEntry, async () => {
            await this.db.tableEntry.where({
                documentId: documentId,
                rowId: rowId
            }).modify({row: row})
        }).catch(e => {
            console.log(e)
        });
    }

此功能按预期完美运行。以下功能在同一个类中以相同的方式实现:

getAllByDocumentId(documentId, callBack) {
        this.db.transaction('rw', this.db.tableEntry, async () => {
            await this.db.tableEntry.where({
                documentId: documentId,
            }).toArray((entries)=>callBack(entries))
        }).catch(e => {
            console.log(e)
        });
    }

执行这个方法会报错:

name: "SubTransactionError"
message: "Table tableEntry not included in parent transaction."

我该如何解决这个问题?错误背后的根本原因是什么?

【问题讨论】:

    标签: javascript reactjs indexeddb dexie


    【解决方案1】:

    我发现原因是,其他调用类执行多个包含事务的函数。因此,这些异步函数与它们的事务重叠。由于这个原因,只有第一个函数调用成功。我使用的简单方法是在调用时延迟函数的执行。

    update(...);
    setTimeout(getAllByDocumentId(...),200);
    setTimeout(otherDBFunction(...),300);
    

    然后它工作正常。

    【讨论】:

      猜你喜欢
      • 2021-01-04
      • 1970-01-01
      • 2013-06-27
      • 2017-07-09
      • 2019-06-17
      • 1970-01-01
      • 2016-12-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多