2024-10-22 07:48:53 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('getI18nTables', {
|
|
|
|
description: 'Return tables with name end with i18n',
|
|
|
|
accessType: 'READ',
|
|
|
|
accepts: [],
|
|
|
|
returns: {
|
|
|
|
type: 'Array',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/get-i18n-tables`,
|
|
|
|
verb: 'GET'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Self.getI18nTables = async() => {
|
|
|
|
const tables = await Self.rawSql(`
|
|
|
|
SELECT c.table_name tableName, c.column_name primaryKey
|
|
|
|
FROM information_schema.columns c
|
|
|
|
WHERE
|
|
|
|
c.table_name LIKE '%i18n'
|
|
|
|
AND c.COLUMN_KEY = 'PRI'
|
2024-10-28 10:52:56 +00:00
|
|
|
AND c.column_name <> 'id'
|
2024-10-22 07:48:53 +00:00
|
|
|
AND c.COLUMN_NAME <> 'lang'`);
|
|
|
|
|
|
|
|
const columns = await Self.rawSql(`
|
|
|
|
SELECT c.table_name tableName, c.column_name field
|
|
|
|
FROM information_schema.columns c
|
|
|
|
WHERE
|
|
|
|
c.table_name LIKE '%i18n'
|
|
|
|
AND c.COLUMN_KEY <> 'PRI'
|
2024-10-28 10:52:56 +00:00
|
|
|
AND c.column_name <> 'id'
|
2024-10-22 07:48:53 +00:00
|
|
|
`);
|
|
|
|
|
|
|
|
for (const column of columns)
|
|
|
|
tables.find(t => t.tableName == column.tableName).field = column.field;
|
|
|
|
return tables;
|
|
|
|
};
|
|
|
|
};
|