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

[core] Expose dbPromise in StateStore #1171

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions spec/state-store-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ describe('StateStore', () => {
});
});

it('returns a database instance via dbPromise', async () => {
const store = new StateStore(databaseName, version);
const instance = await store.dbPromise;
expect(instance instanceof IDBDatabase).toBe(true);
});

describe('when there is an error reading from the database', () => {
it('rejects the promise returned by load', () => {
const store = new StateStore(databaseName, version);
Expand Down Expand Up @@ -119,5 +125,12 @@ describe('StateStore', () => {
expect(count).toBe(0);
});
});

it('returns a database instance via dbPromise', async () => {
const store = new StateStore(databaseName, version);
const instance = await store.dbPromise;
const Database = require("better-sqlite3");
expect(instance instanceof Database).toBe(true);
});
});
});
5 changes: 5 additions & 0 deletions src/state-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ module.exports = class StateStore {
return this._getCorrectImplementation().then(i => i.count());
}

get dbPromise() {
// Exposed due to usage in [`project-plus`](https://web.pulsar-edit.dev/packages/project-plus)
return this._getCorrectImplementation().then(i => i.dbPromise);
}

_getCorrectImplementation() {
return awaitForAtomGlobal().then(() => {
if(atom.config.get('core.useLegacySessionStore')) {
Expand Down
Loading