mirror of
https://github.com/astaxie/beego.git
synced 2025-06-13 14:10:38 +00:00
Optimize orm by using BDOption rather than hints
This commit is contained in:
@ -15,20 +15,12 @@
|
||||
package hints
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/pkg/infrastructure/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
//db level
|
||||
KeyMaxIdleConnections = iota
|
||||
KeyMaxOpenConnections
|
||||
KeyConnMaxLifetime
|
||||
KeyMaxStmtCacheSize
|
||||
|
||||
//query level
|
||||
KeyForceIndex
|
||||
KeyForceIndex = iota
|
||||
KeyUseIndex
|
||||
KeyIgnoreIndex
|
||||
KeyForUpdate
|
||||
@ -57,26 +49,6 @@ func (s *Hint) GetValue() interface{} {
|
||||
|
||||
var _ utils.KV = new(Hint)
|
||||
|
||||
// MaxIdleConnections return a hint about MaxIdleConnections
|
||||
func MaxIdleConnections(v int) *Hint {
|
||||
return NewHint(KeyMaxIdleConnections, v)
|
||||
}
|
||||
|
||||
// MaxOpenConnections return a hint about MaxOpenConnections
|
||||
func MaxOpenConnections(v int) *Hint {
|
||||
return NewHint(KeyMaxOpenConnections, v)
|
||||
}
|
||||
|
||||
// ConnMaxLifetime return a hint about ConnMaxLifetime
|
||||
func ConnMaxLifetime(v time.Duration) *Hint {
|
||||
return NewHint(KeyConnMaxLifetime, v)
|
||||
}
|
||||
|
||||
// MaxStmtCacheSize return a hint about MaxStmtCacheSize
|
||||
func MaxStmtCacheSize(v int) *Hint {
|
||||
return NewHint(KeyMaxStmtCacheSize, v)
|
||||
}
|
||||
|
||||
// ForceIndex return a hint about ForceIndex
|
||||
func ForceIndex(indexes ...string) *Hint {
|
||||
return NewHint(KeyForceIndex, indexes)
|
||||
|
@ -48,34 +48,6 @@ func TestNewHint_float(t *testing.T) {
|
||||
assert.Equal(t, hint.GetValue(), value)
|
||||
}
|
||||
|
||||
func TestMaxOpenConnections(t *testing.T) {
|
||||
i := 887423
|
||||
hint := MaxOpenConnections(i)
|
||||
assert.Equal(t, hint.GetValue(), i)
|
||||
assert.Equal(t, hint.GetKey(), KeyMaxOpenConnections)
|
||||
}
|
||||
|
||||
func TestConnMaxLifetime(t *testing.T) {
|
||||
i := time.Hour
|
||||
hint := ConnMaxLifetime(i)
|
||||
assert.Equal(t, hint.GetValue(), i)
|
||||
assert.Equal(t, hint.GetKey(), KeyConnMaxLifetime)
|
||||
}
|
||||
|
||||
func TestMaxIdleConnections(t *testing.T) {
|
||||
i := 42316
|
||||
hint := MaxIdleConnections(i)
|
||||
assert.Equal(t, hint.GetValue(), i)
|
||||
assert.Equal(t, hint.GetKey(), KeyMaxIdleConnections)
|
||||
}
|
||||
|
||||
func TestMaxStmtCacheSize(t *testing.T) {
|
||||
i := 94157
|
||||
hint := MaxStmtCacheSize(i)
|
||||
assert.Equal(t, hint.GetValue(), i)
|
||||
assert.Equal(t, hint.GetKey(), KeyMaxStmtCacheSize)
|
||||
}
|
||||
|
||||
func TestForceIndex(t *testing.T) {
|
||||
s := []string{`f_index1`, `f_index2`, `f_index3`}
|
||||
hint := ForceIndex(s...)
|
||||
|
Reference in New Issue
Block a user