update dependencies and devDependencies, related updates and minor fixes
[squeep-indie-auther] / src / db / postgres / index.js
index 54c6e9b72ba2ccee85078926113fcc2dea33c08d..3a536f48f5d4250cce11f0483843bbac74335b02 100644 (file)
@@ -7,7 +7,7 @@ const pgpInitOptions = {
 
 const path = require('path');
 const pgp = require('pg-promise')(pgpInitOptions);
-const svh = require('../schema-version-helper');
+const { unappliedSchemaVersions } = require('../schema-version-helper');
 const Database = require('../abstract');
 const DBErrors = require('../errors');
 const common = require('../../common');
@@ -15,10 +15,10 @@ const common = require('../../common');
 const _fileScope = common.fileScope(__filename);
 
 const PGTypeIdINT8 = 20; // Type Id 20 == INT8 (BIGINT)
-const PGTYpeIdINT8Array = 1016; //Type Id 1016 == INT8[] (BIGINT[])
+const PGTypeIdINT8Array = 1016; //Type Id 1016 == INT8[] (BIGINT[])
 pgp.pg.types.setTypeParser(PGTypeIdINT8, BigInt); // Type Id 20 = INT8 (BIGINT)
-const parseBigIntArray = pgp.pg.types.getTypeParser(PGTYpeIdINT8Array); // Type Id 1016 = INT8[] (BIGINT[])
-pgp.pg.types.setTypeParser(PGTYpeIdINT8Array, (a) => parseBigIntArray(a).map(BigInt));
+const parseBigIntArray = pgp.pg.types.getTypeParser(PGTypeIdINT8Array); // Type Id 1016 = INT8[] (BIGINT[])
+pgp.pg.types.setTypeParser(PGTypeIdINT8Array, (a) => parseBigIntArray(a).map(BigInt));
 
 const schemaVersionsSupported = {
   min: {
@@ -48,7 +48,7 @@ class DatabasePostgres extends Database {
     if (queryLogLevel) {
       const queryScope = _fileScope('pgp:query');
       pgpInitOptions.query = (event) => {
-        this.logger[queryLogLevel](queryScope, '', { ...common.pick(event, ['query', 'params']) });
+        this.logger[queryLogLevel](queryScope, '', { ...common.pick(event || {}, ['query', 'params']) });
       };
     }
 
@@ -59,7 +59,7 @@ class DatabasePostgres extends Database {
     };
 
     // Deophidiate column names in-place, log results
-    pgpInitOptions.receive = (data, result, event) => {
+    pgpInitOptions.receive = ({ data, result, ctx: event }) => {
       const exemplaryRow = data[0];
       for (const prop in exemplaryRow) {
         const camel = common.camelfy(prop);
@@ -72,7 +72,7 @@ class DatabasePostgres extends Database {
       }
       if (queryLogLevel) {
         // Omitting .rows
-        const resultLog = common.pick(result, ['command', 'rowCount', 'duration']);
+        const resultLog = common.pick(result || {}, ['command', 'rowCount', 'duration']);
         this.logger[queryLogLevel](_fileScope('pgp:result'), '', { query: event.query, ...resultLog });
       }
     };
@@ -142,7 +142,7 @@ class DatabasePostgres extends Database {
 
     // Apply migrations
     const currentSchema = await this._currentSchema();
-    const migrationsWanted = svh.unappliedSchemaVersions(__dirname, currentSchema, this.schemaVersionsSupported);
+    const migrationsWanted = unappliedSchemaVersions(__dirname, currentSchema, this.schemaVersionsSupported);
     this.logger.debug(_scope, 'schema migrations wanted', { migrationsWanted });
     for (const v of migrationsWanted) {
       const fPath = path.join(__dirname, 'sql', 'schema', v, 'apply.sql');