Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

enable various node.js versions to be used

  • Loading branch information...
commit fa01728654215f81ec904f2d6998cc8ec8c3ff78 1 parent 806d7b4
Luke Bayas authored David Swift committed
Showing with 30 additions and 1 deletion.
  1. +13 −1 binding.cc
  2. +3 −0  binding.h
  3. +12 −0 query.cc
  4. +2 −0  query.h
View
14 binding.cc
@@ -10,6 +10,8 @@ node_db::Binding::~Binding() {
}
}
+uv_async_t node_db::Binding::g_async;
+
void node_db::Binding::Init(v8::Handle<v8::Object> target, v8::Persistent<v8::FunctionTemplate> constructorTemplate) {
NODE_ADD_CONSTANT(constructorTemplate, COLUMN_TYPE_STRING, node_db::Result::Column::STRING);
NODE_ADD_CONSTANT(constructorTemplate, COLUMN_TYPE_BOOL, node_db::Result::Column::BOOL);
@@ -88,7 +90,12 @@ v8::Handle<v8::Value> node_db::Binding::Connect(const v8::Arguments& args) {
req->data = request;
uv_queue_work(uv_default_loop(), req, uvConnect, uvConnectFinished);
- uv_ref(uv_default_loop());
+#if NODE_VERSION_AT_LEAST(0, 7, 9)
+ uv_ref((uv_handle_t *)&g_async);
+#else
+ uv_ref(uv_default_loop());
+#endif
+
} else {
connect(request);
connectFinished(request);
@@ -152,7 +159,12 @@ void node_db::Binding::uvConnectFinished(uv_work_t* uvRequest) {
connect_request_t* request = static_cast<connect_request_t*>(uvRequest->data);
assert(request);
+#if NODE_VERSION_AT_LEAST(0, 7, 9)
+ uv_unref((uv_handle_t *)&g_async);
+#else
uv_unref(uv_default_loop());
+#endif
+
request->binding->Unref();
connectFinished(request);
View
3  binding.h
@@ -2,7 +2,9 @@
#ifndef BINDING_H_
#define BINDING_H_
+#include <v8.h>
#include <node.h>
+#include <node_buffer.h>
#include <node_version.h>
#include <string>
#include "./node_defs.h"
@@ -33,6 +35,7 @@ class Binding : public EventEmitter {
static v8::Handle<v8::Value> Escape(const v8::Arguments& args);
static v8::Handle<v8::Value> Name(const v8::Arguments& args);
static v8::Handle<v8::Value> Query(const v8::Arguments& args);
+ static uv_async_t g_async;
static void uvConnect(uv_work_t* uvRequest);
static void uvConnectFinished(uv_work_t* uvRequest);
static void connect(connect_request_t* request);
View
12 query.cc
@@ -5,6 +5,8 @@
bool node_db::Query::gmtDeltaLoaded = false;
int node_db::Query::gmtDelta;
+uv_async_t node_db::Query::g_async;
+
void node_db::Query::Init(v8::Handle<v8::Object> target, v8::Persistent<v8::FunctionTemplate> constructorTemplate) {
NODE_ADD_PROTOTYPE_METHOD(constructorTemplate, "select", Select);
NODE_ADD_PROTOTYPE_METHOD(constructorTemplate, "from", From);
@@ -649,7 +651,12 @@ v8::Handle<v8::Value> node_db::Query::Execute(const v8::Arguments& args) {
req->data = request;
uv_queue_work(uv_default_loop(), req, uvExecute, uvExecuteFinished);
+#if NODE_VERSION_AT_LEAST(0, 7, 9)
+ uv_ref((uv_handle_t *)&g_async);
+#else
uv_ref(uv_default_loop());
+#endif
+
} else {
request->query->executeAsync(request);
}
@@ -813,7 +820,12 @@ void node_db::Query::uvExecuteFinished(uv_work_t* uvRequest) {
}
}
+#if NODE_VERSION_AT_LEAST(0, 7, 9)
+ uv_unref((uv_handle_t *)&g_async);
+#else
uv_unref(uv_default_loop());
+#endif
+
request->query->Unref();
Query::freeRequest(request);
View
2  query.h
@@ -2,6 +2,7 @@
#ifndef QUERY_H_
#define QUERY_H_
+#include <v8.h>
#include <stdlib.h>
#include <node.h>
#include <node_buffer.h>
@@ -66,6 +67,7 @@ class Query : public EventEmitter {
static v8::Handle<v8::Value> Delete(const v8::Arguments& args);
static v8::Handle<v8::Value> Sql(const v8::Arguments& args);
static v8::Handle<v8::Value> Execute(const v8::Arguments& args);
+ static uv_async_t g_async;
static void uvExecute(uv_work_t* uvRequest);
static void uvExecuteFinished(uv_work_t* uvRequest);
void executeAsync(execute_request_t* request);
Please sign in to comment.
Something went wrong with that request. Please try again.