Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDB version error #57

Closed
academy-services opened this issue Jun 18, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@academy-services
Copy link

commented Jun 18, 2018

Hi again

After modifying the schema of an IDB database a few times I get a connection error:
DOMException: The requested version (1) is less than the existing version (24).

In the docs, I can't see a way to specify the version?

Is there an ability to do so, or can it be included?

ta!

@ClickSimply

This comment has been minimized.

Copy link
Owner

commented Jul 3, 2018

This should be taken care of automatically for you, here's the relevant code in the IndexedDB adapter:

let version = parseInt(localStorage.getItem(this._id + "-idb-version") || "") || 1;
const modelHash = localStorage.getItem(this._id + "-idb-hash") || this._modelHash;

if (modelHash !== this._modelHash) {
    version++;
}

localStorage.setItem(this._id + "-idb-version", String(version));
localStorage.setItem(this._id + "-idb-hash", this._modelHash);
indexedDB.open(this._id, version)

Basically the indexedDB version is stored in localStorage, then when the data model is updated the version is incremented. What happened in your case is likely a result of localStorage getting cleared out but not IndexedDB.

In any case, there's a new optional config property: idbVersion. If you pass it in the automatic code will be ignored and your manually provided version number will be used instead.

Update is live on NPM in v1.7.0.

@ClickSimply ClickSimply added the bug label Jul 3, 2018

@academy-services

This comment has been minimized.

Copy link
Author

commented Jul 4, 2018

Our company's group policy wipes cookies and localstorage after each session, hence the issue.

I implemented a workaround by checking for a connection outside of NanoSQL and incrementing the version number until we get a hit.

Thanks for the response. Loving NanoSQL!

@ClickSimply

This comment has been minimized.

Copy link
Owner

commented Jul 4, 2018

Perfect, marking this one resolved!

@ClickSimply ClickSimply closed this Jul 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.