Skip to content
Browse files

Partially update the sqlite3 driver to work on post net2 node. I fixe…

…d just enough to run a benchmark against orlandov's sqlite3 native driver.
  • Loading branch information...
1 parent 9682a05 commit 1898c3b1a92e5a4bd2c6b20d1260c4aec4815b68 @creationix committed Mar 30, 2010
Showing with 11 additions and 6 deletions.
  1. +11 −6 lib/persistence/sqlite.js
View
17 lib/persistence/sqlite.js
@@ -37,19 +37,22 @@ function parse(string) {
function Connection(path) {
- var child = process.createChildProcess("sqlite3", ['-interactive', '-header', '-nullvalue', "\r", '-separator', "\t", path]),
+ var child = require("child_process").spawn("sqlite3", ['-interactive', '-header', '-nullvalue', "\r", '-separator', "\t", path]),
queue = [], // Queue of sql requests
dequeued = 0, // Pointer used by the delayed shift mechanism
callback = null, // Callback for the query in progress
started, terminated, // Flags set when connection is verified and when close is called.
conn = this;
// Enable the timer footer so that we can detect zero length results
- child.write(".timer on\n");
+ child.stdin.write(".timer on\n");
// A inner state-machine that does all the queue logic. This needs to
// be called any time an event happens that may change the flow.
function cycle(string) {
+ if (typeof string === 'object') {
+ string = string.toString();
+ }
var next;
// Ignore nulls that get output from the child process.
@@ -96,13 +99,13 @@ function Connection(path) {
}
callback = next[1];
- child.write(next[0]);
+ child.stdin.write(next[0]);
}
}
- child.addListener("output", cycle);
+ child.stdout.addListener("data", cycle);
// If sqlite3 isn't in the path or the arguments are bad, this will trigger.
- child.addListener("error", function (data) {
+ child.stderr.addListener("data", function (data) {
// sys.debug("error: " + sys.inspect(data));
// Ignore the null that sometimes gets emitted on close
if (data) {
@@ -199,4 +202,6 @@ Connection.prototype.get_store = function (name, columns) {
exports.new_connection = function (connection_parameters) {
return new Connection(connection_parameters);
-}
+}
+
+

0 comments on commit 1898c3b

Please sign in to comment.
Something went wrong with that request. Please try again.