@oino-ts/db-postgresql 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.OINODbPostgresql = void 0;
9
+ const common_1 = require("@oino-ts/common");
9
10
  const db_1 = require("@oino-ts/db");
10
11
  const pg_1 = require("pg");
11
12
  /**
@@ -21,7 +22,7 @@ class OINOPostgresqlData extends db_1.OINODbDataSet {
21
22
  constructor(data, messages = []) {
22
23
  super(data, messages);
23
24
  if ((data != null) && !(Array.isArray(data))) {
24
- throw new Error(db_1.OINO_ERROR_PREFIX + ": Invalid Posgresql data type!"); // TODO: maybe check all rows
25
+ throw new Error(common_1.OINO_ERROR_PREFIX + ": Invalid Posgresql data type!"); // TODO: maybe check all rows
25
26
  }
26
27
  this._rows = data;
27
28
  if (this.isEmpty()) {
@@ -95,13 +96,13 @@ class OINODbPostgresql extends db_1.OINODb {
95
96
  constructor(params) {
96
97
  super(params);
97
98
  if (this._params.type !== "OINODbPostgresql") {
98
- throw new Error(db_1.OINO_ERROR_PREFIX + ": Not OINODbPostgresql-type: " + this._params.type);
99
+ throw new Error(common_1.OINO_ERROR_PREFIX + ": Not OINODbPostgresql-type: " + this._params.type);
99
100
  }
100
101
  const ssl_enabled = !(this._params.url == "localhost" || this._params.url == "127.0.0.1");
101
102
  this._pool = new pg_1.Pool({ host: this._params.url, database: this._params.database, port: this._params.port, user: this._params.user, password: this._params.password, ssl: ssl_enabled });
102
103
  delete this._params.password;
103
104
  this._pool.on("error", (err) => {
104
- db_1.OINOLog.error("@oino-ts/db-postgresql", "OINODbPostgresql", ".on(error)", "Error-event", { err: err });
105
+ common_1.OINOLog.error("@oino-ts/db-postgresql", "OINODbPostgresql", ".on(error)", "Error-event", { err: err });
105
106
  });
106
107
  }
107
108
  _parseFieldLength(fieldLength) {
@@ -225,7 +226,7 @@ class OINODbPostgresql extends db_1.OINODb {
225
226
  *
226
227
  */
227
228
  async connect() {
228
- let result = new db_1.OINOResult();
229
+ let result = new common_1.OINOResult();
229
230
  try {
230
231
  // make sure that any items are correctly URL encoded in the connection string
231
232
  await this._pool.connect();
@@ -233,7 +234,7 @@ class OINODbPostgresql extends db_1.OINODb {
233
234
  }
234
235
  catch (e) {
235
236
  result.setError(500, "Exception connecting to database: " + e.message, "OINODbPostgresql.connect");
236
- db_1.OINOLog.exception("@oino-ts/db-postgresql", "OINODbPostgresql", "connect", "exception in connect", { message: e.message, stack: e.stack });
237
+ common_1.OINOLog.exception("@oino-ts/db-postgresql", "OINODbPostgresql", "connect", "exception in connect", { message: e.message, stack: e.stack });
237
238
  }
238
239
  return result;
239
240
  }
@@ -242,8 +243,8 @@ class OINODbPostgresql extends db_1.OINODb {
242
243
  *
243
244
  */
244
245
  async validate() {
245
- db_1.OINOBenchmark.startMetric("OINODb", "validate");
246
- let result = new db_1.OINOResult();
246
+ common_1.OINOBenchmark.startMetric("OINODb", "validate");
247
+ let result = new common_1.OINOResult();
247
248
  try {
248
249
  const sql = this._getValidateSql(this._params.database);
249
250
  const sql_res = await this.sqlSelect(sql);
@@ -262,9 +263,9 @@ class OINODbPostgresql extends db_1.OINODb {
262
263
  }
263
264
  catch (e) {
264
265
  result.setError(500, "Exception validating connection: " + e.message, "OINODbPostgresql.validate");
265
- db_1.OINOLog.exception("@oino-ts/db-postgresql", "OINODbPostgresql", "validate", "exception in validate", { message: e.message, stack: e.stack });
266
+ common_1.OINOLog.exception("@oino-ts/db-postgresql", "OINODbPostgresql", "validate", "exception in validate", { message: e.message, stack: e.stack });
266
267
  }
267
- db_1.OINOBenchmark.endMetric("OINODb", "validate");
268
+ common_1.OINOBenchmark.endMetric("OINODb", "validate");
268
269
  return result;
269
270
  }
270
271
  /**
@@ -274,16 +275,16 @@ class OINODbPostgresql extends db_1.OINODb {
274
275
  *
275
276
  */
276
277
  async sqlSelect(sql) {
277
- db_1.OINOBenchmark.startMetric("OINODb", "sqlSelect");
278
+ common_1.OINOBenchmark.startMetric("OINODb", "sqlSelect");
278
279
  let result;
279
280
  try {
280
281
  const rows = await this._query(sql);
281
282
  result = new OINOPostgresqlData(rows, []);
282
283
  }
283
284
  catch (e) {
284
- result = new OINOPostgresqlData(db_1.OINODB_EMPTY_ROWS, [db_1.OINO_ERROR_PREFIX + " (sqlSelect): exception in _db.query [" + e.message + "]"]);
285
+ result = new OINOPostgresqlData(db_1.OINODB_EMPTY_ROWS, [common_1.OINO_ERROR_PREFIX + " (sqlSelect): exception in _db.query [" + e.message + "]"]);
285
286
  }
286
- db_1.OINOBenchmark.endMetric("OINODb", "sqlSelect");
287
+ common_1.OINOBenchmark.endMetric("OINODb", "sqlSelect");
287
288
  return result;
288
289
  }
289
290
  /**
@@ -293,16 +294,16 @@ class OINODbPostgresql extends db_1.OINODb {
293
294
  *
294
295
  */
295
296
  async sqlExec(sql) {
296
- db_1.OINOBenchmark.startMetric("OINODb", "sqlExec");
297
+ common_1.OINOBenchmark.startMetric("OINODb", "sqlExec");
297
298
  let result;
298
299
  try {
299
300
  const rows = await this._exec(sql);
300
301
  result = new OINOPostgresqlData(rows, []);
301
302
  }
302
303
  catch (e) {
303
- result = new OINOPostgresqlData(db_1.OINODB_EMPTY_ROWS, [db_1.OINO_ERROR_PREFIX + " (sqlExec): exception in _db.exec [" + e.message + "]"]);
304
+ result = new OINOPostgresqlData(db_1.OINODB_EMPTY_ROWS, [common_1.OINO_ERROR_PREFIX + " (sqlExec): exception in _db.exec [" + e.message + "]"]);
304
305
  }
305
- db_1.OINOBenchmark.endMetric("OINODb", "sqlExec");
306
+ common_1.OINOBenchmark.endMetric("OINODb", "sqlExec");
306
307
  return result;
307
308
  }
308
309
  _getSchemaSql(dbName, tableName) {
@@ -375,9 +376,9 @@ WHERE col.table_catalog = '${dbName}'`;
375
376
  isAutoInc: default_val.startsWith("nextval(")
376
377
  };
377
378
  if (api.isFieldIncluded(field_name) == false) {
378
- db_1.OINOLog.info("@oino-ts/db-postgresql", "OINODbPostgresql", "initializeApiDatamodel", "Field excluded in API parameters.", { field: field_name });
379
+ common_1.OINOLog.info("@oino-ts/db-postgresql", "OINODbPostgresql", "initializeApiDatamodel", "Field excluded in API parameters.", { field: field_name });
379
380
  if (field_params.isPrimaryKey) {
380
- throw new Error(db_1.OINO_ERROR_PREFIX + "Primary key field excluded in API parameters: " + field_name);
381
+ throw new Error(common_1.OINO_ERROR_PREFIX + "Primary key field excluded in API parameters: " + field_name);
381
382
  }
382
383
  }
383
384
  else {
@@ -405,13 +406,13 @@ WHERE col.table_catalog = '${dbName}'`;
405
406
  api.datamodel.addField(new db_1.OINOStringDataField(this, field_name, sql_type, field_params, numeric_precision + numeric_scale + 1));
406
407
  }
407
408
  else {
408
- db_1.OINOLog.info("@oino-ts/db-postgresql", "OINODbPostgresql", "initializeApiDatamodel", "Unrecognized field type treated as string", { field_name: field_name, sql_type: sql_type, field_length: field_length, field_params: field_params });
409
+ common_1.OINOLog.info("@oino-ts/db-postgresql", "OINODbPostgresql", "initializeApiDatamodel", "Unrecognized field type treated as string", { field_name: field_name, sql_type: sql_type, field_length: field_length, field_params: field_params });
409
410
  api.datamodel.addField(new db_1.OINOStringDataField(this, field_name, sql_type, field_params, 0));
410
411
  }
411
412
  }
412
413
  await schema_res.next();
413
414
  }
414
- db_1.OINOLog.info("@oino-ts/db-postgresql", "OINODbPostgresql", "initializeApiDatamodel", "\n" + api.datamodel.printDebug("\n"));
415
+ common_1.OINOLog.info("@oino-ts/db-postgresql", "OINODbPostgresql", "initializeApiDatamodel", "\n" + api.datamodel.printDebug("\n"));
415
416
  return Promise.resolve();
416
417
  }
417
418
  }
@@ -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 { OINODb, OINODbDataSet, OINOBooleanDataField, OINONumberDataField, OINOStringDataField, OINO_ERROR_PREFIX, OINOBenchmark, OINODatetimeDataField, OINOBlobDataField, OINOLog, OINOResult, OINODB_EMPTY_ROW, OINODB_EMPTY_ROWS } from "@oino-ts/db";
6
+ import { OINO_ERROR_PREFIX, OINOBenchmark, 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 { Pool } from "pg";
8
9
  /**
9
10
  * Implmentation of OINODbDataSet for Postgresql.
@@ -1,4 +1,5 @@
1
- import { OINODb, OINODbParams, OINODbDataSet, OINODbApi, OINODataCell, OINOResult } from "@oino-ts/db";
1
+ import { OINOResult } from "@oino-ts/common";
2
+ import { OINODb, OINODbParams, OINODbDataSet, OINODbApi, OINODataCell } from "@oino-ts/db";
2
3
  /**
3
4
  * Implementation of Postgresql-database.
4
5
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oino-ts/db-postgresql",
3
- "version": "0.18.1",
3
+ "version": "0.19.0",
4
4
  "description": "OINO TS package for using Postgresql databases.",
5
5
  "author": "Matias Kiviniemi (pragmatta)",
6
6
  "license": "MPL-2.0",
@@ -20,7 +20,7 @@
20
20
  "module": "./dist/esm/index.js",
21
21
  "types": "./dist/types/index.d.ts",
22
22
  "dependencies": {
23
- "@oino-ts/db": "0.18.1",
23
+ "@oino-ts/db": "0.19.0",
24
24
  "pg": "^8.11.3"
25
25
  },
26
26
  "devDependencies": {
@@ -4,7 +4,8 @@
4
4
  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
5
  */
6
6
 
7
- import { OINODb, OINODbParams, OINODbDataSet, OINODbApi, OINOBooleanDataField, OINONumberDataField, OINOStringDataField, OINODbDataFieldParams, OINO_ERROR_PREFIX, OINODataRow, OINODataCell, OINOBenchmark, OINODatetimeDataField, OINOBlobDataField, OINOLog, OINOResult, OINODB_EMPTY_ROW, OINODB_EMPTY_ROWS } from "@oino-ts/db";
7
+ import { OINO_ERROR_PREFIX, OINOBenchmark, 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 { Pool, QueryResult } from "pg";
10
11