Add Upsert 方法

This commit is contained in:
殷勇 2023-08-24 11:22:15 +08:00
parent f5fd0f9309
commit 0391e1a006

View File

@ -143,10 +143,22 @@ func (this *dbPool) Replace(
func (this *dbPool) Upsert( func (this *dbPool) Upsert(
dataSource string, dataSource string,
tblName string, tblName string,
whereKv map[string]string, whereKv [][]string,
updateKv map[string]string, updateKv [][]string,
insertKv map[string]string, insertKv [][]string,
cb ExecResultCb) { 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( func (this *dbPool) PageQuery(