Fix build failure with sqlite test
Cette révision appartient à :
Parent
4d87ba3b3e
révision
d165c431d3
2 fichiers modifiés avec 13 ajouts et 3 suppressions
14
db/gorm.go
14
db/gorm.go
|
@ -9,6 +9,10 @@ import (
|
||||||
_ "github.com/jinzhu/gorm/dialects/sqlite" // Need for sqlite
|
_ "github.com/jinzhu/gorm/dialects/sqlite" // Need for sqlite
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
SqliteType = "sqlite3"
|
||||||
|
)
|
||||||
|
|
||||||
// Logger interface
|
// Logger interface
|
||||||
type Logger interface {
|
type Logger interface {
|
||||||
Print(v ...interface{})
|
Print(v ...interface{})
|
||||||
|
@ -32,7 +36,7 @@ func GormInit(conf *config.Config, logger Logger) (*gorm.DB, error) {
|
||||||
return nil, openErr
|
return nil, openErr
|
||||||
}
|
}
|
||||||
|
|
||||||
IsSqlite = conf.DBType == "sqlite"
|
IsSqlite = conf.DBType == SqliteType
|
||||||
|
|
||||||
connectionErr := db.DB().Ping()
|
connectionErr := db.DB().Ping()
|
||||||
if connectionErr != nil {
|
if connectionErr != nil {
|
||||||
|
@ -41,7 +45,13 @@ func GormInit(conf *config.Config, logger Logger) (*gorm.DB, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Negative MaxIdleConns means don't retain any idle connection
|
// Negative MaxIdleConns means don't retain any idle connection
|
||||||
db.DB().SetMaxIdleConns(-1)
|
maxIdleConns := -1
|
||||||
|
if IsSqlite {
|
||||||
|
// sqlite doesn't like having a negative maxIdleConns
|
||||||
|
maxIdleConns = 10
|
||||||
|
}
|
||||||
|
|
||||||
|
db.DB().SetMaxIdleConns(maxIdleConns)
|
||||||
db.DB().SetMaxOpenConns(400)
|
db.DB().SetMaxOpenConns(400)
|
||||||
|
|
||||||
if config.Environment == "DEVELOPMENT" {
|
if config.Environment == "DEVELOPMENT" {
|
||||||
|
|
|
@ -26,7 +26,7 @@ func (logger *errorLogger) Print(values ...interface{}) {
|
||||||
|
|
||||||
func TestGormInitSqlite(t *testing.T) {
|
func TestGormInitSqlite(t *testing.T) {
|
||||||
conf := config.New()
|
conf := config.New()
|
||||||
conf.DBType = "sqlite3"
|
conf.DBType = SqliteType
|
||||||
conf.DBParams = ":memory:?cache=shared&mode=memory"
|
conf.DBParams = ":memory:?cache=shared&mode=memory"
|
||||||
conf.DBLogMode = "detailed"
|
conf.DBLogMode = "detailed"
|
||||||
|
|
||||||
|
|
Référencer dans un nouveau ticket