ngx-indexed-db icon indicating copy to clipboard operation
ngx-indexed-db copied to clipboard

Create more than one database and add defered creation in service and not in Root Module

Open DadvDadv opened this issue 3 years ago • 7 comments

Discussed in https://github.com/assuncaocharles/ngx-indexed-db/discussions/294

Originally posted by DadvDadv January 12, 2022 Hi, I d'nt figure how to create more than one database (not table), i would like to create a database by domains :

db1-users logs files

db2-catalog logs files items

and so on

Thx


Improvements :

  • Create more than one database
  • Deferd the database creation in service and not in root module

Use case :

  • Create database by domain
  • Create database dynamicly base on other services

DadvDadv avatar Jan 12 '22 11:01 DadvDadv

Hi @assuncaocharles, deferd the database creation in service and not in root module is a breaking change?

aparzi avatar Jan 12 '22 12:01 aparzi

I don't think so, creating the db in root should be possible, and we should be able to add or update database in service if we need to.

Ex : in app.module.ts

NgxIndexedDBModule.forRoot({ name: 'catalog', version: 1, objectStoresMeta: [{ store: 'articles', storeConfig: { keyPath: 'id', autoIncrement: false }, storeSchema: [ { name: 'articleType_Id', keypath: 'articleType_Id', options: { unique: false } }, { name: 'timeStamp', keypath: '_ts', options: { unique: false } }, ]
}}

In my application , for some raison i need to create an other Database depending on the userName (for example) :

In users.service.ts

@Injectable({ providedIn: 'root' }) export class UsersService {

constructor( private authentificationService : AuthentificationService, private dbService: NgxIndexedDBService) { }

createHistoryLog(){

this.dbService.createDatabase({ //<= new method name: this.authentificationService.currentUser.uniqueId , //<= Dynamic Database Name version: 1, objectStoresMeta: [{ store: 'historyLogs', storeConfig: { keyPath: 'id', autoIncrement: false }, storeSchema: [
{ name: 'timeStamp', keypath: '_ts', options: { unique: false } }, ] } } } );

I know i can add an index UserName in my object store but it's not convenient for my use case.

The two implementations should be side by side, it's an improvment not a breaking change for me

DadvDadv avatar Jan 12 '22 12:01 DadvDadv

You should probably add the need to register the empty module :

before : NgxIndexedDBModule.forRoot(...)

after : NgxIndexedDBModule.forRoot(...) OR NgxIndexedDBModule -- (alone)

DadvDadv avatar Jan 12 '22 12:01 DadvDadv

Hi @DadvDadv, perfect, if so then yes. I understood you wanted more.

aparzi avatar Jan 12 '22 13:01 aparzi

Hi, I tried to just add the module NgxIndexedDBModule without forRoot in app module but I get No provider for NgxIndexedDBService.

Can you please help explain in details how can we defer database creation to service rather to be created starting from the AppModule?

SDAdham avatar Jan 29 '22 14:01 SDAdham

I think this is not done already, i was asking for add this in a futur release

DadvDadv avatar Apr 10 '22 21:04 DadvDadv

Hey everyone, yeah, this looks like a nice feature to be added. Definitely will come in the next versions, if anyone has some free time before I have feel free to take action on this one.

assuncaocharles avatar May 29 '22 00:05 assuncaocharles

Hi @assuncaocharles, this issue I think it can be closed, given that the possibility of having more databases has been offered

aparzi avatar Apr 02 '24 08:04 aparzi