What database solution to choose for offline data storage (complex data)

The alrady known data storages I don’t want to talk about here.
(Preferences API, IonicStorage, capacitor/sqlite, Ionic SecureStorage).

I have lots of complex data, so simple things like IonicStorage are not enough for me.

I would like to know what you guys of think of using other solutions for ionic capacitor apps.

Things like:

  • PouchDB
  • SQL.js

Maybe you guys could list even more such data storages that allow complex data handling. I am just unsure of going for @capacitor-community/sqlite - npm since I had some bugs with it and there is only mainly one person maintining 95% of it. I am not sure about its future.

How does sth like SQL.js compare to capacitor-sqlite? Are those viable options or is their performance that much worse? What are their upsides/downsides?

Is the native-device SQLITE database that capacitor-sqlite interacts with really that much faster than the one that SQL.js would use in the browser? This is actually my main question. I am wondering why there is capacitor-specific sqlite solutions when we could just use web standard technology. What exactly are the benefits except for things like performance, which I think should be OK/Acceptable for sth like pouchdb - npm, considering it has 20.000 npm downloads per week

1 Like

Really the only capacitor-specific part of your question boils down to whether indexeddb (the only web API to store complex data persistently) is safe to use in capacitor.

Ionic docs do not recommend it because theoretically Apple/Android could change behavior to delete web data when device storage is low. But I’ve been storing data in web APIs in production with many users on Android and iOS and it’s working fine so far.

I use dexie.js but pouchDB uses the same api under the hood (indexeddb).

I am wondering why there is capacitor-specific sqlite solutions when we could just use web standard technology.

Because Ionic does not recommend using web APIs (e.g. indexeddb) in the browser due to the above concern with a potential for data loss if Android/iOS change behavior. Capacitor sqlite avoids relying on web API for storing data entirely and stores data with native APIs via the capacitor bridge.

2 Likes

Ok so this potential data loss due to browser indexedDB storage clearing is the main reason those plugins exist? This is indeed interesting, did not know that. I always thought the main reason was performance or sth else. Furthermore, performance is not even an important factor for me.

I would prefer not using capacitor-community-sqlite, since sth like dexie.js probably is friendlier to use. capacitor-community-sqlite error messages are pretty lacking imo, the whole library is a bit of a pain and the docs are lacking a bit too. Do you think it’s better with dexie.js?

wow I just saw dexie.js has 150k weekly npm downloads, so it’s probably pretty robust. But I think it is a lot weaker than sth like sqlite, when it comes to complex data management or complex search? Isn’t it a bit more like IonicStorage? Probably a solution with data-complexity-strength in between IonicStorage and ionic-capacitor-sqlite ?

also curious what app you are managing, if you mind disclosing. Would love to see what some real-live dexie webview action could look like