@oino-ts/db-bunsqlite 0.18.1 → 0.19.0
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.
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.OINODbBunSqlite = void 0;
|
|
9
|
+
const common_1 = require("@oino-ts/common");
|
|
9
10
|
const db_1 = require("@oino-ts/db");
|
|
10
11
|
const bun_sqlite_1 = require("bun:sqlite");
|
|
11
12
|
/**
|
|
@@ -35,10 +36,10 @@ class OINODbBunSqlite extends db_1.OINODb {
|
|
|
35
36
|
super(params);
|
|
36
37
|
this._db = null;
|
|
37
38
|
if (!this._params.url.startsWith("file://")) {
|
|
38
|
-
throw new Error(
|
|
39
|
+
throw new Error(common_1.OINO_ERROR_PREFIX + ": OINODbBunSqlite url must be a file://-url!");
|
|
39
40
|
}
|
|
40
41
|
if (this._params.type !== "OINODbBunSqlite") {
|
|
41
|
-
throw new Error(
|
|
42
|
+
throw new Error(common_1.OINO_ERROR_PREFIX + ": Not OINODbBunSqlite-type: " + this._params.type);
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
_parseDbFieldParams(fieldStr) {
|
|
@@ -151,8 +152,8 @@ class OINODbBunSqlite extends db_1.OINODb {
|
|
|
151
152
|
*
|
|
152
153
|
*/
|
|
153
154
|
async connect() {
|
|
154
|
-
|
|
155
|
-
let result = new
|
|
155
|
+
common_1.OINOBenchmark.startMetric("OINODb", "connect");
|
|
156
|
+
let result = new common_1.OINOResult();
|
|
156
157
|
const filepath = this._params.url.substring(7);
|
|
157
158
|
try {
|
|
158
159
|
this._db = bun_sqlite_1.Database.open(filepath, { create: true, readonly: false, readwrite: true });
|
|
@@ -160,9 +161,9 @@ class OINODbBunSqlite extends db_1.OINODb {
|
|
|
160
161
|
}
|
|
161
162
|
catch (e) {
|
|
162
163
|
result.setError(500, "Exception connecting to database: " + e.message, "OINODbBunSqlite.connect");
|
|
163
|
-
|
|
164
|
+
common_1.OINOLog.exception("@oino-ts/db-bunsqlite", "OINODbBunSqlite", "connect", "exception in connect", { message: e.message, stack: e.stack });
|
|
164
165
|
}
|
|
165
|
-
|
|
166
|
+
common_1.OINOBenchmark.endMetric("OINODb", "connect");
|
|
166
167
|
return result;
|
|
167
168
|
}
|
|
168
169
|
/**
|
|
@@ -170,8 +171,8 @@ class OINODbBunSqlite extends db_1.OINODb {
|
|
|
170
171
|
*
|
|
171
172
|
*/
|
|
172
173
|
async validate() {
|
|
173
|
-
|
|
174
|
-
let result = new
|
|
174
|
+
common_1.OINOBenchmark.startMetric("OINODb", "validate");
|
|
175
|
+
let result = new common_1.OINOResult();
|
|
175
176
|
try {
|
|
176
177
|
const sql = this._getValidateSql(this._params.database);
|
|
177
178
|
const sql_res = await this.sqlSelect(sql);
|
|
@@ -189,9 +190,9 @@ class OINODbBunSqlite extends db_1.OINODb {
|
|
|
189
190
|
}
|
|
190
191
|
}
|
|
191
192
|
catch (e) {
|
|
192
|
-
result.setError(500,
|
|
193
|
+
result.setError(500, common_1.OINO_ERROR_PREFIX + " (validate): OINODbBunSqlite.validate exception in _db.query: " + e.message, "OINODbBunSqlite.validate");
|
|
193
194
|
}
|
|
194
|
-
|
|
195
|
+
common_1.OINOBenchmark.endMetric("OINODb", "validate");
|
|
195
196
|
return result;
|
|
196
197
|
}
|
|
197
198
|
/**
|
|
@@ -201,7 +202,7 @@ class OINODbBunSqlite extends db_1.OINODb {
|
|
|
201
202
|
*
|
|
202
203
|
*/
|
|
203
204
|
async sqlSelect(sql) {
|
|
204
|
-
|
|
205
|
+
common_1.OINOBenchmark.startMetric("OINODb", "sqlSelect");
|
|
205
206
|
let result;
|
|
206
207
|
try {
|
|
207
208
|
result = new OINOBunSqliteDataset(this._db?.query(sql).values(), []);
|
|
@@ -209,7 +210,7 @@ class OINODbBunSqlite extends db_1.OINODb {
|
|
|
209
210
|
catch (e) {
|
|
210
211
|
result = new OINOBunSqliteDataset(db_1.OINODB_EMPTY_ROWS, ["OINODbBunSqlite.sqlSelect exception in _db.query: " + e.message]);
|
|
211
212
|
}
|
|
212
|
-
|
|
213
|
+
common_1.OINOBenchmark.endMetric("OINODb", "sqlSelect");
|
|
213
214
|
return Promise.resolve(result);
|
|
214
215
|
}
|
|
215
216
|
/**
|
|
@@ -219,16 +220,16 @@ class OINODbBunSqlite extends db_1.OINODb {
|
|
|
219
220
|
*
|
|
220
221
|
*/
|
|
221
222
|
async sqlExec(sql) {
|
|
222
|
-
|
|
223
|
+
common_1.OINOBenchmark.startMetric("OINODb", "sqlExec");
|
|
223
224
|
let result;
|
|
224
225
|
try {
|
|
225
226
|
this._db?.exec(sql);
|
|
226
227
|
result = new OINOBunSqliteDataset(db_1.OINODB_EMPTY_ROWS, []);
|
|
227
228
|
}
|
|
228
229
|
catch (e) {
|
|
229
|
-
result = new OINOBunSqliteDataset(db_1.OINODB_EMPTY_ROWS, [
|
|
230
|
+
result = new OINOBunSqliteDataset(db_1.OINODB_EMPTY_ROWS, [common_1.OINO_ERROR_PREFIX + "(sqlExec): exception in _db.exec [" + e.message + "]"]);
|
|
230
231
|
}
|
|
231
|
-
|
|
232
|
+
common_1.OINOBenchmark.endMetric("OINODb", "sqlExec");
|
|
232
233
|
return Promise.resolve(result);
|
|
233
234
|
}
|
|
234
235
|
_getSchemaSql(dbName, tableName) {
|
|
@@ -256,7 +257,7 @@ class OINODbBunSqlite extends db_1.OINODb {
|
|
|
256
257
|
throw new Error("Table " + api.params.tableName + " not recognized as a valid Sqlite table!");
|
|
257
258
|
}
|
|
258
259
|
else {
|
|
259
|
-
let field_strings =
|
|
260
|
+
let field_strings = common_1.OINOStr.splitExcludingBrackets(table_matches[1], ',', '(', ')');
|
|
260
261
|
for (let field_str of field_strings) {
|
|
261
262
|
field_str = field_str.trim();
|
|
262
263
|
let field_params = this._parseDbFieldParams(field_str);
|
|
@@ -270,7 +271,7 @@ class OINODbBunSqlite extends db_1.OINODb {
|
|
|
270
271
|
for (let i = 0; i < primary_keys.length; i++) {
|
|
271
272
|
const pk = primary_keys[i].trim(); //..the trim
|
|
272
273
|
if (excluded_fields.indexOf(pk) >= 0) {
|
|
273
|
-
throw new Error(
|
|
274
|
+
throw new Error(common_1.OINO_ERROR_PREFIX + "Primary key field excluded in API parameters: " + pk);
|
|
274
275
|
}
|
|
275
276
|
for (let j = 0; j < api.datamodel.fields.length; j++) {
|
|
276
277
|
if (api.datamodel.fields[j].name == pk) {
|
|
@@ -288,7 +289,7 @@ class OINODbBunSqlite extends db_1.OINODb {
|
|
|
288
289
|
}
|
|
289
290
|
}
|
|
290
291
|
else {
|
|
291
|
-
|
|
292
|
+
common_1.OINOLog.info("@oino-ts/db-bunsqlite", "OINODbBunSqlite", "initializeApiDatamodel", "Unsupported field definition skipped.", { field: field_str });
|
|
292
293
|
}
|
|
293
294
|
}
|
|
294
295
|
else {
|
|
@@ -298,7 +299,7 @@ class OINODbBunSqlite extends db_1.OINODb {
|
|
|
298
299
|
const field_length = parseInt(field_match[4]) || 0;
|
|
299
300
|
if (api.isFieldIncluded(field_name) == false) {
|
|
300
301
|
excluded_fields.push(field_name);
|
|
301
|
-
|
|
302
|
+
common_1.OINOLog.info("@oino-ts/db-bunsqlite", "OINODbBunSqlite", "initializeApiDatamodel", "Field excluded in API parameters.", { field: field_name });
|
|
302
303
|
}
|
|
303
304
|
else {
|
|
304
305
|
if ((sql_type == "INTEGER") || (sql_type == "REAL") || (sql_type == "DOUBLE") || (sql_type == "NUMERIC") || (sql_type == "DECIMAL")) {
|
|
@@ -322,14 +323,14 @@ class OINODbBunSqlite extends db_1.OINODb {
|
|
|
322
323
|
api.datamodel.addField(new db_1.OINOBooleanDataField(this, field_name, sql_type, field_params));
|
|
323
324
|
}
|
|
324
325
|
else {
|
|
325
|
-
|
|
326
|
+
common_1.OINOLog.info("@oino-ts/db-bunsqlite", "OINODbBunSqlite", "initializeApiDatamodel", "Unrecognized field type treated as string", { field_name: field_name, sql_type: sql_type, field_length: field_length, field_params: field_params });
|
|
326
327
|
api.datamodel.addField(new db_1.OINOStringDataField(this, field_name, sql_type, field_params, 0));
|
|
327
328
|
}
|
|
328
329
|
}
|
|
329
330
|
}
|
|
330
331
|
}
|
|
331
332
|
;
|
|
332
|
-
|
|
333
|
+
common_1.OINOLog.info("@oino-ts/db-bunsqlite", "OINODbBunSqlite", "initializeApiDatamodel", "\n" + api.datamodel.printDebug("\n"));
|
|
333
334
|
return Promise.resolve();
|
|
334
335
|
}
|
|
335
336
|
}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
4
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { OINO_ERROR_PREFIX, OINOBenchmark, OINOStr, OINOLog, OINOResult } from "@oino-ts/common";
|
|
7
|
+
import { OINODb, OINOBooleanDataField, OINONumberDataField, OINOStringDataField, OINODbMemoryDataSet, OINOBlobDataField, OINODatetimeDataField, OINODB_EMPTY_ROWS } from "@oino-ts/db";
|
|
7
8
|
import { Database as BunSqliteDb } from "bun:sqlite";
|
|
8
9
|
/**
|
|
9
10
|
* Implmentation of OINODbDataSet for BunSqlite.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OINOResult } from "@oino-ts/common";
|
|
2
|
+
import { OINODb, OINODbParams, OINODbDataSet, OINODbApi, OINODataCell } from "@oino-ts/db";
|
|
2
3
|
/**
|
|
3
4
|
* Implementation of BunSqlite-database.
|
|
4
5
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oino-ts/db-bunsqlite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "OINO TS package for using Bun Sqlite databases.",
|
|
5
5
|
"author": "Matias Kiviniemi (pragmatta)",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"module": "./dist/esm/index.js",
|
|
21
21
|
"types": "./dist/types/index.d.ts",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@oino-ts/
|
|
23
|
+
"@oino-ts/common": "^0.19.0",
|
|
24
|
+
"@oino-ts/db": "^0.19.0"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"@types/bun": "latest",
|
package/src/OINODbBunSqlite.ts
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { OINO_ERROR_PREFIX, OINOBenchmark, OINOStr, OINOLog, OINOResult } from "@oino-ts/common";
|
|
8
|
+
import { OINODb, OINODbParams, OINODbDataSet, OINODbApi, OINOBooleanDataField, OINONumberDataField, OINOStringDataField, OINODbDataFieldParams, OINODbMemoryDataSet, OINODataCell, OINOBlobDataField, OINODatetimeDataField, OINODB_EMPTY_ROWS } from "@oino-ts/db";
|
|
8
9
|
|
|
9
10
|
import { Database as BunSqliteDb } from "bun:sqlite";
|
|
10
11
|
|