indexedDB setVersion 请求被阻止?

发布于 2024-12-20 04:13:17 字数 990 浏览 3 评论 0原文

我正在尝试将 indexedDB 与 jax webGL 框架 一起使用,但由于某种原因 setVersion 不起作用。

这是相关的 CoffeeScript

if @indexedDB and @objectStore and @key
  idb_request = indexedDB.open @indexedDB
  idb_request.onsuccess = (e) =>
    idb = e.target.result

    if idb.objectStoreNames.contains @objectStore
      store = idb.transaction([@objectStore], IDBTransaction.READ_WRITE).objectStore(@objectStore)

    else

      console.log idb.version # => ""

      version_request = idb.setVersion(0.1)
      version_request.onblocked = (e) -> console.log e #=> this one fires
      version_request.onerror = (e) -> console.log e
      version_request.onsuccess = (e) -> console.log e
      version_request.onfailure = (e) -> console.log e

  idb_request.onerror = (e) -> console.log "ERROR: Unable to open indexedDB"

...

附加到触发的版本请求的唯一处理程序是 onblocked,但我什至不确定请求被阻止意味着什么或为什么会发生这种情况......

为什么版本请求会被阻止?

I'm trying to use indexedDB with jax webGL framework but for some reason setVersion isn't working.

Here's the relevant coffeescript

if @indexedDB and @objectStore and @key
  idb_request = indexedDB.open @indexedDB
  idb_request.onsuccess = (e) =>
    idb = e.target.result

    if idb.objectStoreNames.contains @objectStore
      store = idb.transaction([@objectStore], IDBTransaction.READ_WRITE).objectStore(@objectStore)

    else

      console.log idb.version # => ""

      version_request = idb.setVersion(0.1)
      version_request.onblocked = (e) -> console.log e #=> this one fires
      version_request.onerror = (e) -> console.log e
      version_request.onsuccess = (e) -> console.log e
      version_request.onfailure = (e) -> console.log e

  idb_request.onerror = (e) -> console.log "ERROR: Unable to open indexedDB"

...

The only handler attached to the version request that fires is onblocked, But i'm not even sure what it means for the request to be blocked or why this would happen...

Why would a version request be blocked?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

行雁书 2024-12-27 04:13:17

根据 IndexedDB 规范,如果在发出版本更改请求时数据库连接仍处于打开状态,则可能会发送 blocked 事件。请参阅:http://www.w3.org/TR/IndexedDB/#version_change -transaction-steps

这是规范中的文本:

3。如果异步运行并且 openDatabases 中的任何连接仍未关闭,请对请求的阻塞事件进行排队。

FWIW:我无法在 Jax 中重现此问题;我知道最好不要说这是不可能的,但目前看起来不太可能是框架中的错误。对应的Jax问题是:https://github.com/sinisterchipmunk/jax/issues/37

According to the IndexedDB spec it's possible a blocked event might be sent if a database connection is still open while a version change request is made. See: http://www.w3.org/TR/IndexedDB/#version_change-transaction-steps

Here's the text from the spec:

3. If running asynchronously and any of the connections in openDatabases are still not closed, queue up a blocked event for the request.

FWIW: I couldn't reproduce this issue in Jax; I know better than to say it isn't possible, but it's looking unlikely to be a bug in the framework at this time. The corresponding Jax issue is: https://github.com/sinisterchipmunk/jax/issues/37

我不吻晚风 2024-12-27 04:13:17

以下是使用 IndexedDB 进行开发时保持数据库连接打开的两种常见方法:

1) 打开多个选项卡。

2)不小心打开数据库两次。

Here are two common ways to leave a database connection open when developing with IndexedDB:

1) Have multiple tabs open.

2) Accidentally open the database twice.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文