Class nimbusly.Database
Defined in: database.js.
Constructor Attributes | Constructor Name and Description |
---|---|
nimbusly.Database(databaseName, migrations, version)
HTML5 Database wrapper class
var db = nimbus.Database.new('mydb', migrations);Most of the methods in this class can accept SQL in a number of different formats:
database.executeSqlUpdate("update user set enabled=true where id=4"); database.executeSqlUpdate("update user set enabled=true where id=?", 4); database.executeSqlUpdate([ ["update user set enabled=true where id=?", 4], ["insert user_permissions (id, code) values (?, 'login)", 4] ]); |
Field Attributes | Field Name and Description |
---|---|
<static> |
nimbusly.Database.logger
Logging method XX
To actually get database logging, set this to your own database logging method, which should be of the form function(message) where message will be a string, db.logger = function(message) { console.log(message); } |
<static> |
nimbusly.Database.open
Open the database, do any upgrade/initialization, then call the callback when it is ready to use
|
Method Attributes | Method Name and Description |
---|---|
nimbusly.Database.executeSqlInsert(sql, callback)
Executes a SQL insert statement and returns the rowid of the row inserted.
|
|
nimbusly.Database.executeSqlQuery(sql, callback)
Executes a SQL query and returns the results as an array of objects.
|
|
nimbusly.Database.executeSqlUpdate(sql, callback)
Executes a SQL update statement,
If successful, the callback, if any, is called.
|
Class Detail
nimbusly.Database(databaseName, migrations, version)
HTML5 Database wrapper class
var db = nimbus.Database.new('mydb', migrations);Most of the methods in this class can accept SQL in a number of different formats:
- String - a simple string contaning SQL
- Array - a sql statement, followed by a list of paramters
- Array of arrays - an array of sql statements with parameters, to be executed as a single transaction
database.executeSqlUpdate("update user set enabled=true where id=4"); database.executeSqlUpdate("update user set enabled=true where id=?", 4); database.executeSqlUpdate([ ["update user set enabled=true where id=?", 4], ["insert user_permissions (id, code) values (?, 'login)", 4] ]);
- Parameters:
- {string} databaseName
- name of HTML database
- {nimbusly.Migration[]} migrations
- migrations for udpdating or initializing the database
- {String} version Optional
- version of database needed (defaults to latest version)
- See:
- nimbusly.Migration
Field Detail
<static>
nimbusly.Database.logger
Logging method XX
To actually get database logging, set this to your own database logging method, which should be of the form function(message) where message will be a string,
db.logger = function(message) { console.log(message); }
<static>
nimbusly.Database.open
Open the database, do any upgrade/initialization, then call the callback when it is ready to use
Method Detail
nimbusly.Database.executeSqlInsert(sql, callback)
Executes a SQL insert statement and returns the rowid of the row inserted.
If successful, the callback, if any, is called. If executeSqlInsert is called with a single
insert statement, a single row id is returned to the callback. If multiple insert statements
are specified, then the callback will be passed an array or rowids corresponding to
the sql statements.
db.executeSqlInsert(["INSERT INTO user (name, password) values (?, ?)", name, password], function(result) { alert("User added with id " + result); });
- Parameters:
- {String|String[]|String[][]} sql
- sql statement
- {Function} callback Optional
- must be of the type function(results) where results will be a single row id, or an array of row ids
nimbusly.Database.executeSqlQuery(sql, callback)
Executes a SQL query and returns the results as an array of objects.
If succesful, the callback, if any, is called with the results.
var userSelect = document.getElementById('userSelect); db.executeSqlQuery("SELECT * FROM users", function(users) { for (var i = 0; i < users.length; ++i) { userSelect.add(new Option(user.name, user.rowid)); } });
- Parameters:
- {String|String[]|String[][]} sql
- sql statement
- {Function} callback Optional
- must be of the form function(results) where results will be an array of objects
nimbusly.Database.executeSqlUpdate(sql, callback)
Executes a SQL update statement,
If successful, the callback, if any, is called.
db.executeSqlUpdate(["UPDATE user SET password = ?", new_password], function() { alert("Password changed!"); });
- Parameters:
- {String|String[]|String[][]} sql
- sql statement(s) to execute
- {Function} callback Optional
- must be of the type function(), and is called on a successful update