parent
c6851fee50
commit
ba3d6ae64c
|
@ -4,4 +4,4 @@
|
|||
|
||||
build
|
||||
config.ini
|
||||
writefreely.db
|
||||
*.db
|
||||
|
|
6
app.go
6
app.go
|
@ -486,7 +486,11 @@ func connectToDatabase(app *app) {
|
|||
db, err = sql.Open(app.cfg.Database.Type, fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=true&loc=%s", app.cfg.Database.User, app.cfg.Database.Password, app.cfg.Database.Host, app.cfg.Database.Port, app.cfg.Database.Database, url.QueryEscape(time.Local.String())))
|
||||
db.SetMaxOpenConns(50)
|
||||
} else if app.cfg.Database.Type == "sqlite3" {
|
||||
db, err = sql.Open("sqlite3", "./writefreely.db?parseTime=true&cached=shared")
|
||||
if app.cfg.Database.FileName == "" {
|
||||
log.Error("SQLite database filename value in config.ini is empty.")
|
||||
os.Exit(1)
|
||||
}
|
||||
db, err = sql.Open("sqlite3", app.cfg.Database.FileName+"?parseTime=true&cached=shared")
|
||||
db.SetMaxOpenConns(1)
|
||||
} else {
|
||||
log.Error("Invalid database type '%s'. Only 'mysql' and 'sqlite3' are supported right now.", app.cfg.Database.Type)
|
||||
|
|
|
@ -22,6 +22,7 @@ type (
|
|||
|
||||
DatabaseCfg struct {
|
||||
Type string `ini:"type"`
|
||||
FileName string `ini:"filename"`
|
||||
User string `ini:"username"`
|
||||
Password string `ini:"password"`
|
||||
Database string `ini:"database"`
|
||||
|
|
Loading…
Reference in New Issue