@oino-ts/db-mariadb 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.OINODbMariadb = void 0;
|
|
9
|
+
const common_1 = require("@oino-ts/common");
|
|
9
10
|
const db_1 = require("@oino-ts/db");
|
|
10
11
|
const mariadb_1 = require("mariadb");
|
|
11
12
|
/**
|
|
@@ -21,7 +22,7 @@ class OINOMariadbData extends db_1.OINODbDataSet {
|
|
|
21
22
|
constructor(data, messages = []) {
|
|
22
23
|
super(data, messages);
|
|
23
24
|
if (data == null) {
|
|
24
|
-
this.messages.push(
|
|
25
|
+
this.messages.push(common_1.OINO_INFO_PREFIX + "SQL result is empty");
|
|
25
26
|
}
|
|
26
27
|
else if (Array.isArray(data)) {
|
|
27
28
|
this._rows = data;
|
|
@@ -100,7 +101,7 @@ class OINODbMariadb extends db_1.OINODb {
|
|
|
100
101
|
constructor(params) {
|
|
101
102
|
super(params);
|
|
102
103
|
if (this._params.type !== "OINODbMariadb") {
|
|
103
|
-
throw new Error(
|
|
104
|
+
throw new Error(common_1.OINO_ERROR_PREFIX + ": Not OINODbMariadb-type: " + this._params.type);
|
|
104
105
|
}
|
|
105
106
|
this._pool = mariadb_1.default.createPool({ host: this._params.url, database: this._params.database, port: this._params.port, user: this._params.user, password: this._params.password, acquireTimeout: 2000, debug: false, rowsAsArray: true, multipleStatements: true });
|
|
106
107
|
delete this._params.password; // do not store password in db object
|
|
@@ -253,7 +254,7 @@ class OINODbMariadb extends db_1.OINODb {
|
|
|
253
254
|
*
|
|
254
255
|
*/
|
|
255
256
|
async connect() {
|
|
256
|
-
const result = new
|
|
257
|
+
const result = new common_1.OINOResult();
|
|
257
258
|
let connection = null;
|
|
258
259
|
try {
|
|
259
260
|
// make sure that any items are correctly URL encoded in the connection string
|
|
@@ -263,7 +264,7 @@ class OINODbMariadb extends db_1.OINODb {
|
|
|
263
264
|
catch (e) {
|
|
264
265
|
const msg_parts = e.message.match(OINODbMariadb._connectionExceptionMessageRegex) || [];
|
|
265
266
|
result.setError(500, "Error connecting to server: " + msg_parts[2], "OINODbMariadb.connect");
|
|
266
|
-
|
|
267
|
+
common_1.OINOLog.exception("@oino-ts/db-mariadb", "OINODbMariadb", "connect", "exception in connect", { message: e.message, stack: e.stack });
|
|
267
268
|
}
|
|
268
269
|
finally {
|
|
269
270
|
if (connection) {
|
|
@@ -277,8 +278,8 @@ class OINODbMariadb extends db_1.OINODb {
|
|
|
277
278
|
*
|
|
278
279
|
*/
|
|
279
280
|
async validate() {
|
|
280
|
-
|
|
281
|
-
let result = new
|
|
281
|
+
common_1.OINOBenchmark.startMetric("OINODb", "validate");
|
|
282
|
+
let result = new common_1.OINOResult();
|
|
282
283
|
try {
|
|
283
284
|
const sql = this._getValidateSql(this._params.database);
|
|
284
285
|
const sql_res = await this.sqlSelect(sql);
|
|
@@ -297,9 +298,9 @@ class OINODbMariadb extends db_1.OINODb {
|
|
|
297
298
|
}
|
|
298
299
|
catch (e) {
|
|
299
300
|
result.setError(500, "Exception validating connection: " + e.message, "OINODbMariadb.validate");
|
|
300
|
-
|
|
301
|
+
common_1.OINOLog.exception("@oino-ts/db-mariadb", "OINODbMariadb", "validate", "exception in validate", { message: e.message, stack: e.stack });
|
|
301
302
|
}
|
|
302
|
-
|
|
303
|
+
common_1.OINOBenchmark.endMetric("OINODb", "validate");
|
|
303
304
|
return result;
|
|
304
305
|
}
|
|
305
306
|
/**
|
|
@@ -309,17 +310,17 @@ class OINODbMariadb extends db_1.OINODb {
|
|
|
309
310
|
*
|
|
310
311
|
*/
|
|
311
312
|
async sqlSelect(sql) {
|
|
312
|
-
|
|
313
|
+
common_1.OINOBenchmark.startMetric("OINODb", "sqlSelect");
|
|
313
314
|
let result;
|
|
314
315
|
try {
|
|
315
316
|
const rows = await this._query(sql);
|
|
316
317
|
result = new OINOMariadbData(rows, []);
|
|
317
318
|
}
|
|
318
319
|
catch (e) {
|
|
319
|
-
|
|
320
|
-
result = new OINOMariadbData(db_1.OINODB_EMPTY_ROWS, [
|
|
320
|
+
common_1.OINOLog.exception("@oino-ts/db-mariadb", "OINODbMariadb", "sqlSelect", "exception in SQL select", { message: e.message, stack: e.stack });
|
|
321
|
+
result = new OINOMariadbData(db_1.OINODB_EMPTY_ROWS, [common_1.OINO_ERROR_PREFIX + " (sqlSelect): OINODbMariadb.sqlSelect exception in _db.query: " + e.message]);
|
|
321
322
|
}
|
|
322
|
-
|
|
323
|
+
common_1.OINOBenchmark.endMetric("OINODb", "sqlSelect");
|
|
323
324
|
return result;
|
|
324
325
|
}
|
|
325
326
|
/**
|
|
@@ -329,7 +330,7 @@ class OINODbMariadb extends db_1.OINODb {
|
|
|
329
330
|
*
|
|
330
331
|
*/
|
|
331
332
|
async sqlExec(sql) {
|
|
332
|
-
|
|
333
|
+
common_1.OINOBenchmark.startMetric("OINODb", "sqlExec");
|
|
333
334
|
let result;
|
|
334
335
|
try {
|
|
335
336
|
const sql_res = await this._exec(sql);
|
|
@@ -337,10 +338,10 @@ class OINODbMariadb extends db_1.OINODb {
|
|
|
337
338
|
}
|
|
338
339
|
catch (e) {
|
|
339
340
|
const msg_parts = e.message.match(OINODbMariadb._sqlExceptionMessageRegex) || [];
|
|
340
|
-
|
|
341
|
-
result = new OINOMariadbData(db_1.OINODB_EMPTY_ROWS, [
|
|
341
|
+
common_1.OINOLog.exception("@oino-ts/db-mariadb", "OINODbMariadb", "sqlExec", "exception in SQL exec", { message: msg_parts[2], stack: e.stack });
|
|
342
|
+
result = new OINOMariadbData(db_1.OINODB_EMPTY_ROWS, [common_1.OINO_ERROR_PREFIX + " (sqlExec): exception in _db.exec [" + msg_parts[2] + "]"]);
|
|
342
343
|
}
|
|
343
|
-
|
|
344
|
+
common_1.OINOBenchmark.endMetric("OINODb", "sqlExec");
|
|
344
345
|
return result;
|
|
345
346
|
}
|
|
346
347
|
_getSchemaSql(dbName, tableName) {
|
|
@@ -391,9 +392,9 @@ WHERE C.TABLE_SCHEMA = '${dbName}';`;
|
|
|
391
392
|
isNotNull: row[2] == "NO"
|
|
392
393
|
};
|
|
393
394
|
if (api.isFieldIncluded(field_name) == false) {
|
|
394
|
-
|
|
395
|
+
common_1.OINOLog.info("@oino-ts/db-mariadb", "OINODbMariadb", ".initializeApiDatamodel", "Field excluded in API parameters", { field: field_name });
|
|
395
396
|
if (field_params.isPrimaryKey) {
|
|
396
|
-
throw new Error(
|
|
397
|
+
throw new Error(common_1.OINO_ERROR_PREFIX + "Primary key field excluded in API parameters: " + field_name);
|
|
397
398
|
}
|
|
398
399
|
}
|
|
399
400
|
else {
|
|
@@ -426,13 +427,13 @@ WHERE C.TABLE_SCHEMA = '${dbName}';`;
|
|
|
426
427
|
}
|
|
427
428
|
}
|
|
428
429
|
else {
|
|
429
|
-
|
|
430
|
+
common_1.OINOLog.info("@oino-ts/db-mariadb", "OINODbMariadb", "initializeApiDatamodel", "Unrecognized field type treated as string", { field_name: field_name, sql_type: sql_type, field_length1: field_length1, field_length2: field_length2, field_params: field_params });
|
|
430
431
|
api.datamodel.addField(new db_1.OINOStringDataField(this, field_name, sql_type, field_params, 0));
|
|
431
432
|
}
|
|
432
433
|
}
|
|
433
434
|
await schema_res.next();
|
|
434
435
|
}
|
|
435
|
-
|
|
436
|
+
common_1.OINOLog.info("@oino-ts/db-mariadb", "OINODbMariadb", "initializeApiDatamodel", "\n" + api.datamodel.printDebug("\n"));
|
|
436
437
|
return Promise.resolve();
|
|
437
438
|
}
|
|
438
439
|
}
|
|
@@ -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, OINO_INFO_PREFIX, OINOLog, OINOResult } from "@oino-ts/common";
|
|
7
|
+
import { OINODb, OINODbDataSet, OINOBooleanDataField, OINONumberDataField, OINOStringDataField, OINODatetimeDataField, OINOBlobDataField, OINODB_EMPTY_ROW, OINODB_EMPTY_ROWS } from "@oino-ts/db";
|
|
7
8
|
import mariadb from "mariadb";
|
|
8
9
|
/**
|
|
9
10
|
* Implmentation of OINODbDataSet for MariaDb.
|
|
@@ -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 MariaDb/MySql-database.
|
|
4
5
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oino-ts/db-mariadb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "OINO TS package for using Mariadb databases.",
|
|
5
5
|
"author": "Matias Kiviniemi (pragmatta)",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"module": "./dist/esm/index.js",
|
|
22
22
|
"types": "./dist/types/index.d.ts",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@oino-ts/
|
|
24
|
+
"@oino-ts/common": "^0.19.0",
|
|
25
|
+
"@oino-ts/db": "^0.19.0",
|
|
25
26
|
"mariadb": "^3.2.3"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
package/src/OINODbMariadb.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, OINO_INFO_PREFIX, OINOLog, OINOResult } from "@oino-ts/common";
|
|
8
|
+
import { OINODb, OINODbParams, OINODbDataSet, OINODbApi, OINOBooleanDataField, OINONumberDataField, OINOStringDataField, OINODbDataFieldParams, OINODataRow, OINODataCell, OINODatetimeDataField, OINOBlobDataField, OINODB_EMPTY_ROW, OINODB_EMPTY_ROWS } from "@oino-ts/db";
|
|
8
9
|
|
|
9
10
|
import mariadb from "mariadb";
|
|
10
11
|
|