|
|
@ -1,4 +1,5 @@ |
|
|
|
'use strict'; |
|
|
|
const { Pool } = require('pg'); |
|
|
|
|
|
|
|
function searchMeta(opts) { |
|
|
|
return async function (ctx, next) { |
|
|
@ -52,7 +53,7 @@ function searchMeta(opts) { |
|
|
|
const rslt2 = await models.MetadataFile.findAndCountAll(findObj2); |
|
|
|
const rslt3 = await models.MetadataRestapi.findAndCountAll(findObj3); |
|
|
|
const fileRslt = rslt2.rows.map(s => { return { ...s.dataValues, type: '文件', tagDatabases: s.tagFiles } }) |
|
|
|
const restapiRslt = rslt3.rows.map(s => { return { ...s.dataValues, type: '接口', tagDatabases: s.tagRestapis } }) |
|
|
|
const restapiRslt = rslt3.rows.map(s => { return { ...s.dataValues, type: '接口', tagDatabases: s.tagRestapis } }) |
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = { |
|
|
|
count: rslt1.count + rslt2.count + rslt3.count, |
|
|
@ -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 = { |
|
|
|
searchMeta |
|
|
|
searchMeta, |
|
|
|
getTableData |
|
|
|
} |