diff --git a/dbpool.go b/dbpool.go index 26113d1..2a00823 100644 --- a/dbpool.go +++ b/dbpool.go @@ -38,7 +38,7 @@ func (this *dbPool) unInit() { } func (this *dbPool) RegisterDataSource(name string, host string, port int32, - user string, passwd string, dataBase string, size int32) { + user string, passwd string, dataBase string, size int32, maxOpenConns int32, maxIdleConns int32) { this.lock.Lock() defer this.lock.Unlock() var head *q5.ListHead @@ -48,10 +48,16 @@ func (this *dbPool) RegisterDataSource(name string, host string, port int32, head = q5.NewListHead() this.dataSourceHash[name] = head } + if maxOpenConns <= 0 { + maxOpenConns = 1 + } + if maxIdleConns <= 0 { + maxIdleConns = 1 + } for i := int32(0); i < size; i++ { ds := dataSource{} ds.name = name - ds.conn = q5.NewMysql(host, port, user, passwd, dataBase) + ds.conn = q5.NewMysql(host, port, user, passwd, dataBase, maxOpenConns, maxIdleConns) ds.entry.Init(&ds) head.AddTail(&ds.entry) err := ds.conn.Open()