40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
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 <> 'id'
|
|
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'
|
|
AND c.column_name <> 'id'
|
|
`);
|
|
|
|
for (const column of columns)
|
|
tables.find(t => t.tableName == column.tableName).field = column.field;
|
|
return tables;
|
|
};
|
|
};
|