@oino-ts/db-mssql 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.
- package/dist/cjs/OINODbMsSql.js +28 -27
- package/dist/esm/OINODbMsSql.js +4 -3
- package/dist/types/OINODbMsSql.d.ts +3 -2
- package/package.json +2 -2
- package/src/OINODbMsSql.ts +4 -3
package/dist/cjs/OINODbMsSql.js
CHANGED
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.OINODbMsSql = void 0;
|
|
9
|
+
const common_1 = require("@oino-ts/common");
|
|
9
10
|
const db_1 = require("@oino-ts/db");
|
|
10
11
|
const mssql_1 = require("mssql");
|
|
11
12
|
/**
|
|
12
|
-
* Implmentation of OINODbDataSet for
|
|
13
|
+
* Implmentation of OINODbDataSet for MsSql.
|
|
13
14
|
*
|
|
14
15
|
*/
|
|
15
16
|
class OINOMsSqlData extends db_1.OINODbDataSet {
|
|
@@ -25,10 +26,10 @@ class OINOMsSqlData extends db_1.OINODbDataSet {
|
|
|
25
26
|
constructor(data, messages = []) {
|
|
26
27
|
super(data, messages);
|
|
27
28
|
if (data == null) {
|
|
28
|
-
this.messages.push(
|
|
29
|
+
this.messages.push(common_1.OINO_INFO_PREFIX + "SQL result is empty");
|
|
29
30
|
}
|
|
30
31
|
else if (!(Array.isArray(data) && (data.length > 0) && Array.isArray(data[0]))) {
|
|
31
|
-
throw new Error(
|
|
32
|
+
throw new Error(common_1.OINO_ERROR_PREFIX + ": OINOMsSqlData constructor: invalid data!");
|
|
32
33
|
}
|
|
33
34
|
else {
|
|
34
35
|
this._recordsets = data;
|
|
@@ -98,7 +99,7 @@ class OINOMsSqlData extends db_1.OINODbDataSet {
|
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
101
|
/**
|
|
101
|
-
* Implementation of
|
|
102
|
+
* Implementation of MsSql-database.
|
|
102
103
|
*
|
|
103
104
|
*/
|
|
104
105
|
class OINODbMsSql extends db_1.OINODb {
|
|
@@ -110,7 +111,7 @@ class OINODbMsSql extends db_1.OINODb {
|
|
|
110
111
|
constructor(params) {
|
|
111
112
|
super(params);
|
|
112
113
|
if (this._params.type !== "OINODbMsSql") {
|
|
113
|
-
throw new Error(
|
|
114
|
+
throw new Error(common_1.OINO_ERROR_PREFIX + ": Not OINODbMsSql-type: " + this._params.type);
|
|
114
115
|
}
|
|
115
116
|
this._pool = new mssql_1.ConnectionPool({
|
|
116
117
|
user: this._params.user,
|
|
@@ -128,7 +129,7 @@ class OINODbMsSql extends db_1.OINODb {
|
|
|
128
129
|
});
|
|
129
130
|
delete this._params.password; // do not store password in db object
|
|
130
131
|
this._pool.on("error", (conn) => {
|
|
131
|
-
|
|
132
|
+
common_1.OINOLog.error("@oino-ts/db-mssql", "OINODbMsSql", "constructor", "OINODbMsSql error event", conn);
|
|
132
133
|
});
|
|
133
134
|
}
|
|
134
135
|
async _query(sql) {
|
|
@@ -258,15 +259,15 @@ class OINODbMsSql extends db_1.OINODb {
|
|
|
258
259
|
}
|
|
259
260
|
if ((limitCondition != "") && (limit_parts.length == 2)) {
|
|
260
261
|
if (orderCondition == "") {
|
|
261
|
-
|
|
262
|
-
throw new Error(
|
|
262
|
+
common_1.OINOLog.error("@oino-ts/db-mssql", "OINODbMsSql", "printSqlSelect", "LIMIT without ORDER BY is not supported in MS SQL Server");
|
|
263
|
+
throw new Error(common_1.OINO_ERROR_PREFIX + ": LIMIT without ORDER BY is not supported in MS SQL Server");
|
|
263
264
|
}
|
|
264
265
|
else {
|
|
265
266
|
result += " OFFSET " + limit_parts[1] + " ROWS FETCH NEXT " + limit_parts[0] + " ROWS ONLY";
|
|
266
267
|
}
|
|
267
268
|
}
|
|
268
269
|
result += ";";
|
|
269
|
-
|
|
270
|
+
common_1.OINOLog.debug("@oino-ts/db-mssql", "OINODbMsSql", "printSqlSelect", "Result", { sql: result });
|
|
270
271
|
return result;
|
|
271
272
|
}
|
|
272
273
|
/**
|
|
@@ -274,7 +275,7 @@ class OINODbMsSql extends db_1.OINODb {
|
|
|
274
275
|
*
|
|
275
276
|
*/
|
|
276
277
|
async connect() {
|
|
277
|
-
let result = new
|
|
278
|
+
let result = new common_1.OINOResult();
|
|
278
279
|
try {
|
|
279
280
|
// make sure that any items are correctly URL encoded in the connection string
|
|
280
281
|
await this._pool.connect();
|
|
@@ -283,7 +284,7 @@ class OINODbMsSql extends db_1.OINODb {
|
|
|
283
284
|
catch (e) {
|
|
284
285
|
// ... error checks
|
|
285
286
|
result.setError(500, "Exception connecting to database: " + e.message, "OINODbMsSql.connect");
|
|
286
|
-
|
|
287
|
+
common_1.OINOLog.exception("@oino-ts/db-mssql", "OINODbMsSql", "connect", "exception in connect", { message: e.message, stack: e.stack });
|
|
287
288
|
}
|
|
288
289
|
return Promise.resolve(result);
|
|
289
290
|
}
|
|
@@ -292,12 +293,12 @@ class OINODbMsSql extends db_1.OINODb {
|
|
|
292
293
|
*
|
|
293
294
|
*/
|
|
294
295
|
async validate() {
|
|
295
|
-
let result = new
|
|
296
|
+
let result = new common_1.OINOResult();
|
|
296
297
|
if (!this.isConnected) {
|
|
297
298
|
result.setError(400, "Database is not connected!", "OINODbMsSql.validate");
|
|
298
299
|
return result;
|
|
299
300
|
}
|
|
300
|
-
|
|
301
|
+
common_1.OINOBenchmark.startMetric("OINODb", "validate");
|
|
301
302
|
try {
|
|
302
303
|
const sql = this._getValidateSql(this._params.database);
|
|
303
304
|
const sql_res = await this.sqlSelect(sql);
|
|
@@ -317,9 +318,9 @@ class OINODbMsSql extends db_1.OINODb {
|
|
|
317
318
|
}
|
|
318
319
|
catch (e) {
|
|
319
320
|
result.setError(500, "Exception in validating connection: " + e.message, "OINODbMsSql.validate");
|
|
320
|
-
|
|
321
|
+
common_1.OINOLog.exception("@oino-ts/db-mssql", "OINODbMsSql", "validate", "exception in validate", { message: e.message, stack: e.stack });
|
|
321
322
|
}
|
|
322
|
-
|
|
323
|
+
common_1.OINOBenchmark.endMetric("OINODb", "validate");
|
|
323
324
|
return result;
|
|
324
325
|
}
|
|
325
326
|
/**
|
|
@@ -329,16 +330,16 @@ class OINODbMsSql extends db_1.OINODb {
|
|
|
329
330
|
*
|
|
330
331
|
*/
|
|
331
332
|
async sqlSelect(sql) {
|
|
332
|
-
|
|
333
|
+
common_1.OINOBenchmark.startMetric("OINODb", "sqlSelect");
|
|
333
334
|
let result;
|
|
334
335
|
try {
|
|
335
336
|
result = await this._query(sql);
|
|
336
337
|
}
|
|
337
338
|
catch (e) {
|
|
338
|
-
|
|
339
|
-
result = new OINOMsSqlData(db_1.OINODB_EMPTY_ROWS, [
|
|
339
|
+
common_1.OINOLog.exception("@oino-ts/db-mssql", "OINODbMsSql", "sqlSelect", "exception in SQL select", { message: e.message, stack: e.stack });
|
|
340
|
+
result = new OINOMsSqlData(db_1.OINODB_EMPTY_ROWS, [common_1.OINO_ERROR_PREFIX + " (sqlSelect): OINODbMsSql.sqlSelect exception in _db.query: " + e.message]);
|
|
340
341
|
}
|
|
341
|
-
|
|
342
|
+
common_1.OINOBenchmark.endMetric("OINODb", "sqlSelect");
|
|
342
343
|
return result;
|
|
343
344
|
}
|
|
344
345
|
/**
|
|
@@ -348,16 +349,16 @@ class OINODbMsSql extends db_1.OINODb {
|
|
|
348
349
|
*
|
|
349
350
|
*/
|
|
350
351
|
async sqlExec(sql) {
|
|
351
|
-
|
|
352
|
+
common_1.OINOBenchmark.startMetric("OINODb", "sqlExec");
|
|
352
353
|
let result;
|
|
353
354
|
try {
|
|
354
355
|
result = await this._exec(sql);
|
|
355
356
|
}
|
|
356
357
|
catch (e) {
|
|
357
|
-
|
|
358
|
-
result = new OINOMsSqlData(db_1.OINODB_EMPTY_ROWS, [
|
|
358
|
+
common_1.OINOLog.exception("@oino-ts/db-mssql", "OINODbMsSql", "sqlExec", "exception in SQL exec", { message: e.message, stack: e.stack });
|
|
359
|
+
result = new OINOMsSqlData(db_1.OINODB_EMPTY_ROWS, [common_1.OINO_ERROR_PREFIX + " (sqlExec): exception in _db.exec [" + e.message + "]"]);
|
|
359
360
|
}
|
|
360
|
-
|
|
361
|
+
common_1.OINOBenchmark.endMetric("OINODb", "sqlExec");
|
|
361
362
|
return result;
|
|
362
363
|
}
|
|
363
364
|
_getSchemaSql(dbName, tableName) {
|
|
@@ -424,9 +425,9 @@ WHERE C.TABLE_CATALOG = '${dbName}';`;
|
|
|
424
425
|
isNotNull: row[1] == "NO"
|
|
425
426
|
};
|
|
426
427
|
if (api.isFieldIncluded(field_name) == false) {
|
|
427
|
-
|
|
428
|
+
common_1.OINOLog.info("@oino-ts/db-mssql", "OINODbMsSql", "initializeApiDatamodel", "Field excluded in API parameters.", { field: field_name });
|
|
428
429
|
if (field_params.isPrimaryKey) {
|
|
429
|
-
throw new Error(
|
|
430
|
+
throw new Error(common_1.OINO_ERROR_PREFIX + "Primary key field excluded in API parameters: " + field_name);
|
|
430
431
|
}
|
|
431
432
|
}
|
|
432
433
|
else {
|
|
@@ -454,13 +455,13 @@ WHERE C.TABLE_CATALOG = '${dbName}';`;
|
|
|
454
455
|
api.datamodel.addField(new db_1.OINOBooleanDataField(this, field_name, sql_type, field_params));
|
|
455
456
|
}
|
|
456
457
|
else {
|
|
457
|
-
|
|
458
|
+
common_1.OINOLog.info("@oino-ts/db-mssql", "OINODbMsSql", "initializeApiDatamodel", "Unrecognized field type treated as string", { field_name: field_name, sql_type: sql_type, char_length: char_field_length, numeric_field_length1: numeric_field_length1, numeric_field_length2: numeric_field_length2, field_params: field_params });
|
|
458
459
|
api.datamodel.addField(new db_1.OINOStringDataField(this, field_name, sql_type, field_params, 0));
|
|
459
460
|
}
|
|
460
461
|
}
|
|
461
462
|
await schema_res.next();
|
|
462
463
|
}
|
|
463
|
-
|
|
464
|
+
common_1.OINOLog.info("@oino-ts/db-mssql", "OINODbMsSql", "initializeApiDatamodel", "\n" + api.datamodel.printDebug("\n"));
|
|
464
465
|
return Promise.resolve();
|
|
465
466
|
}
|
|
466
467
|
}
|
package/dist/esm/OINODbMsSql.js
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
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 { ConnectionPool } from "mssql";
|
|
8
9
|
/**
|
|
9
|
-
* Implmentation of OINODbDataSet for
|
|
10
|
+
* Implmentation of OINODbDataSet for MsSql.
|
|
10
11
|
*
|
|
11
12
|
*/
|
|
12
13
|
class OINOMsSqlData extends OINODbDataSet {
|
|
@@ -95,7 +96,7 @@ class OINOMsSqlData extends OINODbDataSet {
|
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
/**
|
|
98
|
-
* Implementation of
|
|
99
|
+
* Implementation of MsSql-database.
|
|
99
100
|
*
|
|
100
101
|
*/
|
|
101
102
|
export class OINODbMsSql extends OINODb {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OINOResult } from "@oino-ts/common";
|
|
2
|
+
import { OINODb, OINODbParams, OINODbDataSet, OINODbApi, OINODataCell } from "@oino-ts/db";
|
|
2
3
|
/**
|
|
3
|
-
* Implementation of
|
|
4
|
+
* Implementation of MsSql-database.
|
|
4
5
|
*
|
|
5
6
|
*/
|
|
6
7
|
export declare class OINODbMsSql extends OINODb {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oino-ts/db-mssql",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "OINO TS package for using Microsoft Sql databases.",
|
|
5
5
|
"author": "Matias Kiviniemi (pragmatta)",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"module": "./dist/esm/index.js",
|
|
23
23
|
"types": "./dist/types/index.d.ts",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@oino-ts/db": "0.
|
|
25
|
+
"@oino-ts/db": "0.19.0",
|
|
26
26
|
"mssql": "^11.0.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
package/src/OINODbMsSql.ts
CHANGED
|
@@ -4,12 +4,13 @@
|
|
|
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 {ConnectionPool, config} from "mssql";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
|
-
* Implmentation of OINODbDataSet for
|
|
13
|
+
* Implmentation of OINODbDataSet for MsSql.
|
|
13
14
|
*
|
|
14
15
|
*/
|
|
15
16
|
class OINOMsSqlData extends OINODbDataSet {
|
|
@@ -105,7 +106,7 @@ class OINOMsSqlData extends OINODbDataSet {
|
|
|
105
106
|
}
|
|
106
107
|
|
|
107
108
|
/**
|
|
108
|
-
* Implementation of
|
|
109
|
+
* Implementation of MsSql-database.
|
|
109
110
|
*
|
|
110
111
|
*/
|
|
111
112
|
export class OINODbMsSql extends OINODb {
|