mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-06 20:03:05 +08:00
- 数据源支持:新增 OceanBase 与 OpenGauss optional driver-agent 实现 - 连接适配:复用 MySQL/PostgreSQL 兼容链路并补齐查询、DDL、同步能力 - 前端入口:补充连接表单、侧边栏、图标、SQL 方言和危险操作识别 - 驱动管理:更新 driver manifest、安装提示和 revision 自动生成链路 - 构建发布:支持多平台 driver-agent 打包并优化 release 构建失败提示
84 lines
2.0 KiB
Go
84 lines
2.0 KiB
Go
//go:build gonavi_full_drivers || gonavi_opengauss_driver
|
|
|
|
package db
|
|
|
|
import (
|
|
"net"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"GoNavi-Wails/internal/connection"
|
|
)
|
|
|
|
const defaultOpenGaussPort = 5432
|
|
|
|
// OpenGaussDB 使用 PostgreSQL wire protocol 兼容链路,通过独立 agent 类型暴露。
|
|
type OpenGaussDB struct {
|
|
PostgresDB
|
|
}
|
|
|
|
func applyOpenGaussURI(config connection.ConnectionConfig) connection.ConnectionConfig {
|
|
uriText := strings.TrimSpace(config.URI)
|
|
if uriText == "" {
|
|
return config
|
|
}
|
|
parsed, ok := parseConnectionURI(uriText, "opengauss", "postgres", "postgresql")
|
|
if !ok {
|
|
return config
|
|
}
|
|
|
|
if parsed.User != nil {
|
|
if config.User == "" {
|
|
config.User = parsed.User.Username()
|
|
}
|
|
if pass, ok := parsed.User.Password(); ok && config.Password == "" {
|
|
config.Password = pass
|
|
}
|
|
}
|
|
|
|
if dbName := strings.TrimPrefix(parsed.Path, "/"); dbName != "" && config.Database == "" {
|
|
config.Database = dbName
|
|
}
|
|
|
|
defaultPort := config.Port
|
|
if defaultPort <= 0 {
|
|
defaultPort = defaultOpenGaussPort
|
|
}
|
|
if strings.TrimSpace(config.Host) == "" && strings.TrimSpace(parsed.Host) != "" {
|
|
host, port, ok := parseHostPortWithDefault(parsed.Host, defaultPort)
|
|
if ok {
|
|
config.Host = host
|
|
config.Port = port
|
|
}
|
|
}
|
|
if config.Port <= 0 {
|
|
config.Port = defaultOpenGaussPort
|
|
}
|
|
|
|
return config
|
|
}
|
|
|
|
func (o *OpenGaussDB) getDSN(config connection.ConnectionConfig) string {
|
|
runConfig := applyOpenGaussURI(config)
|
|
if runConfig.Port <= 0 {
|
|
runConfig.Port = defaultOpenGaussPort
|
|
}
|
|
if strings.TrimSpace(runConfig.Host) != "" {
|
|
if host, port, err := net.SplitHostPort(runConfig.Host); err == nil {
|
|
runConfig.Host = host
|
|
if p, convErr := strconv.Atoi(port); convErr == nil && p > 0 {
|
|
runConfig.Port = p
|
|
}
|
|
}
|
|
}
|
|
return o.PostgresDB.getDSN(runConfig)
|
|
}
|
|
|
|
func (o *OpenGaussDB) Connect(config connection.ConnectionConfig) error {
|
|
runConfig := applyOpenGaussURI(config)
|
|
if runConfig.Port <= 0 {
|
|
runConfig.Port = defaultOpenGaussPort
|
|
}
|
|
return o.PostgresDB.Connect(runConfig)
|
|
}
|