omniql 0.5.7 → 0.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/binding.gyp ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "targets": [
3
+ {
4
+ "target_name": "omniql_bridge",
5
+ "sources": [ "src/omniql_bridge.cc" ],
6
+ "include_dirs": [
7
+ "<!@(node -p \"require('node-addon-api').include\")"
8
+ ],
9
+ "defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ],
10
+ "cflags!": [ "-fno-exceptions" ],
11
+ "cflags_cc!": [ "-fno-exceptions" ],
12
+ "conditions": [
13
+ ['OS=="mac"', {
14
+ "xcode_settings": {
15
+ "GCC_ENABLE_CPP_EXCEPTIONS": "YES",
16
+ "CLANG_CXX_LIBRARY": "libc++",
17
+ "MACOSX_DEPLOYMENT_TARGET": "10.15"
18
+ }
19
+ }]
20
+ ]
21
+ }
22
+ ]
23
+ }
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "omniql",
3
- "version": "0.5.7",
3
+ "version": "0.5.9",
4
4
  "description": "A standardized, multi-database query language (OQL) for TypeScript/Node.js.",
5
5
  "main": "dist/omniql.js",
6
6
  "types": "dist/omniql.d.ts",
7
7
  "files": [
8
8
  "dist",
9
+ "src",
10
+ "binding.gyp",
9
11
  "*.so",
10
12
  "*.dll",
11
13
  "*.dylib"
@@ -0,0 +1,194 @@
1
+ #include <napi.h>
2
+ #include <uv.h>
3
+ #include <dlfcn.h>
4
+ #include <signal.h>
5
+ #include <iostream>
6
+ #include <vector>
7
+
8
+ // Define function pointers for the Go exported functions
9
+ typedef int (*OmniQL_NewEngine_t)();
10
+ typedef void (*OmniQL_FreeEngine_t)(int);
11
+ typedef char* (*OmniQL_Execute_t)(int, char*);
12
+ typedef char* (*OmniQL_RegisterSchema_t)(int, char*);
13
+ typedef char* (*OmniQL_Route_t)(int, char*, char*);
14
+ typedef char* (*OmniQL_RegisterSQLiteDriver_t)(int, char*);
15
+ typedef char* (*OmniQL_RegisterPostgresDriver_t)(int, char*);
16
+ typedef char* (*OmniQL_RegisterMongoDriver_t)(int, char*, char*);
17
+ typedef void (*OmniQL_Free_t)(char*);
18
+
19
+ // Global function pointers
20
+ OmniQL_NewEngine_t ptr_NewEngine = nullptr;
21
+ OmniQL_FreeEngine_t ptr_FreeEngine = nullptr;
22
+ OmniQL_Execute_t ptr_Execute = nullptr;
23
+ OmniQL_RegisterSchema_t ptr_RegisterSchema = nullptr;
24
+ OmniQL_Route_t ptr_Route = nullptr;
25
+ OmniQL_RegisterSQLiteDriver_t ptr_RegisterSQLiteDriver = nullptr;
26
+ OmniQL_RegisterPostgresDriver_t ptr_RegisterPostgresDriver = nullptr;
27
+ OmniQL_RegisterMongoDriver_t ptr_RegisterMongoDriver = nullptr;
28
+ OmniQL_Free_t ptr_Free = nullptr;
29
+
30
+ void* lib_handle = nullptr;
31
+
32
+ // Helper to load the library and symbols
33
+ void LoadLib(const Napi::CallbackInfo& info) {
34
+ Napi::Env env = info.Env();
35
+
36
+ if (info.Length() < 1 || !info[0].IsString()) {
37
+ Napi::TypeError::New(env, "String expected for library path").ThrowAsJavaScriptException();
38
+ return;
39
+ }
40
+
41
+ std::string libPath = info[0].As<Napi::String>().Utf8Value();
42
+
43
+ // CRITICAL FIX: Ignore SIGURG before loading Go.
44
+ // Go uses SIGURG for preemptive scheduling. Node.js/libuv doesn't like unexpected signals.
45
+ signal(SIGURG, SIG_IGN);
46
+
47
+ // Open the shared library
48
+ // RTLD_GLOBAL is important if the Go runtime needs to see symbols from other loaded libs,
49
+ // or if we load multiple plugins. RTLD_NOW ensures we fail fast if symbols are missing.
50
+ lib_handle = dlopen(libPath.c_str(), RTLD_NOW | RTLD_GLOBAL);
51
+
52
+ if (!lib_handle) {
53
+ std::string err = "Failed to load library: " + std::string(dlerror());
54
+ Napi::Error::New(env, err).ThrowAsJavaScriptException();
55
+ return;
56
+ }
57
+
58
+ // Load symbols
59
+ ptr_NewEngine = (OmniQL_NewEngine_t)dlsym(lib_handle, "OmniQL_NewEngine");
60
+ ptr_FreeEngine = (OmniQL_FreeEngine_t)dlsym(lib_handle, "OmniQL_FreeEngine");
61
+ ptr_Execute = (OmniQL_Execute_t)dlsym(lib_handle, "OmniQL_Execute");
62
+ ptr_RegisterSchema = (OmniQL_RegisterSchema_t)dlsym(lib_handle, "OmniQL_RegisterSchema");
63
+ ptr_Route = (OmniQL_Route_t)dlsym(lib_handle, "OmniQL_Route");
64
+ ptr_RegisterSQLiteDriver = (OmniQL_RegisterSQLiteDriver_t)dlsym(lib_handle, "OmniQL_RegisterSQLiteDriver");
65
+ ptr_RegisterPostgresDriver = (OmniQL_RegisterPostgresDriver_t)dlsym(lib_handle, "OmniQL_RegisterPostgresDriver");
66
+ ptr_RegisterMongoDriver = (OmniQL_RegisterMongoDriver_t)dlsym(lib_handle, "OmniQL_RegisterMongoDriver");
67
+ ptr_Free = (OmniQL_Free_t)dlsym(lib_handle, "OmniQL_Free");
68
+
69
+ if (!ptr_NewEngine) {
70
+ Napi::Error::New(env, "Failed to load symbols from library").ThrowAsJavaScriptException();
71
+ return;
72
+ }
73
+ }
74
+
75
+ Napi::Number NewEngine(const Napi::CallbackInfo& info) {
76
+ Napi::Env env = info.Env();
77
+ if (!ptr_NewEngine) return Napi::Number::New(env, 0);
78
+ return Napi::Number::New(env, ptr_NewEngine());
79
+ }
80
+
81
+ void FreeEngine(const Napi::CallbackInfo& info) {
82
+ if (!ptr_FreeEngine) return;
83
+ int handle = info[0].As<Napi::Number>().Int32Value();
84
+ ptr_FreeEngine(handle);
85
+ }
86
+
87
+ Napi::String Execute(const Napi::CallbackInfo& info) {
88
+ Napi::Env env = info.Env();
89
+ int handle = info[0].As<Napi::Number>().Int32Value();
90
+ std::string query = info[1].As<Napi::String>().Utf8Value();
91
+
92
+ // Go expects a non-const char* (though it treats it as const usually),
93
+ // but our typedef says char*. We cast to be safe.
94
+ char* res = ptr_Execute(handle, const_cast<char*>(query.c_str()));
95
+
96
+ std::string resultStr = "{}";
97
+ if (res) {
98
+ resultStr = std::string(res);
99
+ ptr_Free(res);
100
+ }
101
+ return Napi::String::New(env, resultStr);
102
+ }
103
+
104
+ Napi::String RegisterMongoDriver(const Napi::CallbackInfo& info) {
105
+ Napi::Env env = info.Env();
106
+ int handle = info[0].As<Napi::Number>().Int32Value();
107
+ std::string uri = info[1].As<Napi::String>().Utf8Value();
108
+ std::string dbName = info[2].As<Napi::String>().Utf8Value();
109
+
110
+ char* res = ptr_RegisterMongoDriver(handle, const_cast<char*>(uri.c_str()), const_cast<char*>(dbName.c_str()));
111
+
112
+ std::string resultStr = "{}";
113
+ if (res) {
114
+ resultStr = std::string(res);
115
+ ptr_Free(res);
116
+ }
117
+ return Napi::String::New(env, resultStr);
118
+ }
119
+
120
+ Napi::String RegisterSQLiteDriver(const Napi::CallbackInfo& info) {
121
+ Napi::Env env = info.Env();
122
+ int handle = info[0].As<Napi::Number>().Int32Value();
123
+ std::string dsn = info[1].As<Napi::String>().Utf8Value();
124
+
125
+ char* res = ptr_RegisterSQLiteDriver(handle, const_cast<char*>(dsn.c_str()));
126
+
127
+ std::string resultStr = "{}";
128
+ if (res) {
129
+ resultStr = std::string(res);
130
+ ptr_Free(res);
131
+ }
132
+ return Napi::String::New(env, resultStr);
133
+ }
134
+
135
+ Napi::String RegisterPostgresDriver(const Napi::CallbackInfo& info) {
136
+ Napi::Env env = info.Env();
137
+ int handle = info[0].As<Napi::Number>().Int32Value();
138
+ std::string conn = info[1].As<Napi::String>().Utf8Value();
139
+
140
+ char* res = ptr_RegisterPostgresDriver(handle, const_cast<char*>(conn.c_str()));
141
+
142
+ std::string resultStr = "{}";
143
+ if (res) {
144
+ resultStr = std::string(res);
145
+ ptr_Free(res);
146
+ }
147
+ return Napi::String::New(env, resultStr);
148
+ }
149
+
150
+ Napi::String RegisterSchema(const Napi::CallbackInfo& info) {
151
+ Napi::Env env = info.Env();
152
+ int handle = info[0].As<Napi::Number>().Int32Value();
153
+ std::string schema = info[1].As<Napi::String>().Utf8Value();
154
+
155
+ char* res = ptr_RegisterSchema(handle, const_cast<char*>(schema.c_str()));
156
+
157
+ std::string resultStr = "{}";
158
+ if (res) {
159
+ resultStr = std::string(res);
160
+ ptr_Free(res);
161
+ }
162
+ return Napi::String::New(env, resultStr);
163
+ }
164
+
165
+ Napi::String Route(const Napi::CallbackInfo& info) {
166
+ Napi::Env env = info.Env();
167
+ int handle = info[0].As<Napi::Number>().Int32Value();
168
+ std::string target = info[1].As<Napi::String>().Utf8Value();
169
+ std::string driver = info[2].As<Napi::String>().Utf8Value();
170
+
171
+ char* res = ptr_Route(handle, const_cast<char*>(target.c_str()), const_cast<char*>(driver.c_str()));
172
+
173
+ std::string resultStr = "{}";
174
+ if (res) {
175
+ resultStr = std::string(res);
176
+ ptr_Free(res);
177
+ }
178
+ return Napi::String::New(env, resultStr);
179
+ }
180
+
181
+ Napi::Object Init(Napi::Env env, Napi::Object exports) {
182
+ exports.Set("loadLib", Napi::Function::New(env, LoadLib));
183
+ exports.Set("newEngine", Napi::Function::New(env, NewEngine));
184
+ exports.Set("freeEngine", Napi::Function::New(env, FreeEngine));
185
+ exports.Set("execute", Napi::Function::New(env, Execute));
186
+ exports.Set("registerMongoDriver", Napi::Function::New(env, RegisterMongoDriver));
187
+ exports.Set("registerSQLiteDriver", Napi::Function::New(env, RegisterSQLiteDriver));
188
+ exports.Set("registerPostgresDriver", Napi::Function::New(env, RegisterPostgresDriver));
189
+ exports.Set("registerSchema", Napi::Function::New(env, RegisterSchema));
190
+ exports.Set("route", Napi::Function::New(env, Route));
191
+ return exports;
192
+ }
193
+
194
+ NODE_API_MODULE(omniql_bridge, Init)