You can clone with HTTPS or Subversion.
Clone in Desktop Download ZIPIt's very common to store persistent data in native apps, people usually do it by embedding database libraries or manipulate plain text files. In node-webkit, you have much better choices than that, you can use Web SQL Database, Web Storage or Application Cache without headaches of any extra dependencies.
The Web SQL Database API isn't actually part of the HTML5 specification but it is a separate specification which introduces a set of APIs to manipulate client-side databases using SQL. I'll assume you're familiar with basic database operations and SQL language in following guides.
The Web SQL Database API in node-webkit is implemented with sqlite, and operations are basically the same:
To create and open a database, use the following code:
var db = openDatabase('mydb', '1.0', 'my first database', 2 * 1024 * 1024);I’ve passed four arguments to the openDatabase method. These are:
If you try to open a database that doesn’t exist, the API will create it on the fly for you. You also don’t have to worry about closing databases.
To create table, insert data and query data, just executeSql in transaction:
// Create table and insert one line
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS foo (id unique, text)');
tx.executeSql('INSERT INTO foo (id, text) VALUES (1, "synergies")');
tx.executeSql('INSERT INTO foo (id, text) VALUES (2, "luyao")');
});
// Query out the data
tx.executeSql('SELECT * FROM foo', [], function (tx, results) {
var len = results.rows.length, i;
for (i = 0; i < len; i++) {
alert(results.rows.item(i).text);
}
});For more information, you can read tutorials like Introducing Web SQL Databases.
Web storage is a easy to use key-value database, you can use it like normal js objects but everything will be saved to disk for you.
There are two types of web storage:
The localStorage object stores the data with no expiration date. The data will not be deleted when the browser is closed, and will be available the next day, week, or year.
localStorage.love = "luyao";
// Love lasts forever
console.log(localStorage.love);The sessionStorage object is equal to the localStorage object, except that it stores the data for only one session. The data is deleted when the user closes the window.
sessionStorage.life = "";
// But life will have an end
console.log(sessionStorage.life);... TODO ... IndexedDB's API is asynchronous relatively low-level and tedious to use, so it is preferable to use an abstraction, like PouchDB.
HTML5 introduces application cache, which means that a web application is cached, and accessible without an internet connection.
Application cache gives an application three advantages:
However, application cache is designed for browser use, for apps using node-webkit, it's less useful than the other two method, read HTML5 Application Cache if you want to use it.