forked from sqlanywhere/node-sqlanywhere
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsqlanywhere.cpp
More file actions
59 lines (47 loc) · 1.92 KB
/
sqlanywhere.cpp
File metadata and controls
59 lines (47 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// ***************************************************************************
// Copyright (c) 2021 SAP SE or an SAP affiliate company. All rights reserved.
// ***************************************************************************
#include "napi.h"
#include "h/sqlany_utils.h"
#include "h/connection.h"
#include "h/stmt.h"
// Global variables
SQLAnywhereInterface api;
unsigned openConnections = 0;
uv_mutex_t api_mutex;
// Global flag for debug logging, off by default
bool g_debug_logging = false;
// N-API function to set the debug logging flag from JavaScript
Napi::Value SetDebugLogging(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
if (info.Length() < 1 || !info[0].IsBoolean()) {
Napi::TypeError::New(env, "Boolean expected")
.ThrowAsJavaScriptException();
return env.Undefined();
}
g_debug_logging = info[0].As<Napi::Boolean>().Value();
return env.Undefined();
}
// Addon entry point
Napi::Object Init(Napi::Env env, Napi::Object exports) {
uv_mutex_init(&api_mutex);
if (!sqlany_initialize_interface(&api, NULL)) {
Napi::Error::New(env, "Could not initialize the SQL Anywhere C API interface.")
.ThrowAsJavaScriptException();
return exports;
}
if (!api.sqlany_init("node-sqlanywhere", SQLANY_API_VERSION_4, NULL)) {
Napi::Error::New(env, "Failed to initialize the SQL Anywhere C API.")
.ThrowAsJavaScriptException();
return exports;
}
Connection::Init(env, exports);
StmtObject::Init(env, exports);
// Create a top-level createConnection function for convenience
Napi::Function conn_constructor = exports.Get("Connection").As<Napi::Function>();
exports.Set("createConnection", conn_constructor);
// Export the new debug logging function
exports.Set("debugLogging", Napi::Function::New(env, SetDebugLogging));
return exports;
}
NODE_API_MODULE(sqlanywhere, Init)