改进退出程序时关闭数据库写入

This commit is contained in:
GoEdgeLab
2023-06-23 17:45:39 +08:00
parent 54787a8a8e
commit 67355c85bd
12 changed files with 25 additions and 10 deletions

View File

@@ -45,6 +45,9 @@ func (this *Batch) OnFail(callback func(err error)) {
}
func (this *Batch) Add(query string, args ...any) {
if this.isClosed {
return
}
this.queue <- &batchItem{
query: query,
args: args,
@@ -139,6 +142,10 @@ func (this *Batch) beginTx() *sql.Tx {
}
func (this *Batch) execItem(tx *sql.Tx, item *batchItem) error {
if this.isClosed {
return nil
}
if this.enableStat {
defer SharedQueryStatManager.AddQuery(item.query).End()
}