omniql 0.5.2 → 0.5.3
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/dist/omniql.d.ts +15 -44
- package/dist/omniql.js +53 -71
- package/package.json +2 -5
package/dist/omniql.d.ts
CHANGED
|
@@ -2,36 +2,16 @@
|
|
|
2
2
|
* OmniQL TypeScript / Node.js Binding
|
|
3
3
|
* =====================================
|
|
4
4
|
*
|
|
5
|
-
* A Node.js
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Build the native library first:
|
|
9
|
-
* go build -buildmode=c-shared -o libomniql.so ../../pkg/ffi
|
|
10
|
-
*
|
|
11
|
-
* Install:
|
|
12
|
-
* npm install
|
|
5
|
+
* A modern, low-friction Node.js binding built with Koffi that wraps the
|
|
6
|
+
* OmniQL shared library.
|
|
13
7
|
*
|
|
14
8
|
* Example usage:
|
|
15
|
-
* import { OmniEngine
|
|
9
|
+
* import { OmniEngine } from 'omniql';
|
|
16
10
|
*
|
|
17
11
|
* const engine = new OmniEngine();
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* const
|
|
21
|
-
* engine.route('analytics_data', driverName);
|
|
22
|
-
*
|
|
23
|
-
* // 2. Execute a query.
|
|
24
|
-
* const result = await engine.execute({
|
|
25
|
-
* target: 'analytics_data',
|
|
26
|
-
* action: 'FIND',
|
|
27
|
-
* filter: {
|
|
28
|
-
* category: { $in: ['electronics', 'books'] },
|
|
29
|
-
* price: { $lt: 500 },
|
|
30
|
-
* },
|
|
31
|
-
* options: { limit: 20 },
|
|
32
|
-
* });
|
|
33
|
-
*
|
|
34
|
-
* console.log(result.data);
|
|
12
|
+
* const driver = engine.registerSQLiteDriver(':memory:');
|
|
13
|
+
* engine.route('data', driver);
|
|
14
|
+
* const result = await engine.execute({ target: 'data', action: 'FIND' });
|
|
35
15
|
* engine.close();
|
|
36
16
|
*/
|
|
37
17
|
export type Action = 'FIND' | 'INSERT' | 'UPDATE' | 'DELETE' | 'COUNT';
|
|
@@ -73,14 +53,14 @@ export interface CollectionSchema {
|
|
|
73
53
|
required?: boolean;
|
|
74
54
|
}>;
|
|
75
55
|
}
|
|
76
|
-
/**
|
|
77
|
-
* OmniEngine is the main entry-point for the OmniQL TypeScript binding.
|
|
78
|
-
*
|
|
79
|
-
* All `execute` calls are async and safe to use with `await`.
|
|
80
|
-
*/
|
|
81
56
|
export declare class OmniEngine {
|
|
82
57
|
private readonly handle;
|
|
83
58
|
constructor();
|
|
59
|
+
/**
|
|
60
|
+
* Internal helper to call native functions that return a JSON string
|
|
61
|
+
* and need to be freed.
|
|
62
|
+
*/
|
|
63
|
+
private callNative;
|
|
84
64
|
/**
|
|
85
65
|
* Executes an OQL query and returns the OmniJSON result.
|
|
86
66
|
*/
|
|
@@ -91,31 +71,22 @@ export declare class OmniEngine {
|
|
|
91
71
|
registerSchema(schema: CollectionSchema): void;
|
|
92
72
|
/**
|
|
93
73
|
* Binds a collection/table target name to a driver name.
|
|
94
|
-
* Must be called after registering a driver.
|
|
95
|
-
*
|
|
96
|
-
* @param target The collection or table name.
|
|
97
|
-
* @param driverName The driver name returned by a registerXxxDriver call.
|
|
98
74
|
*/
|
|
99
75
|
route(target: string, driverName: string): void;
|
|
100
76
|
/**
|
|
101
|
-
* Registers a SQLite driver
|
|
102
|
-
* Returns the driver name ("sqlite") to use with {@link route}.
|
|
77
|
+
* Registers a SQLite driver.
|
|
103
78
|
*/
|
|
104
79
|
registerSQLiteDriver(dsn: string): string;
|
|
105
80
|
/**
|
|
106
|
-
* Registers a PostgreSQL driver
|
|
107
|
-
* e.g. "host=localhost user=pg password=pg dbname=mydb sslmode=disable"
|
|
108
|
-
* Returns the driver name ("postgres") to use with {@link route}.
|
|
81
|
+
* Registers a PostgreSQL driver.
|
|
109
82
|
*/
|
|
110
83
|
registerPostgresDriver(connStr: string): string;
|
|
111
84
|
/**
|
|
112
|
-
* Registers a MongoDB driver
|
|
113
|
-
* e.g. uri = "mongodb://localhost:27017", dbName = "mydb"
|
|
114
|
-
* Returns the driver name ("mongo") to use with {@link route}.
|
|
85
|
+
* Registers a MongoDB driver.
|
|
115
86
|
*/
|
|
116
87
|
registerMongoDriver(uri: string, dbName: string): string;
|
|
117
88
|
/**
|
|
118
|
-
* Releases the native engine handle.
|
|
89
|
+
* Releases the native engine handle.
|
|
119
90
|
*/
|
|
120
91
|
close(): void;
|
|
121
92
|
}
|
package/dist/omniql.js
CHANGED
|
@@ -3,36 +3,16 @@
|
|
|
3
3
|
* OmniQL TypeScript / Node.js Binding
|
|
4
4
|
* =====================================
|
|
5
5
|
*
|
|
6
|
-
* A Node.js
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* Build the native library first:
|
|
10
|
-
* go build -buildmode=c-shared -o libomniql.so ../../pkg/ffi
|
|
11
|
-
*
|
|
12
|
-
* Install:
|
|
13
|
-
* npm install
|
|
6
|
+
* A modern, low-friction Node.js binding built with Koffi that wraps the
|
|
7
|
+
* OmniQL shared library.
|
|
14
8
|
*
|
|
15
9
|
* Example usage:
|
|
16
|
-
* import { OmniEngine
|
|
10
|
+
* import { OmniEngine } from 'omniql';
|
|
17
11
|
*
|
|
18
12
|
* const engine = new OmniEngine();
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* const
|
|
22
|
-
* engine.route('analytics_data', driverName);
|
|
23
|
-
*
|
|
24
|
-
* // 2. Execute a query.
|
|
25
|
-
* const result = await engine.execute({
|
|
26
|
-
* target: 'analytics_data',
|
|
27
|
-
* action: 'FIND',
|
|
28
|
-
* filter: {
|
|
29
|
-
* category: { $in: ['electronics', 'books'] },
|
|
30
|
-
* price: { $lt: 500 },
|
|
31
|
-
* },
|
|
32
|
-
* options: { limit: 20 },
|
|
33
|
-
* });
|
|
34
|
-
*
|
|
35
|
-
* console.log(result.data);
|
|
13
|
+
* const driver = engine.registerSQLiteDriver(':memory:');
|
|
14
|
+
* engine.route('data', driver);
|
|
15
|
+
* const result = await engine.execute({ target: 'data', action: 'FIND' });
|
|
36
16
|
* engine.close();
|
|
37
17
|
*/
|
|
38
18
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
@@ -70,7 +50,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
70
50
|
})();
|
|
71
51
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
72
52
|
exports.OmniEngine = void 0;
|
|
73
|
-
const
|
|
53
|
+
const koffi = __importStar(require("koffi"));
|
|
74
54
|
const path = __importStar(require("path"));
|
|
75
55
|
const fs = __importStar(require("fs"));
|
|
76
56
|
// ---------------------------------------------------------------------------
|
|
@@ -80,40 +60,51 @@ const LIB_SEARCH_PATHS = [
|
|
|
80
60
|
path.join(__dirname, 'libomniql.so'),
|
|
81
61
|
path.join(__dirname, 'libomniql.dylib'),
|
|
82
62
|
path.join(__dirname, 'omniql.dll'),
|
|
83
|
-
'libomniql',
|
|
63
|
+
path.join(process.cwd(), 'libomniql.so'),
|
|
64
|
+
path.join(process.cwd(), 'libomniql.dylib'),
|
|
65
|
+
path.join(process.cwd(), 'omniql.dll'),
|
|
84
66
|
];
|
|
85
|
-
function
|
|
67
|
+
function findLibPath() {
|
|
86
68
|
for (const p of LIB_SEARCH_PATHS) {
|
|
87
|
-
if (fs.existsSync(p))
|
|
88
|
-
return
|
|
89
|
-
OmniQL_NewEngine: ['int', []],
|
|
90
|
-
OmniQL_FreeEngine: ['void', ['int']],
|
|
91
|
-
OmniQL_Execute: ['string', ['int', 'string']],
|
|
92
|
-
OmniQL_RegisterSchema: ['string', ['int', 'string']],
|
|
93
|
-
OmniQL_Route: ['string', ['int', 'string', 'string']],
|
|
94
|
-
OmniQL_RegisterSQLiteDriver: ['string', ['int', 'string']],
|
|
95
|
-
OmniQL_RegisterPostgresDriver: ['string', ['int', 'string']],
|
|
96
|
-
OmniQL_RegisterMongoDriver: ['string', ['int', 'string', 'string']],
|
|
97
|
-
OmniQL_Free: ['void', ['pointer']],
|
|
98
|
-
});
|
|
99
|
-
}
|
|
69
|
+
if (fs.existsSync(p))
|
|
70
|
+
return p;
|
|
100
71
|
}
|
|
101
72
|
throw new Error('OmniQL native library not found. ' +
|
|
102
|
-
'
|
|
73
|
+
'Please ensure libomniql.so/dylib/dll is present in the package or CWD.');
|
|
103
74
|
}
|
|
104
|
-
const lib =
|
|
75
|
+
const lib = koffi.load(findLibPath());
|
|
76
|
+
// Function definitions
|
|
77
|
+
const OmniQL_NewEngine = lib.func('int OmniQL_NewEngine()');
|
|
78
|
+
const OmniQL_FreeEngine = lib.func('void OmniQL_FreeEngine(int)');
|
|
79
|
+
const OmniQL_Execute = lib.func('char *OmniQL_Execute(int, const char *)');
|
|
80
|
+
const OmniQL_RegisterSchema = lib.func('char *OmniQL_RegisterSchema(int, const char *)');
|
|
81
|
+
const OmniQL_Route = lib.func('char *OmniQL_Route(int, const char *, const char *)');
|
|
82
|
+
const OmniQL_RegisterSQLiteDriver = lib.func('char *OmniQL_RegisterSQLiteDriver(int, const char *)');
|
|
83
|
+
const OmniQL_RegisterPostgresDriver = lib.func('char *OmniQL_RegisterPostgresDriver(int, const char *)');
|
|
84
|
+
const OmniQL_RegisterMongoDriver = lib.func('char *OmniQL_RegisterMongoDriver(int, const char *, const char *)');
|
|
85
|
+
const OmniQL_Free = lib.func('void OmniQL_Free(void *)');
|
|
105
86
|
// ---------------------------------------------------------------------------
|
|
106
87
|
// OmniEngine class
|
|
107
88
|
// ---------------------------------------------------------------------------
|
|
108
|
-
/**
|
|
109
|
-
* OmniEngine is the main entry-point for the OmniQL TypeScript binding.
|
|
110
|
-
*
|
|
111
|
-
* All `execute` calls are async and safe to use with `await`.
|
|
112
|
-
*/
|
|
113
89
|
class OmniEngine {
|
|
114
90
|
handle;
|
|
115
91
|
constructor() {
|
|
116
|
-
this.handle =
|
|
92
|
+
this.handle = OmniQL_NewEngine();
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Internal helper to call native functions that return a JSON string
|
|
96
|
+
* and need to be freed.
|
|
97
|
+
*/
|
|
98
|
+
callNative(fn, ...args) {
|
|
99
|
+
const raw = fn(this.handle, ...args);
|
|
100
|
+
if (!raw)
|
|
101
|
+
return '{}';
|
|
102
|
+
try {
|
|
103
|
+
return koffi.decode(raw, 'char *');
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
OmniQL_Free(raw);
|
|
107
|
+
}
|
|
117
108
|
}
|
|
118
109
|
/**
|
|
119
110
|
* Executes an OQL query and returns the OmniJSON result.
|
|
@@ -123,8 +114,8 @@ class OmniEngine {
|
|
|
123
114
|
const json = JSON.stringify(queryWithDefaults);
|
|
124
115
|
return new Promise((resolve, reject) => {
|
|
125
116
|
try {
|
|
126
|
-
const
|
|
127
|
-
resolve(JSON.parse(
|
|
117
|
+
const rawResponse = this.callNative(OmniQL_Execute, json);
|
|
118
|
+
resolve(JSON.parse(rawResponse));
|
|
128
119
|
}
|
|
129
120
|
catch (err) {
|
|
130
121
|
reject(err);
|
|
@@ -135,49 +126,40 @@ class OmniEngine {
|
|
|
135
126
|
* Registers a collection schema with the engine.
|
|
136
127
|
*/
|
|
137
128
|
registerSchema(schema) {
|
|
138
|
-
|
|
129
|
+
this.callNative(OmniQL_RegisterSchema, JSON.stringify(schema));
|
|
139
130
|
}
|
|
140
131
|
/**
|
|
141
132
|
* Binds a collection/table target name to a driver name.
|
|
142
|
-
* Must be called after registering a driver.
|
|
143
|
-
*
|
|
144
|
-
* @param target The collection or table name.
|
|
145
|
-
* @param driverName The driver name returned by a registerXxxDriver call.
|
|
146
133
|
*/
|
|
147
134
|
route(target, driverName) {
|
|
148
|
-
|
|
135
|
+
this.callNative(OmniQL_Route, target, driverName);
|
|
149
136
|
}
|
|
150
137
|
/**
|
|
151
|
-
* Registers a SQLite driver
|
|
152
|
-
* Returns the driver name ("sqlite") to use with {@link route}.
|
|
138
|
+
* Registers a SQLite driver.
|
|
153
139
|
*/
|
|
154
140
|
registerSQLiteDriver(dsn) {
|
|
155
|
-
const raw =
|
|
141
|
+
const raw = this.callNative(OmniQL_RegisterSQLiteDriver, dsn);
|
|
156
142
|
return JSON.parse(raw).driver ?? 'sqlite';
|
|
157
143
|
}
|
|
158
144
|
/**
|
|
159
|
-
* Registers a PostgreSQL driver
|
|
160
|
-
* e.g. "host=localhost user=pg password=pg dbname=mydb sslmode=disable"
|
|
161
|
-
* Returns the driver name ("postgres") to use with {@link route}.
|
|
145
|
+
* Registers a PostgreSQL driver.
|
|
162
146
|
*/
|
|
163
147
|
registerPostgresDriver(connStr) {
|
|
164
|
-
const raw =
|
|
148
|
+
const raw = this.callNative(OmniQL_RegisterPostgresDriver, connStr);
|
|
165
149
|
return JSON.parse(raw).driver ?? 'postgres';
|
|
166
150
|
}
|
|
167
151
|
/**
|
|
168
|
-
* Registers a MongoDB driver
|
|
169
|
-
* e.g. uri = "mongodb://localhost:27017", dbName = "mydb"
|
|
170
|
-
* Returns the driver name ("mongo") to use with {@link route}.
|
|
152
|
+
* Registers a MongoDB driver.
|
|
171
153
|
*/
|
|
172
154
|
registerMongoDriver(uri, dbName) {
|
|
173
|
-
const raw =
|
|
155
|
+
const raw = this.callNative(OmniQL_RegisterMongoDriver, uri, dbName);
|
|
174
156
|
return JSON.parse(raw).driver ?? 'mongo';
|
|
175
157
|
}
|
|
176
158
|
/**
|
|
177
|
-
* Releases the native engine handle.
|
|
159
|
+
* Releases the native engine handle.
|
|
178
160
|
*/
|
|
179
161
|
close() {
|
|
180
|
-
|
|
162
|
+
OmniQL_FreeEngine(this.handle);
|
|
181
163
|
}
|
|
182
164
|
}
|
|
183
165
|
exports.OmniEngine = OmniEngine;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omniql",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
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",
|
|
@@ -13,13 +13,10 @@
|
|
|
13
13
|
"author": "Uttam Mahata <uttam-mahata-cs@outlook.com>",
|
|
14
14
|
"license": "Apache-2.0",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"
|
|
17
|
-
"ref-napi": "^3.0.3"
|
|
16
|
+
"koffi": "^2.9.0"
|
|
18
17
|
},
|
|
19
18
|
"devDependencies": {
|
|
20
|
-
"@types/ffi-napi": "^4.0.10",
|
|
21
19
|
"@types/node": "^20.0.0",
|
|
22
|
-
"@types/ref-napi": "^3.0.12",
|
|
23
20
|
"typescript": "^5.0.0"
|
|
24
21
|
},
|
|
25
22
|
"scripts": {
|