Documentation or examples on how to work with multiple databases efficiently
masimplo opened this issue · 7 comments
Excellent job on a much needed plugin to move us away from the Cordova implementation of sqlite and localforage.
Is your feature request related to a problem? Please describe.
I am trying to use this plugin to replace the cordova localforage one and Ionic Storage, but from what I have tried so far I can't figure out in which way we are supposed to use multiple databases on the same app. For instance we have a database called "offlineLogs" and another called "offlineAnalytics" (just two examples). The app needs to read and write to both of these interchangeably many times every few secs. Is it the case that CapacitorDataStorageSqlite only has one instance and we have to open and close each db for each read/write?
By the way I have seen the example usage you gave to #23 for using multiple tables, but wondering if this is the most efficient approach when dealing with different databases as opposed to different tables of the same database, which I guess could have some other implications for data consistency.
Describe the solution you'd like
Being able to read/write from/to multiple databases without having to open/close the db that I am interested in by having multiple instances of the storage open at any point in time.
@masimplo thank for looking at the plugin this one is a simple key/value store and can work with multiple tables in a store but to work with multiples stores you need to open and close one before to use a second one. Simultaneous open databases can be donc by using the more sophisticated plugin @capacitor-community/sqlite you may look at that one to solve your problem.
@masimplo Did you progress on the issue? Have you move to @capacitor-community/sqlite?
Hello @jepiqueau, thanks for replying. As I said I am using Cordovalocalforage as it is a more complete solution. @capacitor/sqlite needs some facades above it to behave like a document store and I think support for that is still on the early stages.
I thought your project was implementing the above, but after giving it a try I realised what you just stated, which is a pity for me because your work quality is impressive.
@masimplo that was my first plugin so i did not know capacitor at that time so i decided to develop data storage to give it a try but developers use it quickly and asked for a full sqlite database capacitor plugin and i spent a lot of time to make it and i think it is now quite stable and as i said this one offers multiple databases opened simustaneously. So i could for the native part of the plugin offers the same functionality but it will require a complete rewriting of the plugin. For the Web part which is using localforage i will have to understand how this is done with localforage. Your are the first to ask for it i may look at it but i cannot promise as you can understand it is not maintenance only
@masimplo i could also move to sql.js for the web which will use sqlite in memory and save the multiple databases in a local forage store as i did it for @capacitor-community/sqlite
@jepiqueau this makes sense. I understand this library is not a fit for my use case and that is OK. Just happy we cleared this up. Thank you again for taking the time to respond and for your great attitude. I think you can close this issue and I will give capacitor/SQLite a try next.