Skip to content
This repository has been archived by the owner on Feb 13, 2021. It is now read-only.

Address open requests as well #1

Open
inexorabletash opened this issue Sep 25, 2015 · 2 comments
Open

Address open requests as well #1

inexorabletash opened this issue Sep 25, 2015 · 2 comments

Comments

@inexorabletash
Copy link
Owner

Implicitly, the proposal allows for:

let connection = await indexedDB.open('db').ready;

But that doesn't handle initial opens/upgrades, where you need to watch the upgradeneeded event on the request.

As a follow-on, we could do this:

interface IDBFactory {
  IDBOpenDBRequest open(DOMString name, [EnforceRange] optional unsigned long long version);
  IDBOpenDBRequest open(DOMString name, IDBOpenOptions options); // new overload!
  ...
}

dictionary IDBOpenOptions {
  optional unsigned long long version;
  optional UpgradeCallback upgrade;
};

callback UpgradeCallback = void (IDBDatabase connection,
                                 IDBTransaction transaction,
                                 unsigned long long oldVersion,
                                 unsigned long long newVersion);

So you'd write:

let connection = await indexedDB.open('db', {
  version: 2,
  upgrade: (db, tx, oldVersion, newVersion) => {
    if (oldVersion < 1) { ... }
    if (newVersion < 2) { ... }
  }}).ready;
@jakearchibald
Copy link

Strongly agree with having upgrade as part of the options object - much easier to reason-about as they say.

@inexorabletash
Copy link
Owner Author

Note that if we don't do this, developers would need to write:

let request = indexedDB.open('db', 2);
request.onupgradeneeded = (e) => {
  if (e.oldVersion < 1) { ... }
  if (e.oldVersion < 2) { ... }
};
let connection = await request.ready;

... which is not the end of the world, but it makes sense to pursue the event-less approach as well. I guess if you supply the upgrade callback we call it in addition to events, with the same semantics? (exception -> abort, etc)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants