mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-04 00:10:25 +08:00
refactor: code review
This commit is contained in:
@@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
pq "gitee.com/opengauss/openGauss-connector-go-pq"
|
||||
"github.com/kanzihuang/vitess/go/vt/sqlparser"
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
type DbType string
|
||||
|
||||
@@ -12,11 +12,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
pq "gitee.com/opengauss/openGauss-connector-go-pq"
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
func getPgsqlDB(d *DbInfo) (*sql.DB, error) {
|
||||
driverName := "opengauss"
|
||||
driverName := string(d.Type)
|
||||
// SSH Conect
|
||||
if d.SshTunnelMachineId > 0 {
|
||||
// 如果使用了隧道,则使用`postgres:ssh:隧道机器id`注册名
|
||||
@@ -41,7 +41,7 @@ func getPgsqlDB(d *DbInfo) (*sql.DB, error) {
|
||||
}
|
||||
}
|
||||
|
||||
dsn := fmt.Sprintf("host=%s port=%d user=%s password='%s' %s sslmode=disable", d.Host, d.Port, d.Username, d.Password, dbParam)
|
||||
dsn := fmt.Sprintf("host=%s port=%d user=%s password=%s %s sslmode=disable", d.Host, d.Port, d.Username, d.Password, dbParam)
|
||||
// 存在额外指定参数,则拼接该连接参数
|
||||
if d.Params != "" {
|
||||
// 存在指定的db,则需要将dbInstance配置中的parmas排除掉dbname和search_path
|
||||
|
||||
@@ -45,13 +45,13 @@ func (dbInfo *DbInfo) Conn() (*DbConn, error) {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
logx.Errorf("连接db失败: %s:%d/%s", dbInfo.Host, dbInfo.Port, database)
|
||||
logx.Errorf("连接db失败: %s:%d/%s, err:%s", dbInfo.Host, dbInfo.Port, database, err.Error())
|
||||
return nil, errorx.NewBiz(fmt.Sprintf("数据库连接失败: %s", err.Error()))
|
||||
}
|
||||
|
||||
err = conn.Ping()
|
||||
if err != nil {
|
||||
logx.Errorf("db ping失败: %s:%d/%s", dbInfo.Host, dbInfo.Port, database)
|
||||
logx.Errorf("db ping失败: %s:%d/%s, err:%s", dbInfo.Host, dbInfo.Port, database, err.Error())
|
||||
return nil, errorx.NewBiz(fmt.Sprintf("数据库连接失败: %s", err.Error()))
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ SELECT
|
||||
case when column_default like 'nextval%%' then 'PRI' else '' end "columnKey",
|
||||
col_description((table_schema || '.' || table_name)::regclass, ordinal_position) AS "columnComment"
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = (select current_schema()) and table_name = %s
|
||||
WHERE table_schema = (select current_schema()) and table_name in (%s)
|
||||
order by table_name, ordinal_position
|
||||
---------------------------------------
|
||||
--PGSQL_TABLE_DDL_FUNC 表ddl函数
|
||||
|
||||
Reference in New Issue
Block a user