diff --git a/dbpool.go b/dbpool.go index b18c4fc..fc2ab87 100644 --- a/dbpool.go +++ b/dbpool.go @@ -143,10 +143,22 @@ func (this *dbPool) Replace( func (this *dbPool) Upsert( dataSource string, tblName string, - whereKv map[string]string, - updateKv map[string]string, - insertKv map[string]string, + whereKv [][]string, + updateKv [][]string, + insertKv [][]string, cb ExecResultCb) { + this.OrmSelectOne(dataSource, tblName, whereKv, + func(err error, ds *DataSet) { + if err != nil { + cb(err, 0, 0) + return + } + if ds.Next() { + this.Update(dataSource, tblName, updateKv, whereKv, cb) + } else { + this.Insert(dataSource, tblName, insertKv, cb) + } + }) } func (this *dbPool) PageQuery(