Skip to content

Commit 3b41060

Browse files
committed
first stab at 0.5.x compatibility
1 parent 9f039e8 commit 3b41060

9 files changed

Lines changed: 205 additions & 198 deletions

File tree

lib/sqlite3.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
var sqlite3 = module.exports = exports = require('./sqlite3_bindings');
1+
var sqlite3 = module.exports = exports = require('./sqlite3_bindings.node');
22
var path = require('path');
3+
var util = require('util');
34
var EventEmitter = require('events').EventEmitter;
45

56
var Database = sqlite3.Database;
@@ -148,6 +149,11 @@ Database.prototype.removeAllListeners = function(type) {
148149
return val;
149150
};
150151

152+
Database.prototype.emit = EventEmitter.prototype.emit;
153+
Database.prototype.once = EventEmitter.prototype.once;
154+
155+
// util.inherits(Database, EventEmitter);
156+
// util.inherits(Statement, EventEmitter);
151157

152158
// Save the stack trace over EIO callbacks.
153159
sqlite3.verbose = function() {

src/database.cc

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <string.h>
2-
#include <v8.h>
3-
#include <node.h>
4-
#include <node_events.h>
2+
#include <node/v8.h>
3+
#include <node/node.h>
54

65
#include "macros.h"
76
#include "database.h"
@@ -17,7 +16,6 @@ void Database::Init(Handle<Object> target) {
1716
Local<FunctionTemplate> t = FunctionTemplate::New(New);
1817

1918
constructor_template = Persistent<FunctionTemplate>::New(t);
20-
constructor_template->Inherit(EventEmitter::constructor_template);
2119
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
2220
constructor_template->SetClassName(String::NewSymbol("Database"));
2321

@@ -141,7 +139,7 @@ void Database::EIO_BeginOpen(Baton* baton) {
141139
eio_custom(EIO_Open, EIO_PRI_DEFAULT, EIO_AfterOpen, baton);
142140
}
143141

144-
int Database::EIO_Open(eio_req *req) {
142+
void Database::EIO_Open(eio_req *req) {
145143
OpenBaton* baton = static_cast<OpenBaton*>(req->data);
146144
Database* db = baton->db;
147145

@@ -161,8 +159,6 @@ int Database::EIO_Open(eio_req *req) {
161159
// Set default database handle values.
162160
sqlite3_busy_timeout(db->handle, 1000);
163161
}
164-
165-
return 0;
166162
}
167163

168164
int Database::EIO_AfterOpen(eio_req *req) {
@@ -225,7 +221,7 @@ void Database::EIO_BeginClose(Baton* baton) {
225221
eio_custom(EIO_Close, EIO_PRI_DEFAULT, EIO_AfterClose, baton);
226222
}
227223

228-
int Database::EIO_Close(eio_req *req) {
224+
void Database::EIO_Close(eio_req *req) {
229225
Baton* baton = static_cast<Baton*>(req->data);
230226
Database* db = baton->db;
231227

@@ -237,7 +233,6 @@ int Database::EIO_Close(eio_req *req) {
237233
else {
238234
db->handle = NULL;
239235
}
240-
return 0;
241236
}
242237

243238
int Database::EIO_AfterClose(eio_req *req) {
@@ -504,7 +499,7 @@ void Database::EIO_BeginExec(Baton* baton) {
504499
eio_custom(EIO_Exec, EIO_PRI_DEFAULT, EIO_AfterExec, baton);
505500
}
506501

507-
int Database::EIO_Exec(eio_req *req) {
502+
void Database::EIO_Exec(eio_req *req) {
508503
ExecBaton* baton = static_cast<ExecBaton*>(req->data);
509504

510505
char* message = NULL;
@@ -520,8 +515,6 @@ int Database::EIO_Exec(eio_req *req) {
520515
baton->message = std::string(message);
521516
sqlite3_free(message);
522517
}
523-
524-
return 0;
525518
}
526519

527520
int Database::EIO_AfterExec(eio_req *req) {
@@ -574,7 +567,7 @@ void Database::EIO_BeginLoadExtension(Baton* baton) {
574567
eio_custom(EIO_LoadExtension, EIO_PRI_DEFAULT, EIO_AfterLoadExtension, baton);
575568
}
576569

577-
int Database::EIO_LoadExtension(eio_req *req) {
570+
void Database::EIO_LoadExtension(eio_req *req) {
578571
LoadExtensionBaton* baton = static_cast<LoadExtensionBaton*>(req->data);
579572

580573
sqlite3_enable_load_extension(baton->db->handle, 1);
@@ -593,8 +586,6 @@ int Database::EIO_LoadExtension(eio_req *req) {
593586
baton->message = std::string(message);
594587
sqlite3_free(message);
595588
}
596-
597-
return 0;
598589
}
599590

600591
int Database::EIO_AfterLoadExtension(eio_req *req) {
@@ -673,13 +664,11 @@ void Database::Destruct(Persistent<Value> value, void *data) {
673664
}
674665
}
675666

676-
int Database::EIO_Destruct(eio_req *req) {
667+
void Database::EIO_Destruct(eio_req *req) {
677668
Database* db = static_cast<Database*>(req->data);
678669

679670
sqlite3_close(db->handle);
680671
db->handle = NULL;
681-
682-
return 0;
683672
}
684673

685674
int Database::EIO_AfterDestruct(eio_req *req) {

src/database.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#ifndef NODE_SQLITE3_SRC_DATABASE_H
22
#define NODE_SQLITE3_SRC_DATABASE_H
33

4-
#include <v8.h>
5-
#include <node.h>
6-
#include <node_events.h>
4+
#include <node/v8.h>
5+
#include <node/node.h>
76

87
#include <string>
98
#include <queue>
@@ -19,7 +18,7 @@ namespace node_sqlite3 {
1918
class Database;
2019

2120

22-
class Database : public EventEmitter {
21+
class Database : public ObjectWrap {
2322
public:
2423
static Persistent<FunctionTemplate> constructor_template;
2524
static void Init(Handle<Object> target);
@@ -100,7 +99,7 @@ class Database : public EventEmitter {
10099
friend class Statement;
101100

102101
protected:
103-
Database() : EventEmitter(),
102+
Database() : ObjectWrap(),
104103
handle(NULL),
105104
open(false),
106105
locked(false),
@@ -121,7 +120,7 @@ class Database : public EventEmitter {
121120

122121
static Handle<Value> New(const Arguments& args);
123122
static void EIO_BeginOpen(Baton* baton);
124-
static int EIO_Open(eio_req *req);
123+
static void EIO_Open(eio_req *req);
125124
static int EIO_AfterOpen(eio_req *req);
126125

127126
static Handle<Value> OpenGetter(Local<String> str, const AccessorInfo& accessor);
@@ -131,17 +130,17 @@ class Database : public EventEmitter {
131130

132131
static Handle<Value> Exec(const Arguments& args);
133132
static void EIO_BeginExec(Baton* baton);
134-
static int EIO_Exec(eio_req *req);
133+
static void EIO_Exec(eio_req *req);
135134
static int EIO_AfterExec(eio_req *req);
136135

137136
static Handle<Value> Close(const Arguments& args);
138137
static void EIO_BeginClose(Baton* baton);
139-
static int EIO_Close(eio_req *req);
138+
static void EIO_Close(eio_req *req);
140139
static int EIO_AfterClose(eio_req *req);
141140

142141
static Handle<Value> LoadExtension(const Arguments& args);
143142
static void EIO_BeginLoadExtension(Baton* baton);
144-
static int EIO_LoadExtension(eio_req *req);
143+
static void EIO_LoadExtension(eio_req *req);
145144
static int EIO_AfterLoadExtension(eio_req *req);
146145

147146
static Handle<Value> Serialize(const Arguments& args);
@@ -168,7 +167,7 @@ class Database : public EventEmitter {
168167
inline void MakeWeak();
169168
virtual void Unref();
170169
static void Destruct (Persistent<Value> value, void *data);
171-
static int EIO_Destruct(eio_req *req);
170+
static void EIO_Destruct(eio_req *req);
172171
static int EIO_AfterDestruct(eio_req *req);
173172

174173
protected:

src/macros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ const char* sqlite_authorizer_string(int type);
124124
#define EIO_DEFINITION(name) \
125125
static Handle<Value> name(const Arguments& args); \
126126
static void EIO_Begin##name(Baton* baton); \
127-
static int EIO_##name(eio_req *req); \
127+
static void EIO_##name(eio_req *req); \
128128
static int EIO_After##name(eio_req *req);
129129

130130
#define STATEMENT_BEGIN(type) \

src/sqlite3.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#include <v8.h>
22
#include <node.h>
3-
#include <node_events.h>
3+
#include <node_buffer.h>
44

5+
#include <stdint.h>
6+
#include <sstream>
7+
#include <cstring>
8+
#include <string>
59
#include <sqlite3.h>
610

711
#include "macros.h"
@@ -10,7 +14,9 @@
1014

1115
using namespace node_sqlite3;
1216

13-
extern "C" void init (v8::Handle<Object> target) {
17+
namespace {
18+
19+
void RegisterModule(v8::Handle<Object> target) {
1420
Database::Init(target);
1521
Statement::Init(target);
1622

@@ -52,6 +58,8 @@ extern "C" void init (v8::Handle<Object> target) {
5258
DEFINE_CONSTANT_INTEGER(target, SQLITE_NOTADB, NOTADB);
5359
}
5460

61+
}
62+
5563
const char* sqlite_code_string(int code) {
5664
switch (code) {
5765
case SQLITE_OK: return "SQLITE_OK";
@@ -95,3 +103,5 @@ const char* sqlite_authorizer_string(int type) {
95103
default: return "";
96104
}
97105
}
106+
107+
NODE_MODULE(sqlite3_bindings, RegisterModule);

0 commit comments

Comments
 (0)