knex/lib/dialects/websql/index.js

58 lines
1.7 KiB
JavaScript
Raw Normal View History

'use strict';
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
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();
2014-07-17 08:34:53 -04:00
this.transaction = function () {
return this;
};
2014-04-16 10:40:55 -04:00
}
inherits(Client_WebSQL, Client_SQLite3);
2014-09-02 22:03:14 +02:00
Client_WebSQL.prototype.dialect = 'websql';
2014-04-16 10:40:55 -04:00
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 {
/*jslint browser: true*/
2014-07-11 11:52:05 -04:00
var db = openDatabase(client.name, client.version, client.displayName, client.estimatedSize);
db.transaction(function(t) {
2014-05-05 22:00:29 -04:00
t.__cid = _.uniqueId('__cid');
resolve(t);
});
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() {});
2014-04-16 10:40:55 -04:00
module.exports = Client_WebSQL;