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

Detect when a database was added #1935

Open
tobiasBora opened this issue Mar 29, 2024 · 2 comments
Open

Detect when a database was added #1935

tobiasBora opened this issue Mar 29, 2024 · 2 comments

Comments

@tobiasBora
Copy link
Contributor

As of today, it is documented here https://dexie.org/docs/Dexie/Dexie.getDatabaseNames() that it is impossible in Dexie 3 and 4 to listen for the creation/deletion of databases. I'd love to have an observable like:

let names = PlanotoFileDexie.getDatabaseNamesObs();
$: files = databaseNames.map(name => ({uuid: name,
                                       file: liveQuery(() => new PlanotoFileDexie(name).fileInfo.get(0))}));

to be able to list all databases (I use them to store files basically).

@dfahlander
Copy link
Collaborator

You can get an observable and all if you could change your model to let a file be represented by a row in a single db instead. (And you'd get better performance).

@tobiasBora
Copy link
Contributor Author

Yes, my main issue so far is that this creates a repetition: I want fileInfo to stay in the database as I will export/save/… and I want fileInfo to also be exported with the database. Also I don't want to duplicate fileInfo inside a separate database as it does not comply with DRY, leading to easy inconsistencies. Anyway, for now I don't plan to have such a huge number of files that it is a performance problem. For now, what I did is using a writable([]) populated by getDatabaseNamesObs that I update each time I create a new file. This seems to work well enough for now, but this will not update if a file is created in another tab for instance… but not too hard to fix I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants