From 9abafa50b22aa84c428aa194010848df62e5f546 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Tue, 3 Oct 2017 19:37:58 -0400 Subject: [PATCH] Update gorp dialect depending on DB type used --- db.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/db.go b/db.go index 6c279d8..0c2fdae 100644 --- a/db.go +++ b/db.go @@ -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")