refs #5541 Added/fixed per table: showField, relation, idName
gitea/mylogger/pipeline/head This commit looks good
Details
gitea/mylogger/pipeline/head This commit looks good
Details
This commit is contained in:
parent
7c27e96243
commit
c007d316e8
|
@ -22,6 +22,7 @@ dstDb:
|
|||
showFields:
|
||||
- name
|
||||
- description
|
||||
- nickname
|
||||
castTypes:
|
||||
tinyint: boolean
|
||||
logs:
|
||||
|
|
41
mylogger.js
41
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
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue