So I got a new GeeksPhone Peak, and started making apps in HTML5, CSS, JavaScript.. It is great, I love it, but now I'm trying to make a timetable app and I have to save data, when I fill my timetable (just text) somehow, and reload it when the app is loaded.
I started searching and found localStorage, IndexDB, backbone.local-storage but couldn't really find great tutorials on them. Or is there a special API for that case? Can someone help me on which one to use, or how to write to file, save it, read it, etc.?
FirefoxOS provides multiple mechanisms for supporting persistence in your application. While considering the choice between local Storage and Indexed DB, your decision will rest on how important the following points are for your application:
How easy the API is use [Local Storage is easier. Simple key-value pairs]
Synchronous v/s Asynchronous API [Local Storage is synchronous. IndexedDB has both modes]
Transaction Support [Indexed DB has it]
How easy it is to do Search [Since local storage is just key-value pairs, it is difficult to do searches especially if your values contain complex structures]
A good article that provides comparison is here.
In case, you want to take a look at how to use the localStorage, IndexedDB APIs on FirefoxOS, I have written tutorials on the same: localStorage & IndexedDB & Device Storage.
Related
I've been tinkering a bit on a small application which would show a limited amount of data to the viewer in a nicer way. I was thinking instead of opting for a database (be it SQLiteor / MongoDB) to have my data stored in a simple json file. It would have below characteristics:
Static data (will never have to be updated - 100-150 arrays)
Not private data - can be freely accessed by anybody which has access to the application
Offline application (not a single connection with internet)
Multiple users which would read only the data
JavaScript being used for this
What I am wondering about though is simultaneous reads. The application would never be used to update the data, it remains static. However there might be several people using the application simultaneously. As the tool will be stored on a shared drive, accessible by several other clients at the same time (only to read the file).
As I haven't touched anything with data or databases yet, I'd wanted to see if anybody already tried this out before I go into it deeper.
I am aware of the implications in terms of security however the data inside the application is not secure data and can be accessed by anybody freely. I only want to show it in a nice way. And as it is static anyway I was going to opt for a JSON file i/o starting to work with a database to speed up the development.
As far as I can see from your description, I think that there should be no conflict. You should be fine.
It's actually fairly common to use JSON-formatted files to store truly-static data.
I'm currently in the process of making an App using Javascroipt and Phonegap that needs to save a Database or something similar localy while offline until it is later synced with an external Database (not the main Problem).
So whats the best solution for managing relativly big chunks of data that have to be modified a lot during runtime, be able to delete entrys, add new entrys, read entrys using attributes and ids, sort entrys and be able to import and export data in a file (i.e give me a string or object that I can save in a file using phonegap)?
I already looked at TaffyDB (abandonned since 2 years) and pounchDB (seams to work using ajax and therefore require internet connection).
Its good that you have already tried pouchdb.js that is client side implementation of couchdb database and is supported and tested for all the major browsers and platforms.
indexeddb is actually latest web browser standard for storing large chunks of data in the form of objects.
All the major storage libraries including pouchdb are based on this only.
Kindly mark this answer if this is what you need or comment back for more explanations.
I feel like this is a complicated topic, I searched everywhere and can't seem to find a good method to save data from users. I'm making an incremental and want people to be able to leave their browsers and have their data saved when they come back. Anyone have any suggestions?
It's pretty easy though I guess it might depend on your app. Easiest way is through using HTML5 localStorage which is built in permanent storage for modern browsers that can be manipulated easily with javascript. A good article here. If you are concerned about browsers that don't support localStorage then you can use one of the libraries that offers cookie fallback such as jStorage which happens to have a form example.
It sounds like you're going to need an SQL database. I'd recommend learning SQL, and learning a server-side programming language like PHP or ASP to automatically access the database. There is a lot to cover. I learned originally using w3schools, and have supplemented my education since then. w3schools an okay (not good, just okay) reference, but I wouldn't really recommend learning entirely from it. I'd recommend learning from youtube tutorials to get demonstrations and reading the manual for your server-side language.
You may want to look into HTML5 Web Storage. The localStorage object can be used to store data (strings) in the user's browser (not server-side). HTML5 Web Storage is widely supported in modern browsers.
If you need the data server-side as well, cookies may be a good choice for small amounts of data.
If you have large amounts of structured data and wide browser support is not crucial, you should check out HTML5 IndexedDB.
While experimenting with some data indexing using node.js objects (arrays, maps...) that takes some time to populate (from DB data) at every startup of the script, I wished my node.js objects could be automatically and transparently persisted in my database.
Having used MongoDB from node.js as well as other databases (including SQL-based) for some time now, I'm quite aware that the query/update mechanisms are very different between javascript objects (synchronous access, no queries) and database records (asynchronous access, queries, ...). However, I'm still hoping that a solution to make a javascript var persisted, at least for indices, can exist and be helpful.
Basically, I'm thinking of something like HTML5's LocalStorage, but for node.js servers.
Do you think this idea is interesting, feasible, or maybe it already exists?
EDIT: Work in progress: https://github.com/adrienjoly/persistent-harmony
A first thing to make clear, is that databases serve two purposes: persistence and convenient/efficient querying.
If you only need the first because you absolutely know up front that no other program is going to access your persistent data, you could take a look at the literature on orthogonal persistence, which is exactly the concept that you're suggesting here. An example is the KEN protocol that was successfully implemented in the WaterKen Java server.
There is some work to integrate the protocol into Google's V8 JavaScript runtime, which could lead to Nodeken, a Node.js with orthogonal persistence.
One of the difficulties of getting orthogonal persistence right is to map transactional semantics to a f.e. object-oriented programming system. The approach taken by V8-ken is to treat a single event loop execution of your JavaScript runtime as a transaction. In other words, the state of the virtual machine is persisted at the end of each "turn" in response of some event (incoming web request, server reply, user interface event, all asynchronous operations (IO), etc.). This however requires a modified runtime such as V8-ken, but evolutions in ECMAScript, such as proxies, look promising to be able to implement such features more conveniently.
In many cases (think web applications) though, persistent data needs to be accessible by different programs, requiring a "real" database for data to be easily exported, migrated, queried, etc.
Hybrid approaches could of course be possible...
%> npm search persistent storage
closet JSON persistent storage with methods chainability and callbacks for asynchronous use. =ganglio 2013-01-29 18:41 0.0.7 json persistent storag
ewdDOM Persistent lightweight DOM using Mumps Global Storage =robtweed 2013-02-02 14:39 0.0.4
fs-persistent-object Tiny Node library for persisting small runtime objects on filesystem =oleksiyk 2013-04-09 09:13 0.0.1 persistent tiny storage
headstorage A persistent storage for Node.js =headhsu2568 2012-11-20 13:41 0.0.0 storage
level-store A streaming storage engine based on LevelDB. =juliangruber 2013-06-21 19:55 3.3.2 leveldb levelup stream persistent
node-persist Super-easy (and fast) persistent data structures in Node.js, modeled after HTML5 localStorage =benmonro 2013-04-09 17:33 0.0.1 node persist
persistent-hash-trie Pure string:val storage, using structural sharing =hughfdjackson 2013-05-24 19:24 0.4.1 persistent hash trie pure functional d
perstore Perstore is a cross-platform JavaScript object store interface for mapping persistent objects to various different storage mediums using an in
shelf.js A modular, powerful wrapper library for persistent objects in the browser and Node.js =shakty 2013-05-24 08:10 0.4.7 persistance localStorag
stay Persistent scuttlebutt instances for browser and node =juliangruber 2012-12-11 21:54 0.1.0 persistent scuttlebutt persistence loc
Looks like the closest match would be node-persist
=)
EDIT: Here may be a better alternative solution...
#adrienjoly You know prototyping is still fairly high level and may not be (in the long run) as efficient as you are thinking.
You may be better off developing a module in C/C++ exposing a high level API for node.js to take advantage of.
I think I have a post about getting your feet wet with this type of node.js development (it stemmed from an original tutorial I followed here)
I do believe that method is however outdated and a newer method is to use the node-gyp tool. Some additional resources and examples: node-gyp projects, uRSA (I have a small pull request with this one), bcrypt etc..
My assumption in this is that you may bind the module extension to a db api such as oracle or postgres etc., and by writing a low level module linking to a low level API while exposing a high level API for developers to implement the persistent configuration options with API calls for slicing, indices, etc the performance would be optimal vs. trying to have node.js interpret your prototyping shim
Maybe this is what you're looking for?
https://github.com/yangli1990/flydb
or
npm install flydb
Now in javascript
var flydb = require('flydb');
flydb.test = "hello world"; //flydb.test will now persist
To run this
node --harmony-proxies <your commands>
e.g
node --harmony-proxies app
I'd like to be able to store, not a massive amount of data but not a trivial amount either on the client. Basically, I want to be able to use something like an SQLite database on the client side using Web technologies. The application is a foreign language dictionary so I want this data to be accessible once the application has been downloaded.
Is this possible with Sencha touch or any JavaScript/HTML5 technology?
There's several options depending on the target browsers:
localStorage (has the advantage of being cross-browser back to IE8)
WebSQL (deprecated)
IndexedDB
Application Cache (this is a stretch for data storage...but it /can/ be done)
All of these technologies have storage limits, some of which vary between browsers, and to complicate things even more, some will let the user choose to allow expansion of the storage ceiling.
I've used localStorage with good results, and using a JavaScript compression library ( http://code.google.com/p/jslzjb/ ), you can gain some storage advantage (though in my experience, not a lot. If you're at 5.5Mb with a 5MB limit, the compression might get you by, though)
Yes it is. The only question is what type of data, but you can store anything.
If its a lot of text/object data you can use localstorage. Not sure how large the dictionary is, but that might be a very simple solution. You can download the dictionary to the client and then use JSON.stringify() to convert your data to text (a string), and the local store can store it and retrive it.
A link to help, with other options including a database option:
http://www.html5rocks.com/en/tutorials/offline/storage/