Commit ef859feb by Orlando Vazquez

tentatively remove query queuing since it may not be exactly require

parent 30507228
...@@ -20,39 +20,38 @@ var sqlite = require("./sqlite3_bindings"); ...@@ -20,39 +20,38 @@ var sqlite = require("./sqlite3_bindings");
var Database = exports.Database = function () { var Database = exports.Database = function () {
var self = this; var self = this;
this.queue = [];
this.driver = new sqlite.Database();
this.driver.addListener("ready", function () {
self.dispatch();
});
};
Database.prototype.dispatch = function () { var db = new sqlite.Database();
if (!this.queue || this.currentQuery db.__proto__ = Database.prototype;
|| !this.queue.length) {
return;
}
this.currentQuery = this.queue.shift();
this.executeQuery.apply(this, this.currentQuery);
}
Database.prototype.open = function () { // this.queue = [];
this.driver.open.apply(this.driver, arguments); //
} // this.addListener("ready", function () {
// db.dispatch();
// });
Database.prototype.close = function () { return db;
this.driver.close.apply(this.driver, arguments); };
}
Database.prototype.prepare = function () { Database.prototype = {
this.driver.prepare.apply(this.driver, arguments); __proto__: sqlite.Database.prototype,
} constructor: Database,
};
Database.prototype.query = function (sql, bindings, queryCallback) { // Database.prototype.dispatch = function () {
this.queue = this.queue || []; // if (!this.queue || this.currentQuery
this.queue.push([sql, bindings, queryCallback]); // || !this.queue.length) {
this.dispatch(); // return;
} // }
// this.currentQuery = this.queue.shift();
// this.executeQuery.apply(this, this.currentQuery);
// }
// Database.prototype.query = function (sql, bindings, queryCallback) {
// this.queue = this.queue || [];
// this.queue.push([sql, bindings, queryCallback]);
// this.dispatch();
// }
// Iterate over the list of bindings. Since we can't use something as // Iterate over the list of bindings. Since we can't use something as
// simple as a for or while loop, we'll just chain them via the event loop // simple as a for or while loop, we'll just chain them via the event loop
...@@ -75,7 +74,7 @@ function _setBindingsByIndex(db, ...@@ -75,7 +74,7 @@ function _setBindingsByIndex(db,
function _queryDone(db, statement) { function _queryDone(db, statement) {
if (statement.tail) { if (statement.tail) {
statement.finalize(function () { statement.finalize(function () {
db.driver.prepare(statement.tail, onPrepare); db.prepare(statement.tail, onPrepare);
}); });
return; return;
} }
...@@ -83,7 +82,7 @@ function _queryDone(db, statement) { ...@@ -83,7 +82,7 @@ function _queryDone(db, statement) {
statement.finalize(function () { statement.finalize(function () {
db.currentQuery = undefined; db.currentQuery = undefined;
// if there are any queries queued, let them know it's safe to go // if there are any queries queued, let them know it's safe to go
db.driver.emit("ready"); db.emit("ready");
}); });
} }
...@@ -116,7 +115,7 @@ function _onPrepare(db, statement, bindings, rowCallback) { ...@@ -116,7 +115,7 @@ function _onPrepare(db, statement, bindings, rowCallback) {
} }
} }
Database.prototype.executeQuery = function(sql, bindings, rowCallback) { Database.prototype.query = function(sql, bindings, rowCallback) {
var self = this; var self = this;
if (typeof(bindings) == "function") { if (typeof(bindings) == "function") {
...@@ -124,7 +123,7 @@ Database.prototype.executeQuery = function(sql, bindings, rowCallback) { ...@@ -124,7 +123,7 @@ Database.prototype.executeQuery = function(sql, bindings, rowCallback) {
bindings = []; bindings = [];
} }
this.driver.prepare(sql, function(error, statement) { this.prepare(sql, function(error, statement) {
if (error) throw error; if (error) throw error;
if (statement) { if (statement) {
_onPrepare(self, statement, bindings, rowCallback) _onPrepare(self, statement, bindings, rowCallback)
...@@ -132,7 +131,7 @@ Database.prototype.executeQuery = function(sql, bindings, rowCallback) { ...@@ -132,7 +131,7 @@ Database.prototype.executeQuery = function(sql, bindings, rowCallback) {
rowCallback(); rowCallback();
self.currentQuery = undefined; self.currentQuery = undefined;
// if there are any queries queued, let them know it's safe to go // if there are any queries queued, let them know it's safe to go
self.dispatch(); // self.dispatch();
} }
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment