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
Closed

IDB version error #57

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

Comments

@academy-services
Copy link

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!

@only-cliches
Copy link
Owner

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.

@academy-services
Copy link
Author

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!

@only-cliches
Copy link
Owner

Perfect, marking this one resolved!

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

No branches or pull requests

2 participants