From f5fd0f9309b257f55e0a5588d5f018546a1b8bd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B7=E5=8B=87?= Date: Tue, 22 Aug 2023 18:03:05 +0800 Subject: [PATCH] Add replace --- dbpool.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dbpool.go b/dbpool.go index 1414b75..b18c4fc 100644 --- a/dbpool.go +++ b/dbpool.go @@ -130,6 +130,16 @@ func (this *dbPool) Insert( 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, ¶ms) + this.internalExec(dataSource, sql, params, cb) +} + func (this *dbPool) Upsert( dataSource string, tblName string, @@ -274,7 +284,7 @@ func (this *dbPool) joinInsertFields(fieldsKv [][]string, params *[]string) stri *params = append(*params, items[1]) } sql += ")" - return "" + return sql } func (this *dbPool) internalExec(dataSource string, sql string, params []string,