mirror of
https://gitee.com/dromara/mayfly-go
synced 2026-01-04 05:36:35 +08:00
fix: model.FillBaseInfo遗漏调整完善等
This commit is contained in:
@@ -25,6 +25,17 @@ func (dbType DbType) Equal(typ string) bool {
|
||||
return ToDbType(typ) == dbType
|
||||
}
|
||||
|
||||
func (dbType DbType) QuoteIdentifier(name string) string {
|
||||
switch dbType {
|
||||
case DbTypeMysql, DbTypeMariadb:
|
||||
return quoteIdentifier(name, "`")
|
||||
case DbTypePostgres:
|
||||
return pq.QuoteIdentifier(name)
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid database type: %s", dbType))
|
||||
}
|
||||
}
|
||||
|
||||
func (dbType DbType) MetaDbName() string {
|
||||
switch dbType {
|
||||
case DbTypeMysql, DbTypeMariadb:
|
||||
@@ -38,14 +49,13 @@ func (dbType DbType) MetaDbName() string {
|
||||
}
|
||||
}
|
||||
|
||||
func (dbType DbType) QuoteIdentifier(name string) string {
|
||||
// 包装字段名,防止使用了数据库保留关键字
|
||||
func (dbType DbType) WrapName(name string) string {
|
||||
switch dbType {
|
||||
case DbTypeMysql, DbTypeMariadb:
|
||||
return quoteIdentifier(name, "`")
|
||||
case DbTypePostgres:
|
||||
return pq.QuoteIdentifier(name)
|
||||
return fmt.Sprintf("`%s`", name)
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid database type: %s", dbType))
|
||||
return fmt.Sprintf(`"%s"`, name)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,9 +90,6 @@ type DbDialect interface {
|
||||
// GetDbProgram 获取数据库程序模块,用于数据库备份与恢复
|
||||
GetDbProgram() DbProgram
|
||||
|
||||
// 封装名字,如,mysql: `table_name`, dm: "table_name"
|
||||
WrapName(name string) string
|
||||
|
||||
// 批量保存数据
|
||||
BatchInsert(tx *sql.Tx, tableName string, columns []string, values [][]any) (int64, error)
|
||||
|
||||
|
||||
@@ -278,10 +278,6 @@ func (dd *DMDialect) GetDbProgram() DbProgram {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (dd *DMDialect) WrapName(name string) string {
|
||||
return "\"" + name + "\""
|
||||
}
|
||||
|
||||
func (dd *DMDialect) GetDataType(dbColumnType string) DataType {
|
||||
if regexp.MustCompile(`(?i)int|double|float|number|decimal|byte|bit`).MatchString(dbColumnType) {
|
||||
return DataTypeNumber
|
||||
@@ -311,7 +307,7 @@ func (dd *DMDialect) BatchInsert(tx *sql.Tx, tableName string, columns []string,
|
||||
// 去除最后一个逗号,占位符由括号包裹
|
||||
placeholder := fmt.Sprintf("(%s)", strings.TrimSuffix(repeated, ","))
|
||||
|
||||
sqlTemp := fmt.Sprintf("insert into %s (%s) values %s", dd.WrapName(tableName), strings.Join(columns, ","), placeholder)
|
||||
sqlTemp := fmt.Sprintf("insert into %s (%s) values %s", dd.dc.Info.Type.WrapName(tableName), strings.Join(columns, ","), placeholder)
|
||||
effRows := 0
|
||||
for _, value := range values {
|
||||
// 达梦数据库只能一条条的执行insert
|
||||
|
||||
@@ -202,10 +202,6 @@ func (md *MysqlDialect) GetDbProgram() DbProgram {
|
||||
return NewDbProgramMysql(md.dc)
|
||||
}
|
||||
|
||||
func (md *MysqlDialect) WrapName(name string) string {
|
||||
return "`" + name + "`"
|
||||
}
|
||||
|
||||
func (md *MysqlDialect) GetDataType(dbColumnType string) DataType {
|
||||
if regexp.MustCompile(`(?i)int|double|float|number|decimal|byte|bit`).MatchString(dbColumnType) {
|
||||
return DataTypeNumber
|
||||
@@ -240,7 +236,7 @@ func (md *MysqlDialect) BatchInsert(tx *sql.Tx, tableName string, columns []stri
|
||||
// 去除最后一个逗号
|
||||
placeholder = strings.TrimSuffix(repeated, ",")
|
||||
|
||||
sqlStr := fmt.Sprintf("insert into %s (%s) values %s", md.WrapName(tableName), strings.Join(columns, ","), placeholder)
|
||||
sqlStr := fmt.Sprintf("insert into %s (%s) values %s", md.dc.Info.Type.WrapName(tableName), strings.Join(columns, ","), placeholder)
|
||||
// 执行批量insert sql
|
||||
// 把二维数组转为一维数组
|
||||
var args []any
|
||||
|
||||
@@ -280,10 +280,6 @@ func (pd *PgsqlDialect) GetDbProgram() DbProgram {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (pd *PgsqlDialect) WrapName(name string) string {
|
||||
return fmt.Sprintf(`"%s"`, name)
|
||||
}
|
||||
|
||||
func (pd *PgsqlDialect) GetDataType(dbColumnType string) DataType {
|
||||
if regexp.MustCompile(`(?i)int|double|float|number|decimal|byte|bit`).MatchString(dbColumnType) {
|
||||
return DataTypeNumber
|
||||
@@ -323,7 +319,7 @@ func (pd *PgsqlDialect) BatchInsert(tx *sql.Tx, tableName string, columns []stri
|
||||
placeholders = append(placeholders, "("+strings.Join(placeholder, ", ")+")")
|
||||
}
|
||||
|
||||
sqlStr := fmt.Sprintf("insert into %s (%s) values %s", pd.WrapName(tableName), strings.Join(columns, ","), strings.Join(placeholders, ", "))
|
||||
sqlStr := fmt.Sprintf("insert into %s (%s) values %s", pd.dc.Info.Type.WrapName(tableName), strings.Join(columns, ","), strings.Join(placeholders, ", "))
|
||||
// 执行批量insert sql
|
||||
|
||||
return pd.dc.TxExec(tx, sqlStr, args...)
|
||||
|
||||
Reference in New Issue
Block a user