2014-04-16 10:40:55 -04:00
|
|
|
// WebSQL
|
|
|
|
// -------
|
|
|
|
var inherits = require('inherits');
|
2014-06-09 12:57:10 -04:00
|
|
|
var _ = require('lodash');
|
2014-04-16 10:40:55 -04:00
|
|
|
|
2014-05-05 21:53:09 -04:00
|
|
|
var Client_SQLite3 = require('../sqlite3/index');
|
2014-04-16 10:40:55 -04:00
|
|
|
var Promise = require('../../promise');
|
|
|
|
|
|
|
|
function Client_WebSQL(config) {
|
|
|
|
config = config || {};
|
|
|
|
Client_SQLite3.super_.apply(this, arguments);
|
|
|
|
if (config.debug) this.isDebugging = true;
|
|
|
|
this.name = config.name || 'knex_database';
|
2014-07-11 11:52:05 -04:00
|
|
|
this.version = config.version || '1.0';
|
|
|
|
this.displayName = config.displayName || this.name;
|
|
|
|
this.estimatedSize = config.estimatedSize || 5 * 1024 * 1024;
|
2014-04-16 10:40:55 -04:00
|
|
|
this.initDriver();
|
|
|
|
this.initRunner();
|
|
|
|
}
|
|
|
|
inherits(Client_WebSQL, Client_SQLite3);
|
|
|
|
|
|
|
|
Client_WebSQL.prototype.dialect = 'websql',
|
|
|
|
Client_WebSQL.prototype.initDriver = function() {};
|
|
|
|
Client_WebSQL.prototype.initPool = function() {};
|
|
|
|
Client_WebSQL.prototype.initMigrator = function() {};
|
|
|
|
|
|
|
|
// Initialize the query "runner"
|
|
|
|
Client_WebSQL.prototype.initRunner = function() {
|
|
|
|
require('./runner')(this);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Get a raw connection from the database, returning a promise with the connection object.
|
|
|
|
Client_WebSQL.prototype.acquireConnection = function() {
|
|
|
|
var client = this;
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
try {
|
2014-07-11 11:52:05 -04:00
|
|
|
var db = openDatabase(client.name, client.version, client.displayName, client.estimatedSize);
|
2014-05-05 21:53:09 -04:00
|
|
|
db.transaction(function(t) {
|
2014-05-05 22:00:29 -04:00
|
|
|
t.__cid = _.uniqueId('__cid');
|
|
|
|
resolve(t);
|
2014-05-05 21:53:09 -04:00
|
|
|
});
|
2014-04-16 10:40:55 -04:00
|
|
|
} catch (e) {
|
|
|
|
reject(e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Used to explicitly close a connection, called internally by the pool
|
|
|
|
// when a connection times out or the pool is shutdown.
|
|
|
|
Client_WebSQL.prototype.releaseConnection = Promise.method(function(connection) {});
|
|
|
|
|
|
|
|
module.exports = Client_WebSQL;
|