Nozbe / WatermelonDB

🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️
https://watermelondb.dev
MIT License
10.54k stars 593 forks source link

Using watermelon without react native #887

Closed sandergroenen closed 3 years ago

sandergroenen commented 3 years ago

This is more of a question: we are deciding on which framework to use for developing a new mobile app. One of the considerations is that our front end team has developed its own ui library using stencil. This would require us to use iononic (with capcitorjs) so we can use web/js/css. However another main aspect of the app would be its offline-first character (app for banking with loan officers visiting remote locations without internet for client intakes for example). That is how i came to watermelondb and its sync feature which would be nice to have to sync to our mysql backend db through api. Now for my question: how hard would it be to use watermelondb without react native as just a javascript library?

radex commented 3 years ago

Now for my question: how hard would it be to use watermelondb without react native as just a javascript library?

WatermelonDB works on web (using IndexedDB) but it's not going to be a great experience on mobile, as performance of IDB backing is not great. You could develop a SQLite adapter for iconic. That should only require a small bit of native code (the "dispatcher"), with the rest (C++ or swift/kotlin on native and JS) already handled the rest. Someone in the community already developed a Node.js dispatcher for SQLite.

sandergroenen commented 3 years ago

Thnx for your reply, but im not sure im following. I read the database agnostic philosophy of watermeldondb, but as i understand it it primarily based on the sqlite db. Which with it's lazy loading feature should actually be performant on mobile? To be clear the solution we were looking for is using watermelondb on mobile as local storage and then use the sync method (push/pull) to exchange data with our backend mysql database server, through a custom api endpoint. So basically exchange the json data with the api end point. However since we are likely to go the ionic/compositor way we won't be using react native as a framework. So to use the watermelondb js core without react native setup/part. Perhaps im missing the point as i'm kind of a noob for mobile app developent, but we would have to include all the npm packages (sqlite,babel and of course watermelondn) and then...

radex commented 3 years ago

I read the database agnostic philosophy of watermeldondb, but as i understand it it primarily based on the sqlite db.

It IS database-agnostic, but sqlite implementation is most performant, and to use it in ionic, you'll have to hook it up yourself. Otherwise, you don't have to do anything and it should just work, as ionic is just a web view, and Watermelon supports web, but if you have more than a few MB of data, you'll lose out on some performance.

sandergroenen commented 3 years ago

Thanks for the info! So in short using the sqlite node.js dispatcher we could use the sqlite option and don't lose the performance which we would when using just webview+indexeddb. This would be a prerequisite as it would be using possibly large datasets. Perhaps a last question: i read the sync method currently supports only the entire database to be synced and not a subsection. Is that something that would be possible in the (near) future or is it out of scope. The reason i ask is because i really like the feature and would like to avoid implementing retrieving/pushing data through our api for all available models, including the exception handling/data refresh logic. However storing all records for every used model locally would be overkill and would really like to be selective in when to store locally (for example a loan officer would search for a customer when device is online and can connect with backend database, picks it, visits the client offline, edits new data and when back on the internet syncs the changes. It does not need the potential thousands/millions of other records to be stored locally...

radex commented 3 years ago

@sandergroenen what did you decide to do in the end?