Skip to content

Commit

Permalink
Adds db.ping() (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
dresende committed Mar 4, 2013
1 parent 392535a commit af2f640
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Drivers/DML/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ Driver.prototype.drop = function (opts, cb) {
return require("../DDL/mysql").drop(this, opts, cb);
};

Driver.prototype.ping = function (cb) {
this.db.ping(cb);
return this;
};

Driver.prototype.on = function (ev, cb) {
if (ev == "error") {
this.db.on("error", cb);
Expand Down
7 changes: 7 additions & 0 deletions lib/Drivers/DML/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ Driver.prototype.drop = function (opts, cb) {
return require("../DDL/postgres").drop(this, opts, cb);
};

Driver.prototype.ping = function (cb) {
this.db.query("SELECT * FROM pg_stat_activity LIMIT 1", function () {
return cb();
});
return this;
};

Driver.prototype.on = function (ev, cb) {
if (ev == "error") {
this.db.on("error", cb);
Expand Down
8 changes: 8 additions & 0 deletions lib/Drivers/DML/postgresaxomic.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ Driver.prototype.sync = function (opts, cb) {
Driver.prototype.drop = function (opts, cb) {
return require("../DDL/postgres").drop(this, opts, cb);
};

Driver.prototype.ping = function (cb) {
this.db.query("SELECT * FROM pg_stat_activity LIMIT 1", function () {
return cb();
});
return this;
};

Driver.prototype.connect = function (cb) {
//console.log("connect called");
cb(null);
Expand Down
5 changes: 5 additions & 0 deletions lib/Drivers/DML/sqlite.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ Driver.prototype.drop = function (opts, cb) {
return require("../DDL/sqlite").drop(this, opts, cb);
};

Driver.prototype.ping = function (cb) {
process.nextTick(cb);
return this;
};

Driver.prototype.on = function (ev, cb) {
if (ev == "error") {
this.db.on("error", cb);
Expand Down
5 changes: 5 additions & 0 deletions lib/ORM.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ ORM.prototype.define = function (name, properties, opts) {
});
return this.models[name];
};
ORM.prototype.ping = function (cb) {
this.driver.ping(cb);

return this;
};
ORM.prototype.close = function (cb) {
this.driver.close(cb);

Expand Down
10 changes: 10 additions & 0 deletions test/integration/test-ping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var common = require('../common');
var assert = require('assert');

common.createConnection(function (err, db) {
db.ping(function (err) {
assert.equal(err, null);

db.close();
});
});

0 comments on commit af2f640

Please sign in to comment.