From eb482c3b277db6792f5a63a7d9eea835fee3fc90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B7=E5=8B=87?= Date: Tue, 26 Sep 2023 16:26:04 +0800 Subject: [PATCH] add SyncSelectCustomQuery --- dbpool.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/dbpool.go b/dbpool.go index c9ce380..7b8abcb 100644 --- a/dbpool.go +++ b/dbpool.go @@ -89,6 +89,31 @@ func (this *dbPool) SelectCustomQuery(dataSource string, sql string, cb QueryRes this.internalQuery(dataSource, sql, params, cb) } +func (this *dbPool) SyncSelectCustomQuery(dataSource string, sql string, cb QueryResultCb) { + chDone := make(chan bool) + params := []string{} + if this.style == GO_STYLE_DB { + go this.internalQuery(dataSource, sql, params, + func(err error, ds *DataSet) { + cb(err, ds) + chDone <- true + }) + } else { + this.internalQuery(dataSource, sql, params, + func(err error, ds *DataSet) { + cb(err, ds) + chDone <- true + }) + } + for { + select { + case <-chDone: + close(chDone) + return + } + } +} + func (this *dbPool) SelectLike( dataSource string, tblName string,