Add replace

This commit is contained in:
殷勇 2023-08-22 18:03:05 +08:00
parent 1055774a44
commit f5fd0f9309

View File

@ -130,6 +130,16 @@ func (this *dbPool) Insert(
this.internalExec(dataSource, sql, params, cb) this.internalExec(dataSource, sql, params, cb)
} }
func (this *dbPool) Replace(
dataSource string,
tblName string,
fieldsKv [][]string,
cb ExecResultCb) {
params := []string{}
sql := "REPLACE INTO `" + tblName + "` " + this.joinInsertFields(fieldsKv, &params)
this.internalExec(dataSource, sql, params, cb)
}
func (this *dbPool) Upsert( func (this *dbPool) Upsert(
dataSource string, dataSource string,
tblName string, tblName string,
@ -274,7 +284,7 @@ func (this *dbPool) joinInsertFields(fieldsKv [][]string, params *[]string) stri
*params = append(*params, items[1]) *params = append(*params, items[1])
} }
sql += ")" sql += ")"
return "" return sql
} }
func (this *dbPool) internalExec(dataSource string, sql string, params []string, func (this *dbPool) internalExec(dataSource string, sql string, params []string,