salix/loopback/common/methods/application/getI18nTables.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

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'
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'
`);
for (const column of columns)
tables.find(t => t.tableName == column.tableName).field = column.field;
return tables;
};
};