Skip to content

Commit

Permalink
Merge pull request #1171 from pulsar-edit/expose-database-dbPromise-m…
Browse files Browse the repository at this point in the history
…ethod

[core] Expose `dbPromise` in `StateStore`
  • Loading branch information
confused-Techie authored Dec 30, 2024
2 parents a5fccfc + 4788055 commit e46ba9a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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

0 comments on commit e46ba9a

Please sign in to comment.