Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
muidea committed Sep 25, 2023
1 parent 5b9dba7 commit 55b0bcc
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions orm/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type Orm interface {
}

var name2Pool sync.Map
var name2PoolInitializeOnce sync.Once
var name2PoolUninitializedOnce sync.Once

// NewPool new executor pool
func NewPool() executor.Pool {
Expand All @@ -47,19 +49,23 @@ func NewConfig(dbServer, dbName, username, password, charSet string) executor.Co

// Initialize InitOrm
func Initialize() {
name2Pool = sync.Map{}
name2PoolInitializeOnce.Do(func() {
name2Pool = sync.Map{}
})
}

// Uninitialized orm
func Uninitialized() {
name2Pool.Range(func(_, val interface{}) bool {
pool := val.(executor.Pool)
pool.Uninitialized()
name2PoolUninitializedOnce.Do(func() {
name2Pool.Range(func(_, val interface{}) bool {
pool := val.(executor.Pool)
pool.Uninitialized()

return true
})
return true
})

name2Pool = sync.Map{}
name2Pool = sync.Map{}
})
}

func AddDatabase(dbServer, dbName, username, password, charSet string, maxConnNum int, owner string) (err error) {
Expand Down

0 comments on commit 55b0bcc

Please sign in to comment.