Skip to content

Commit

Permalink
fix: db cannot be created twice with the same name which crashes demos (
Browse files Browse the repository at this point in the history
  • Loading branch information
elribonazo committed Apr 25, 2024
1 parent 459e3e7 commit 5686474
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/pluto/rxdb/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Model } from '../models';
import { RxDBEncryptedMigrationPlugin } from '../migration';
import { Domain } from '../..';
import { RxDBUpdatePlugin } from 'rxdb/plugins/update';

export class RxdbStore implements Pluto.Store {
private _db?: RxDatabase<CollectionsOfDatabase, any, any>;

Expand All @@ -33,12 +34,14 @@ export class RxdbStore implements Pluto.Store {
* Start the database and build collections
*/
async start(): Promise<void> {
this._db = await createRxDatabase({
...this.options,
multiInstance: true
});
const collections = makeCollections(this.collections ?? {});
await this._db.addCollections(collections);
if (!this._db) {
this._db = await createRxDatabase({
...this.options,
multiInstance: true
});
const collections = makeCollections(this.collections ?? {});
await this._db.addCollections(collections);
}
}

async update<T extends Domain.Pluto.Storable>(name: string, model: T): Promise<void> {
Expand Down

0 comments on commit 5686474

Please sign in to comment.