mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-25 02:20:30 +08:00
refactor: dbms优化
This commit is contained in:
@@ -11,12 +11,9 @@ import (
|
||||
)
|
||||
|
||||
type PgsqlDialect struct {
|
||||
dc *dbi.DbConn
|
||||
}
|
||||
dbi.DefaultDialect
|
||||
|
||||
// GetDbProgram 获取数据库程序模块,用于数据库备份与恢复
|
||||
func (pd *PgsqlDialect) GetDbProgram() (dbi.DbProgram, error) {
|
||||
return nil, fmt.Errorf("该数据库类型不支持数据库备份与恢复: %v", pd.dc.Info.Type)
|
||||
dc *dbi.DbConn
|
||||
}
|
||||
|
||||
func (pd *PgsqlDialect) BatchInsert(tx *sql.Tx, tableName string, columns []string, values [][]any, duplicateStrategy int) (int64, error) {
|
||||
@@ -183,30 +180,6 @@ func (pd *PgsqlDialect) CopyTable(copy *dbi.DbCopyTable) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (pd *PgsqlDialect) TransColumns(columns []dbi.Column) []dbi.Column {
|
||||
var commonColumns []dbi.Column
|
||||
for _, column := range columns {
|
||||
// 取出当前数据库类型
|
||||
arr := strings.Split(column.ColumnType, "(")
|
||||
ctype := arr[0]
|
||||
// 翻译为通用数据库类型
|
||||
t1 := commonColumnTypeMap[ctype]
|
||||
if t1 == "" {
|
||||
ctype = "varchar(2000)"
|
||||
} else {
|
||||
// 回写到列信息
|
||||
if len(arr) > 1 {
|
||||
ctype = t1 + "(" + arr[1]
|
||||
} else {
|
||||
ctype = t1
|
||||
}
|
||||
}
|
||||
column.ColumnType = ctype
|
||||
commonColumns = append(commonColumns, column)
|
||||
}
|
||||
return commonColumns
|
||||
}
|
||||
|
||||
func (pd *PgsqlDialect) CreateTable(commonColumns []dbi.Column, tableInfo dbi.Table, dropOldTable bool) (int, error) {
|
||||
meta := pd.dc.GetMetaData()
|
||||
replacer := strings.NewReplacer(";", "", "'", "")
|
||||
@@ -224,7 +197,7 @@ func (pd *PgsqlDialect) CreateTable(commonColumns []dbi.Column, tableInfo dbi.Ta
|
||||
arr := strings.Split(column.ColumnType, "(")
|
||||
ctype := arr[0]
|
||||
// 翻译为通用数据库类型
|
||||
t1 := pgsqlColumnTypeMap[ctype]
|
||||
t1 := pgsqlColumnTypeMap[dbi.ColumnDataType(ctype)]
|
||||
if t1 == "" {
|
||||
ctype = "varchar(2000)"
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user