jsql-sx Wiki
jsql-sx is a javascript API for simple SQL-like local data handling
Brought to you by:
portucalle
Class methods do not need access to any specific jsql.DB object. The ones available for the developer are:
This class method will check if the browser supports local storage or not.
// Open the 'books' database with auto-saving turned off //
var db = jsql.DB.open("books", false);
// ... Do what need to be done ... //
// If local storage is supported, save the database //
if (jsql.DB.supportsLS() === true) {db.save();}
This class method will check if the given DB exists in the local storage.
// If the 'books' database does not yet exist //
if (jsql.DB.exists("books") === false) {
// Create it //
var db = jsql.DB.open("books");
// Create the 'classics' table //
db.create("classics", [["title", "TEXT", "NOT NULL"], ["author", "TEXT", "NOT NULL"]]);
// If the 'books' database already exists //
} else {
// No need to create the 'classics' table so just open it //
var db = jsql.DB.open("books");
}
This class method will drop the database identified by the given name.
// Drop the 'books' database //
jsql.DB.drop("books");
This class method will retrieve the names of all the databases.
// Initialize the array which will contain the handles for all the databases //
var dbs = [];
// Retrieve the name of all the databases //
var dbnames = jsql.DB.getDbNames();
// Go through all of them //
for (var i=0 ; i<dbnames.length ; i++) {
// Retrieve the handle for the current database and save it in the array //
dbs.push(jsql.DB.open(dbnames[i]));
}