-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Connector for browser indexedDB #858
Comments
5MB is practically too less for a major application housing all data offline. Please add IndexedDB support. We can't think of an application to survive only on 5 MB where most part of the app is going to be offline. |
How is localstorage support provided? I thought memory connector was persisted server side. |
See Memory.prototype.loadFromFile and Memory.prototype.saveToFile. We had extended memory connector to support both It is possible to extend the memory connector to load/save data in indexeddb, but such solution would be be very memory hungry, as the page will load whole indexeddb into javavascript memory (heap). A better solution is to implement a new connector that will fetch the data from the indexeddb on per-record basis as needed. |
What about using Mozilla's localForge solution? |
A powerful solution would be to implement a levelup connector, which could be then configured to use either LevelDB on the server or IndexedDB in the browser (via level.js). However, both modules are quite large and thus the final client bundle would be even bigger than it is now. In the light of that, I am inclining towards writing a connector directly on top of the IndexedDB API, so that the module size is as small as reasonably possible. |
Ah, that makes sense. Maybe it could be a wrapper which try's to detect leveldb or local forge and if found then resorts to the included library? |
API wise, we could use localForge instead of IndexedDB. However, [https://mozilla.github.io/localForage/localforage.min.js] is almost 24kb, which is a problem. Why are you pushing for localForage, what are the advantages compared to pure IndexedDB? |
I'm not. Just what I know. |
Fair enough. I was wondering if there is something important that I am missing. |
Hi, |
@vigyanhoon This is not the top priority for us ATM, it's almost certain that the feature won't be implemented in the next 4 weeks. Would you mind contributing the connector yourself? |
I will try. Please provide resources to look upto. |
@vigyanhoon I am afraid this is the only documentation we have so far: http://docs.strongloop.com/display/LB/Building+a+connector The implementation of the filtering function is at the moment hidden inside the memory connector: loopback-datasource/lib/connectors/memory.js#L367-L527. We would like to expose it via a public API at some point, either as a public API of loopback-datasource-juggler, or even better as a standalone module. |
@bajtos how does loopback memory connector connect to the browser's localstorage? |
+1 to expose it. I want to use it as part of the rules engine. |
@jrschumacher search for "localStorage" in loopback-datasource-juggler/lib/connectors/memory.js. Note that the approach used by memory connector, where it builds/loads a giant JSON containing all model instances, is not the right approach to use for the IndexedDB connector. The IndexedDB connector should store each model instance as a standalone IndexDB entity (row) and then use IndexDB API to access a single model instance or iterate over all model instances. |
i just found https://github.com/r3dm/loopback-connector-indexedDB by @morenoh149 and @BerkeleyTrue what about that (havn't tried it yet)? |
I have tried this and it is not working. From what I can recall, it doesn't have the 'all' method implemented. I'm currently working to put together a sqlite connector for loopback (iOS and Android). Basing my work off the existing loopback-connector-sqlite for node, in combination with Cordova SqlitePlugin. |
Sorry y'all. That plugin is a work in progress. |
This sounds great @boscodsouza82 +1 |
Had put this on hold due to being busy with other parts of my app. However, I have now resumed work on loopback (connector and sync), and will be posting a solution as soon as I can, within the month at worst. For those that did, don't lose hope. :) |
would be awesome! @boscodsouza82 +1 |
Just to clear up some confusion (for myself and others). Here's my approach for an alternative to LocalStorage. For now, this approach works for a Mobile App, not for a Mobile Website. For the sake of discussion, let's use the Official Sync Example, https://github.com/strongloop/loopback-example-offline-sync
Note once again, that I based all my work off the Official Sync Example. We can keep our discussions focused around that example. I am making this elaborate announcement for the following reasons...
Best regards, |
Thanks @boscodsouza82 for your findings! We tried to use replication as shown in the loopback-example with LocalStorage and PostgreSQL. LocalStorage unfortunately is no solution for the future as it is limited to 5MB. Concerning robustness a sophisticated cleanup, archiving or some store-when-required methodology would have to be implemented following this approach. As loopback client is still missing a well tested and maintained indexddb-connector, we are currently looking into removing the loopback-dependency in our client code testing http://dev.yathit.com/ydn-db as it already supports indexddb and syncs with rest-apis. Syncing via Rest makes the code independent of the underlying server side database like mysql, postgres or others. And loopback is strong in building awesome rest apis. |
Welcome @gruzilla. :) Side note: Unable to access http://dev.yathit.com/ydn-db Also quickly read about ydn-db sync, https://dev.yathit.com/ydn-db/doc/sync/index.html What are your thoughts about ydn-db sync vs loopback sync? No hurry, whenever you get the time. :) |
@boscodsouza82 - would it be possible to share your Cordova client version of loopback sync example? I tend to use the Ionic and Cordova client frameworks for Android so would be good to see how you went about it. |
I am still testing it out on Android and iOS. Had hoped to finish y'day but still on it. Will share as soon as I am done. |
Brilliant thanks @boscodsouza82, this will help me save a lot of time. |
sorry @boscodsouza82 for the link copy pasting mistake.. after looking a little closer at the code we saw that the sync-module is in a private bitbucket repository and we are unhappy with the whole project-setup. therefore we decided against using it. again @boscodsouza82 are you interested in joining forces developing the connector? do you have a github repo for it? |
@gruzilla :) Half happy you decided against ydn-db since now we will have atleast 3 more people looking at this connector. me, @gruzilla and @nikvaliris. :) For ydn-db though, I think they have a different approach than the one Loopback uses. However, I am not versed enough to comment on either. Maybe someone from the Loopback team can chime in, no hurry :). I intend to put all this up on github soon, but I am a bit caught in device related troubles (on iOS and Android) and am ironing those out. The project does appear a bit different from the original, https://github.com/strongloop/loopback-example-offline-sync. This is primarily because I have to tweak it to work as a mobile app. @nikvaliris, it's already largely Ionic. However, I am not using Ionic lib, rather am using Angular directly, as per the official version. Will replace it in a few days. 2 Projects
I am interested in joining forces. 👍 |
Functionally, the connector creates a SQLite DB, and it's table on the devices. I am facing some issues with some failing SQL queries so debugging those at the moment. Please feel free to use the code and provide solutions if possible. |
At the moment, loopback's memory connector can be configured to persist data in browser's local storage. This has a significant problem as the local storage is size limited to about 5MB.
We should support storing the data in indexdb too, possibly via https://github.com/google/lovefield
A community-run implementation: https://github.com/r3dm/loopback-connector-indexedDB
The text was updated successfully, but these errors were encountered: