Menu

class methods

Portucalle

Class methods do not need access to any specific jsql.DB object. The ones available for the developer are:

jsql.DB.supportsLS ()

This class method will check if the browser supports local storage or not.

Parameters

  • None

Returns

  • true: The browser supports local storage.
  • false: The browser does not support local storage.

Example


// 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();}

jsql.DB.exists (name)

This class method will check if the given DB exists in the local storage.

Parameters

  • name: The name of the DB to be checked for existence.

Returns

  • true: The DB with the given name exists.
  • false: The DB with the given name does not exist.

Example


// 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");
}

jsql.DB.drop (name)

This class method will drop the database identified by the given name.

Parameters

  • name: The name of the database to be dropped.

Returns

  • None.

Example


// Drop the 'books' database //
jsql.DB.drop("books");

jsql.DB.getDbNames ()

This class method will retrieve the names of all the databases.

Parameters

  • None.

Returns

  • Array containing the names of all the databases.

Example


// 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]));
}

Related

Wiki: Home