1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2024-12-26 07:33:21 -05:00

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

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")