1
0
mirror of https://github.com/astaxie/beego.git synced 2025-06-12 21:30:39 +00:00

Optimize orm by using BDOption rather than hints

This commit is contained in:
Ming Deng
2020-09-08 20:47:39 +08:00
parent 9ccd58bfff
commit f580a714d5
7 changed files with 63 additions and 102 deletions

View File

@ -20,8 +20,6 @@ import (
"time"
"github.com/astaxie/beego/pkg/client/orm"
"github.com/astaxie/beego/pkg/client/orm/hints"
"github.com/astaxie/beego/pkg/infrastructure/utils"
)
// DriverType database driver constant int.
@ -86,13 +84,13 @@ func AddAliasWthDB(aliasName, driverName string, db *sql.DB) error {
// RegisterDataBase Setting the database connect params. Use the database driver self dataSource args.
func RegisterDataBase(aliasName, driverName, dataSource string, params ...int) error {
opts := make([]utils.KV, 0, 2)
opts := make([]orm.DBOption, 0, 2)
if len(params) > 0 {
opts = append(opts, hints.MaxIdleConnections(params[0]))
opts = append(opts, orm.MaxIdleConnections(params[0]))
}
if len(params) > 1 {
opts = append(opts, hints.MaxOpenConnections(params[1]))
opts = append(opts, orm.MaxOpenConnections(params[1]))
}
return orm.RegisterDataBase(aliasName, driverName, dataSource, opts...)
}