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

PouchDB Wrapper #28

Closed
srbala opened this issue Jul 8, 2020 · 12 comments
Closed

PouchDB Wrapper #28

srbala opened this issue Jul 8, 2020 · 12 comments

Comments

@srbala
Copy link

srbala commented Jul 8, 2020

Any plans for PouchDB wrapper?

Do you think it might help data avilabilty in browsers and PWA use cases?

@jepiqueau
Copy link
Collaborator

@srbala there is no plan for this. PouchDB is a document database not SQL. The problem associated with PWA or Web browsers app is that no permanent storage is available. Before to answer, i look at pouchDB and try without success to create an app in typescript with Ionic5 and Angular9 and using pouchdb-adapter-cordova-sqlite and cordova-plugin-sqlite-2 (Could not import pouchdb) to create a service. Is your choice of pouchDB was related to have a PWA app synchronizing with a CouchDB server database or was it just to have an sql equivalent database for PWA or Web apps. In that case we may be looking to IndexedDB which is also not an sql driven database. So not sure that all SQLite statements could be implemented ? Can you tell me more about your concern

@srbala
Copy link
Author

srbala commented Jul 8, 2020

Looking into the possibility of single ORM layer library (lets say capacitor-db-wrapper as CDW) which can work browser and app, detects and adopts based on availability or device type. This way app development has the calls CDW, CDW takes care of rest.

https://pouchdb.com/adapters.html
https://www.techiediaries.com/ionic-sqlite-pouchdb/

https://github.com/google/lovefield seems to alternate for SQL like statements and can be a bridge

@srbala
Copy link
Author

srbala commented Jul 8, 2020

Having single code base for Mobile app vs PWA, when it comes to storage, it seems to be complicated.

@fernandocode
Copy link

I don't know, but it looks like what you (@srbala) want is what the plugin was already doing (https://github.com/jepiqueau/capacitor-data-storage-sqlite), even before this sql plugin was created, maybe what you are requesting is the opposite of what I requested some time ago (jepiqueau/capacitor-data-storage-sqlite#11).

I didn't deep into your request, so I may be completely wrong

@srbala srbala closed this as completed Jul 8, 2020
@jepiqueau
Copy link
Collaborator

@srbala is the answer given by @fernandocode is good enough for what you are looking for ? As you close the issue i assume yes. Thanks anyway for looking at both plugins

@srbala
Copy link
Author

srbala commented Jul 9, 2020

@jepiqueau Thanks for checking

I think might have to do some more research and experiments.

Mobile app development is fairly new world for me, trying to PWA in parallel. My experience in the past are mainly enterprise application development, usually use ORM layer (like typeorm) to mask the difference between databases and environments.

I am looking for a library (or ready to contribute to built one) for mobile and PWA, which can hide the complexity underneth and provide consistant API for development.

@fernandocode
Copy link

As I saw that you mentioned the typeorm (I found it very interesting), if you go to a project where sql is needed, I use in my projects ionic-database-builder, which in its base uses database-builder, currently I haven’t published the configuration for use with capacitor (open an issue there, which I add, because the provider isn’t complete yet), the purpose of not being an orm in fact, is just a way of abstracting much of the complexity of the sql commands, and not having to create string commands, which leads to many errors.

@jpike88
Copy link

jpike88 commented Nov 1, 2023

Please reopen this issue.

My company has been using enterprise-grade hybrid + web + pouchDB + cordova-sqlite-storage for many years now. I've been looking at ways to transition us off Cordova, but this is a major blocking problem.

your choice of pouchDB was related to have a PWA app synchronizing with a CouchDB server database or was it just to have an sql equivalent database for PWA or Web apps. In that case we may be looking to IndexedDB which is also not an sql driven database

To answer this, it's purely to act as a safe, permanent storage, nothing more fancy than that. I would not trust indexedDB on iOS device at all, it's primarily to ensure data permanence and no tricks being done by the WKWebKit module. We have high value clients and need to use the safest ways of data storage we can.

Here's the implementation of it, you may want to model off that.
https://github.com/storesafe/cordova-sqlite-storage/blob/dev/www/SQLitePlugin.js

@jpike88
Copy link

jpike88 commented Nov 2, 2023

Another big reason I forgot is that sqlite allows limits for indexeddb to be cancelled out, the way we use pouchDB means that often we may breach 100s of megabytes, even up to a 1GB of storage.

Using this as an adapter will allow us to make the step fully out of Cordova space.

Why not use SQL instead? We have a lot of 'templates' that consist of JSON documents with many flags and other things on them.

Using the PouchDB map/reduce method, I can easily define a view that can interrogate each document in a bucket to give me specific results. It's a far more efficient and cleaner code than just iterating over an SQL table, and the performance profile is simple to understand.

@jpike88
Copy link

jpike88 commented Nov 3, 2023

I should have added another couple of reasons:

  • PouchDB enables sane cross-platform local storage of things like access tokens, user preferences, any other localized data that a web SPA would worry about. That means I'm not having to implement SQL for mobile, and some other layer or adapter for web to store and interrogate the exact same data.
  • Why not use a local preferences or something? Aside from the fact that I can't enumerate collections of data on it, @capacitor/preferences recommends not using native local prefs for fast and frequent access of local data.
  • IndexedDB is poorly supported and has a history on safari of being unreliable https://twitter.com/feross/status/1404568122158313474, I don't the risk of my users to be randomly logged out of a mobile app.

I'm also asking the cordova-sqlite-storage if they're able to make themselves capacitor-native, which would solve my problem. I could probably contribute to them to achieve that, can't be too difficult. But I like your project better, it's cleaner and capacitor first. If a pouchDB adapter can be looked at seriously that would be great, maybe I could write but I'd need some tips.

@jepiqueau
Copy link
Collaborator

@jpike88 are you talking about a web app or native app? In Native the plugin stores the databases in the device as pure sqlite db. In web i use sql.js which use the database in memory and store it with localeforage in indexdb. There is also a method to store it in the filesystem if you wish. It working offline. If you want to connect it to a remote server there are mthods to import from and export to json object. I will not go for pouchdb. If you want to have this you must developp a pouchDb capacitor plugin on its own. Hope this clarify

@jpike88
Copy link

jpike88 commented Nov 3, 2023

Fair enough... a shame because I can't just dump pouchdb anyway. I need to look at bringing that other plugin across. Do you know how hard that might be?

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

4 participants