diff --git a/src/binding.cc b/src/binding.cc index 1a432665..9d049a09 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -35,6 +35,7 @@ public: NODE_SET_PROTOTYPE_METHOD(t, "connect", Connect); NODE_SET_PROTOTYPE_METHOD(t, "_sendQuery", SendQuery); + NODE_SET_PROTOTYPE_METHOD(t, "end", End); target->Set(String::NewSymbol("Connection"), t->GetFunction()); LOG("created class"); @@ -83,6 +84,15 @@ public: return Undefined(); } + static Handle + End(const Arguments& args) + { + HandleScope scope; + Connection *self = ObjectWrap::Unwrap(args.This()); + + self->End(); + } + ev_io read_watcher_; ev_io write_watcher_; PGconn *connection_; @@ -257,6 +267,11 @@ protected: } } } + + void End() + { + PQfinish(connection_); + } private: void HandleConnectionIO() diff --git a/test/libpq/binding-spike.js b/test/libpq/binding-spike.js index f0844ba4..ad08bf7a 100644 --- a/test/libpq/binding-spike.js +++ b/test/libpq/binding-spike.js @@ -17,6 +17,7 @@ test('connecting with wrong parameters', function() { con.connect("user=asldfkj hostaddr=127.0.0.1 port=5432 dbname=asldkfj"); assert.emits(con, 'error', function(error) { console.log(error); + }) }); @@ -26,5 +27,8 @@ test('connects', function() { con.connect("user=brian hostaddr=127.0.0.1 port=5432 dbname=postgres"); assert.emits(con, 'connect', function() { con._sendQuery("SELECT NOW()"); + test('ends connection', function() { + con.end(); + }) }); })