ngx-indexed-db
ngx-indexed-db copied to clipboard
Create more than one database and add defered creation in service and not in Root Module
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
Hi @assuncaocharles, deferd the database creation in service and not in root module is a breaking change?
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
You should probably add the need to register the empty module :
before : NgxIndexedDBModule.forRoot(...)
after : NgxIndexedDBModule.forRoot(...) OR NgxIndexedDBModule -- (alone)
Hi @DadvDadv, perfect, if so then yes. I understood you wanted more.
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
?
I think this is not done already, i was asking for add this in a futur release
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.
Hi @assuncaocharles, this issue I think it can be closed, given that the possibility of having more databases has been offered