Files
mayfly-go/server/internal/db/dbm/dm/meta.go
zongyangleo 9a59749763 !86 dbms支持sqlite和一些bug修复
* fix: 达梦数据库连接修复,以支持带特殊字符的密码和schema
* fix: oracle bug修复
* feat: dbms支持sqlite
* fix: dbms 修改字段名bug
2024-01-19 08:59:35 +00:00

55 lines
1.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package dm
import (
"database/sql"
"fmt"
"mayfly-go/internal/db/dbm/dbi"
"net/url"
"strings"
"sync"
)
var (
meta dbi.Meta
once sync.Once
)
func GetMeta() dbi.Meta {
once.Do(func() {
meta = new(DmMeta)
})
return meta
}
type DmMeta struct {
}
func (md *DmMeta) GetSqlDb(d *dbi.DbInfo) (*sql.DB, error) {
driverName := "dm"
db := d.Database
var dbParam string
if db != "" {
// dm database可以使用db/schema表示方便连接指定schema, 若不存在schema则使用默认schema
ss := strings.Split(db, "/")
if len(ss) > 1 {
dbParam = fmt.Sprintf("%s?schema=\"%s\"&escapeProcess=true", ss[0], ss[len(ss)-1])
} else {
dbParam = db + "?escapeProcess=true"
}
} else {
dbParam = "?escapeProcess=true"
}
err := d.IfUseSshTunnelChangeIpPort()
if err != nil {
return nil, err
}
dsn := fmt.Sprintf("dm://%s:%s@%s:%d/%s", d.Username, url.PathEscape(d.Password), d.Host, d.Port, dbParam)
return sql.Open(driverName, dsn)
}
func (md *DmMeta) GetDialect(conn *dbi.DbConn) dbi.Dialect {
return &DMDialect{conn}
}