Update gorp dialect depending on DB type used

This commit is contained in:
Aaron Lindsay 2017-10-03 19:37:58 -04:00
parent c1dc6a21e8
commit 9abafa50b2
1 changed files with 15 additions and 1 deletions

16
db.go
View File

@ -17,7 +17,21 @@ func initDB(cfg *Config) {
log.Fatal(err)
}
dbmap := &gorp.DbMap{Db: db, Dialect: gorp.SqliteDialect{}}
var dialect gorp.Dialect
if cfg.MoneyGo.DBType == SQLite {
dialect = gorp.SqliteDialect{}
} else if cfg.MoneyGo.DBType == MySQL {
dialect = gorp.MySQLDialect{
Engine: "InnoDB",
Encoding: "UTF8",
}
} else if cfg.MoneyGo.DBType == Postgres {
dialect = gorp.PostgresDialect{}
} else {
log.Fatalf("Don't know gorp dialect to go with '%s' DB type", cfg.MoneyGo.DBType.String())
}
dbmap := &gorp.DbMap{Db: db, Dialect: dialect}
dbmap.AddTableWithName(User{}, "users").SetKeys(true, "UserId")
dbmap.AddTableWithName(Session{}, "sessions").SetKeys(true, "SessionId")
dbmap.AddTableWithName(Account{}, "accounts").SetKeys(true, "AccountId")