refs #5541 Added/fixed per table: showField, relation, idName
gitea/mylogger/pipeline/head This commit looks good Details

This commit is contained in:
Juan Ferrer 2023-04-12 18:57:15 +02:00
parent 7c27e96243
commit c007d316e8
3 changed files with 28 additions and 16 deletions

View File

@ -22,6 +22,7 @@ dstDb:
showFields: showFields:
- name - name
- description - description
- nickname
castTypes: castTypes:
tinyint: boolean tinyint: boolean
logs: logs:

View File

@ -64,10 +64,19 @@ module.exports = class MyLogger {
? toUpperCamelCase(table.name) ? toUpperCamelCase(table.name)
: table.name; : table.name;
const {
showField,
relation,
idName
} = tableConf;
Object.assign(tableInfo, { Object.assign(tableInfo, {
conf: tableConf, conf: tableConf,
exclude: new Set(tableConf.exclude), exclude: new Set(tableConf.exclude),
modelName modelName,
showField,
relation,
idName,
}); });
return tableInfo; return tableInfo;
@ -200,22 +209,24 @@ module.exports = class MyLogger {
// Fetch primary key // Fetch primary key
const [dbPks] = await db.query( if (!tableConf.idName) {
`SELECT COLUMN_NAME idName const [dbPks] = await db.query(
FROM information_schema.KEY_COLUMN_USAGE `SELECT COLUMN_NAME idName
WHERE CONSTRAINT_NAME = 'PRIMARY' FROM information_schema.KEY_COLUMN_USAGE
AND TABLE_NAME = ? WHERE CONSTRAINT_NAME = 'PRIMARY'
AND TABLE_SCHEMA = ?`, AND TABLE_NAME = ?
[table, schema] AND TABLE_SCHEMA = ?`,
); [table, schema]
);
if (!dbPks.length) if (!dbPks.length)
throw new Error(`Primary not found for table: ${schema}.${table}`); throw new Error(`Primary not found for table: ${schema}.${table}`);
if (dbPks.length > 1) if (dbPks.length > 1)
throw new Error(`Only one column primary is supported: ${schema}.${table}`); throw new Error(`Only one column primary is supported: ${schema}.${table}`);
for (const {idName} of dbPks) for (const {idName} of dbPks)
tableInfo.idName = idName; tableInfo.idName = idName;
}
// Get show field // Get show field

View File

@ -1,6 +1,6 @@
{ {
"name": "mylogger", "name": "mylogger",
"version": "0.1.7", "version": "0.1.9",
"author": "Verdnatura Levante SL", "author": "Verdnatura Levante SL",
"description": "MySQL and MariaDB logger using binary log", "description": "MySQL and MariaDB logger using binary log",
"license": "GPL-3.0", "license": "GPL-3.0",