提交 664776a3 编写于 作者: Sliver_Horn's avatar Sliver_Horn

refactor:

- pgsql 获取指定数据库和指定数据表的所有字段名,类型值等 sql 添加字段备注
上级 f11c0eec
......@@ -7,6 +7,7 @@ import (
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"strings"
)
var AutoCodePgsql = new(autoCodePgsql)
......@@ -60,17 +61,29 @@ func (a *autoCodePgsql) GetColumn(tableName string, dbName string) (data []respo
WHEN 'bigint' THEN
concat_ws('', '', columns.NUMERIC_PRECISION)
ELSE ''
END AS data_type_long
END AS data_type_long,
(select description.description
from pg_description description
where description.objoid = (select attribute.attrelid
from pg_attribute attribute
where attribute.attrelid =
(select oid from pg_class class where class.relname = '@table_name') and attname =columns.COLUMN_NAME )
and description.objsubid = (select attribute.attnum
from pg_attribute attribute
where attribute.attrelid =
(select oid from pg_class class where class.relname = '@table_name') and attname =columns.COLUMN_NAME )) as column_comment
FROM INFORMATION_SCHEMA.COLUMNS columns
WHERE table_catalog = ?
and table_schema = ?
and table_name = ?
WHERE table_catalog = '@table_catalog'
and table_schema = 'public'
and table_name = '@table_name';
`
var entities []response.Column
db, _err := gorm.Open(postgres.Open(global.GVA_CONFIG.Pgsql.LinkDsn(dbName)), &gorm.Config{Logger: logger.Default.LogMode(logger.Info)})
if _err != nil {
return nil, errors.Wrapf(err, "[pgsql] 连接 数据库(%s)的表(%s)失败!", dbName, tableName)
}
err = db.Raw(sql, dbName, "public", tableName).Scan(&entities).Error
sql = strings.ReplaceAll(sql, "@table_catalog", dbName)
sql = strings.ReplaceAll(sql, "@table_name", tableName)
err = db.Raw(sql).Scan(&entities).Error
return entities, err
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册