Pow db

From PlainOldWebserver

Jump to: navigation, search

Back to Top

Pow_db

The SJS version of Mozilla Storage cleans up after itself, casts all numbers to strings in returns from the DB, and allows access through mysql-like pretty printing or a string-only array. SQL is compatible with SQLite. If you need binary data support, use the Storage API directly. The SQLite database is stored in the pow/data directory in your Moz profile directory.

  <?sjs
        try {
          var pdb = new pow_DB("object_db");
         pdb.exec("CREATE TABLE foo ('object_id' int, 'name' varchar(10),"+
             "'name2' varchar(12))");
        } catch  (e) {
         // noop
        }
        pdb.exec("INSERT INTO foo (object_id, name, name2)"+
            "VALUES (1, 'gus', 'bob')");
        var results = pdb.exec("SELECT * FROM foo WHERE 1=1");
        pdb.pretty_print(results);
        document.writeln(results["column_names"].join(" ")+"<br>");
        for (var i=0;i<results.length;i++) {
         document.writeln(results[i].join(", ")+"<br>");
        }
  ?>

Result:

  --------------------------
 | object_id | name | name2 | 
  --------------------------
 |         1 |  gus |   bob | 
  --------------------------
 object_id, name, name2
 1, gus, bob

See Also

Personal tools
Navigation