I developed a hybrid app with Cordova. I used localStorage for saving some data on devices. Now I need better and persistent storage method. Also I'm looking for a synchronous library. Do you have any advice?
I just find Persisto (https://github.com/mar10/persisto). Can I use this with Cordova?
I just find Persisto. Can I use this with Cordova?
You can use it with Cordova, but it appears to just be a wrapper around localStorage, so is no better/more persistent that using directly using localStorage.
If your Cordova app is targeting iOS then you should be aware that any locally persisted data stored inside the Webview (localStorage, WebSQL, IndexedDB) is considered cache data and therefore can be wiped at any time if the device runs low on storage space.
Also I'm looking for a synchronous library. Do you have any advice?
TL;DR: I don't think you'll find a sychronous interface to a better storage mechanism because the more durable/reliable mechanisms are all inherently asynchronous.
Ultimately it would be better to bite the bullet and rework your code to work with an asynchronous storage mechanism.
For reliable persistent storage that isn't going to get wiped by iOS at a whim, you could use a native SQLite DB via the cordova-sqlite-storage plugin.
For an simple interface to it, you can use a wrapper such as localForage with the cordovaSQLiteDriver adapter.
Or if your content is more file-based, you can store it using cordova-plugin-file to a durable storage location.
Now I need better and persistent storage method.
You can use indexeddb for bettter persistent storage. but all the apis are asychronous and are very complex to implement.
I'm looking for a synchronous library. Do you have any advice?
You can use jsstore for executing the db code sychronously. It provides sql like apis and all the apis are sychronous. So you dont need to worry about not getting latest data etc.
So if you call update, select api one after another, then first update api will be executed and after that select api.
Again it does not make your code asychrnous, it just executed the code in the same order as you call.
Check it out here - http://jsstore.net/
if you are looking for a library to store only keypair value, then you can use KeyStore. Here you dont need to do any setup.
Check out keystore here - https://github.com/ujjwalguptaofficial/KeyStore
Related
I'm dealing with a dilemma regarding chrome storage.
My use case it that I have a Chrome extension that will store the user's cleaned tabs on a daily basis. One of the requirements is that a history is kept, so I store tabs in an array per day.
My current implementation is to store to chrome.storage.sync, however this storage is way to small for what I intend to use it. It is in fact, rather tiny.
The second option would be to use chrome.storage.local which has sufficient capacity, but we don't want the user's historical tab data to get lost, so this poses the problem that we actually need sync.
The third option is to use localstorage and implement a custom sync to some free remote service like Firebase.
My question is:
Is my understanding right that chrome.storage.sync is only to be used for some configuration data? And is there a straightforward way to force sync the 'local' chrome storage anyhow (might Firebase be an option)?
Is my understanding right that chrome.storage.sync is only to be used for some configuration data?
Yes, being a limited storage, it is intended for maintaining different forms of state data.
And is there a straightforward way to force sync the 'local' chrome
storage anyhow (might Firebase be an option)?
You can definitely use some external service like Firebase to save the user data and gain synchronization on different devices
I am migrating my script from Google Chrome Extension to node.js
And I simply need to store a couple of variables, nothing fancy and performance isn't an issue either, since they would only be accessed when the script is restarted.
In Google Chrome Extension I would use the client side HTML5 storage (localStorage)
However as a server language node.js doesn't have this feature and it's not surprising.
I could of course install some database and being particularly familiar with MySQL this is not an issue, but, if there is a simple way of storing my configs - I would much like to try it out.
If u get experience with localStorage you can use node-localstorage.
I'd recommend using sw-precache, aka service workers. They run in the browser and can be used by the fetch api. Here's a great node_module that will accomplish your needs.
https://github.com/GoogleChrome/sw-precache
Here is a codelab that explains service workers in more detail:
https://codelabs.developers.google.com/codelabs/sw-precache/index.html
I have simple CRUD application with the backend written in Flask, datastore is Mongo and frontend in AngularJS.
I would like to augment the application to allow for CRUD operations even when it's offline and automatically sync when a data connection is available. What is the best correct technology to do this with the minimum amount of extra development?
I've looked at Meteor which could solve the problem but would involve re-writting the app in Meteor.
I've also looked at Breeze which look like it might be a better option and allow me to keep using Angular and Flask.
Is it a lot of data? Adding offline capabilities to an existing application will always have some impact.
You could try using some HTML5 features directly: HTML5 Application Caching is made for offline access and allows to download all the needed artifacts for the webapp to be able to work offline, so that solves a part of the problem.
The other part is the the data, it could be loaded into the browser using either the browser HTML5 Local Storage or IndexedDB.
Local Storage allows to store String associated to keys, so for storing JSON you need to stringify it first. IndexedDB supports more data types,both datastores have a Javascript API.
So it would be a matter of choosing one datastore and making a sync module that periodically pings back the server and when the connection is available sync the local datastore.
The alternative is to use some offline first framework like hoodie, this an article from a hoodie developer for how to use hoodie together with angular. He took the Angular TODO sample application and modified it to use hoodie.
This together with application cache might be a lower impact way to get offline capability to your Angular app.
I'm working on some web application and we need to store number of javascript objects in local storage. Until now we did it using cookies but we want to use one of HTML5 storage solutions because cookies data is send to server on each server call and it is a waste of resources and also it's size is very limited. The data should be stored permanently, I mean it should be available after closing the browser and opening it again.
What is the best practice to do this? Is there any way to store objects in local storage. Thanks for the assistance
In my current project I'm using PouchDB library (http://pouchdb.com/). It is a lightweight javascript database which can store data locally in browser (string, int, object etc). All stored data are still available after browser restart.
You should use it with some JS framework, in my case it is AngularJS (very simple integration).
Have a look at this link: http://slides.html5rocks.com/#web-storage
It sounds like HTML5's Local Storage is definitely a great option for you. That presentation has a lot of great info in that should help you decide on the best form of storage.
IndexedDb is a good option for storing javascript objects.
I strongly recommend you to read this -> https://developer.mozilla.org/en-US/docs/IndexedDB
I would like to see a decent example of a mobile web app using the Sencha framework with a client side DB accessed with SQLite. I'm currently digesting JqTouch and kinda get the binding method used there from reading Jonathon Stark's "iPhone apps" book, but cant find any examples of accessing Senchas features ie listed elements with SQLite. The DB will be small; 30 records, with about 5 fields, mostly numeric, a few of them calculated. All the math is done in javascript and I have that part working (in dash code). I need to add, delete, and edit the records.
Any pointers or examples would be very much appreciated. I'm an old dog trying to learn new tricks. Thanks
Sencha is client-side Javascript, so your application actually runs on top of Safari. That means you can forget about accessing (or installing) your own SQLite database from within the browser sandbox.
Having said that, you want to learn some new tricks, so why dont you read up on localStorage and DOM Storage. Basically the HTML5 specification allows for offline database storage based on SQLite (imagine relational database cookies). There is 1 per domain and they can be up to 5MB in size. I believe the iPhone supports this as well.
Here are some links: Introduction some API Information and a nice little blog entry by a chap called Ben Lister
Your client side code (i.e. Sencha/Javascript) would not access the SQLLite database. It will either need to read JSON or XML from the server. You'll need server side code to read the data from the database and format it in a way that your Sencha data readers will understand.
What are you using server side? If it's PHP you should look into MDB2
I had very good experience integrating Lawnchair library with Sencha Touch. Take a look at their guide, it's very easy.
Looks like there is a SQLite proxy available for sencha 2 now. http://market.sencha.com/addon/sqliteproxy-
Check out this thread on the Sencha Forums - it's a user created proxy for SQLite which I've successfully used to put data into a SQLite DB. The proxy comes with an example, but I might try and make a slightly more complicated one at some point.
Sencha's local storage doesn't take advantage of SQLite via the JavaScript API in the browser, but does use local key:value storage and has it's own way of referencing data to make it pseudo relational. This is still part of the WebDB spec, which is probably still SQLite under the hood if I had to guess. It's more persistent than a cookie or session, regardless.
You can also receive XML/JSON from a server over JSONP or Ajax if you're on the same domain, create a model to handle that data as well and bind it to a local store so that your data is available offline.