From c007d316e852274449758e46dd080be2be77d64d Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 12 Apr 2023 18:57:15 +0200 Subject: [PATCH] refs #5541 Added/fixed per table: showField, relation, idName --- config.yml | 1 + mylogger.js | 41 ++++++++++++++++++++++++++--------------- package.json | 2 +- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/config.yml b/config.yml index 35b75e4..3a98c4e 100644 --- a/config.yml +++ b/config.yml @@ -22,6 +22,7 @@ dstDb: showFields: - name - description + - nickname castTypes: tinyint: boolean logs: diff --git a/mylogger.js b/mylogger.js index 6dd098a..5822c82 100644 --- a/mylogger.js +++ b/mylogger.js @@ -64,10 +64,19 @@ module.exports = class MyLogger { ? toUpperCamelCase(table.name) : table.name; + const { + showField, + relation, + idName + } = tableConf; + Object.assign(tableInfo, { conf: tableConf, exclude: new Set(tableConf.exclude), - modelName + modelName, + showField, + relation, + idName, }); return tableInfo; @@ -200,22 +209,24 @@ module.exports = class MyLogger { // Fetch primary key - const [dbPks] = await db.query( - `SELECT COLUMN_NAME idName - FROM information_schema.KEY_COLUMN_USAGE - WHERE CONSTRAINT_NAME = 'PRIMARY' - AND TABLE_NAME = ? - AND TABLE_SCHEMA = ?`, - [table, schema] - ); + if (!tableConf.idName) { + const [dbPks] = await db.query( + `SELECT COLUMN_NAME idName + FROM information_schema.KEY_COLUMN_USAGE + WHERE CONSTRAINT_NAME = 'PRIMARY' + AND TABLE_NAME = ? + AND TABLE_SCHEMA = ?`, + [table, schema] + ); - if (!dbPks.length) - throw new Error(`Primary not found for table: ${schema}.${table}`); - if (dbPks.length > 1) - throw new Error(`Only one column primary is supported: ${schema}.${table}`); + if (!dbPks.length) + throw new Error(`Primary not found for table: ${schema}.${table}`); + if (dbPks.length > 1) + throw new Error(`Only one column primary is supported: ${schema}.${table}`); - for (const {idName} of dbPks) - tableInfo.idName = idName; + for (const {idName} of dbPks) + tableInfo.idName = idName; + } // Get show field diff --git a/package.json b/package.json index 10090c5..c0cbacb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mylogger", - "version": "0.1.7", + "version": "0.1.9", "author": "Verdnatura Levante SL", "description": "MySQL and MariaDB logger using binary log", "license": "GPL-3.0",