Browse Source

(*)元数据采集 元数据表增加数据源返回信息

master
peng.peng 2 years ago
parent
commit
fa2053a713
  1. 4
      api/app/lib/controllers/auth/index.js
  2. 3
      api/app/lib/controllers/metadataAcquisition/taskHandle.js
  3. 35
      api/app/lib/controllers/metadataSearch/index.js
  4. 2
      api/app/lib/models/data_source.js
  5. 9
      api/app/lib/models/metadata_database.js
  6. 7
      api/app/lib/routes/metadataSearch/index.js

4
api/app/lib/controllers/auth/index.js

@ -19,12 +19,12 @@ async function login (ctx, next) {
attributes: { exclude: ['password'] }, attributes: { exclude: ['password'] },
where: { where: {
username: params.username, username: params.username,
password: password password: password,
}, },
}); });
} }
if (userRes) { if (userRes) {
if (userRes.forbidden) { if (!userRes.enabled) {
throw '用户已禁用' throw '用户已禁用'
} else { } else {
const token = uuid.v4(); const token = uuid.v4();

3
api/app/lib/controllers/metadataAcquisition/taskHandle.js

@ -75,6 +75,8 @@ async function handleTask(app, task) {
dataToSave.name = table; dataToSave.name = table;
dataToSave.code = table; dataToSave.code = table;
dataToSave.type = '表'; dataToSave.type = '表';
dataToSave.datasourceConfig = dataSource.config;
const tableObj = { ...dataToSave } const tableObj = { ...dataToSave }
tableBodys.push(tableObj) tableBodys.push(tableObj)
} }
@ -93,6 +95,7 @@ async function handleTask(app, task) {
dataToSave.name = table; dataToSave.name = table;
dataToSave.code = table; dataToSave.code = table;
dataToSave.type = '表'; dataToSave.type = '表';
dataToSave.datasourceConfig = dataSource.config;
const tableObj = { ...dataToSave } const tableObj = { ...dataToSave }
tableBodys.push(tableObj) tableBodys.push(tableObj)
}); });

35
api/app/lib/controllers/metadataSearch/index.js

@ -1,4 +1,5 @@
'use strict'; 'use strict';
const { Pool } = require('pg');
function searchMeta(opts) { function searchMeta(opts) {
return async function (ctx, next) { return async function (ctx, next) {
@ -66,6 +67,38 @@ function searchMeta(opts) {
} }
} }
// 新增模型
function getTableData(opts) {
return async function (ctx, next) {
const models = ctx.fs.dc.models;
try {
const { id } = ctx.query;
let { user, host, database, password, port } = ctx.request.body;
const pool = new Pool({
user: user,
host: host,
database: database,
password: password,
port: port,
})
const client = await pool.connect()
const tableName = "user"
const ress = await client.query(`SELECT * from "${tableName}"`, [])
console.log(ress.rows)
ctx.status = 200;
ctx.body = { rslt: ress.rows }
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 200;
ctx.body = { message: '连接失败' }
}
}
}
module.exports = { module.exports = {
searchMeta searchMeta,
getTableData
} }

2
api/app/lib/models/data_source.js

@ -98,7 +98,7 @@ module.exports = dc => {
}, },
type: { type: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "元数据类型", comment: "元数据类型",
primaryKey: false, primaryKey: false,

9
api/app/lib/models/metadata_database.js

@ -122,6 +122,15 @@ module.exports = dc => {
primaryKey: false, primaryKey: false,
field: "catalogKey", field: "catalogKey",
autoIncrement: false autoIncrement: false
},
datasourceConfig: {
type: DataTypes.JSONB,
allowNull: true,
defaultValue: null,
comment: null,
primaryKey: false,
field: "datasource_config",
autoIncrement: false
} }
}, { }, {
tableName: "t_metadata_database", tableName: "t_metadata_database",

7
api/app/lib/routes/metadataSearch/index.js

@ -3,7 +3,10 @@
const search = require('../../controllers/metadataSearch/index'); const search = require('../../controllers/metadataSearch/index');
module.exports = function (app, router, opts, AuthCode) { module.exports = function (app, router, opts, AuthCode) {
//获取适配器列表 //元数据资源检索
app.fs.api.logAttr['GET/meta/data/search'] = { content: '获取适配器列表', visible: true }; app.fs.api.logAttr['GET/meta/data/search'] = { content: '元数据资源检索', visible: true };
router.get('/meta/data/search', search.searchMeta(opts)); router.get('/meta/data/search', search.searchMeta(opts));
app.fs.api.logAttr['GET/meta/table/data'] = { content: '查询元数据表数据', visible: true };
router.get('/meta/table/data', search.getTableData(opts))
}; };

Loading…
Cancel
Save