feat: Database type support

This commit is contained in:
zhangwenjian committed 2020-07-03 00:34:54 +08:00
1 parent ab34ba8aad
commit a6970e9c67
20 files changed
+190 -301

No files matched your search

+6 -5
View File
@@ -5,6 +5,7 @@ import (
_ "github.com/jinzhu/gorm/dialects/sqlite"
log "github.com/sirupsen/logrus"
"go-admin/global/orm"
"go-admin/tools/config"
)
type PgSql struct {
@@ -17,7 +18,7 @@ func (*PgSql) Open(dbType string, conn string) (db *gorm.DB, err error) {
func (e *PgSql) GetConnect() string {
return ""
return config.DatabaseConfig.PgSql.MasterConn
}
func (e *PgSql) Setup() {
@@ -28,12 +29,12 @@ func (e *PgSql) Setup() {
db = new(PgSql)
orm.PgSqlConn = db.GetConnect()
log.Info(orm.PgSqlConn)
orm.Eloquent, err = db.Open(DbType, orm.PgSqlConn)
orm.Eloquent, err = db.Open(config.DatabaseConfig.DbType, orm.PgSqlConn)
if err != nil {
log.Fatalf("%s connect error %v", DbType, err)
log.Fatalf("%s connect error %v", config.DatabaseConfig.DbType, err)
} else {
log.Printf("%s connect success!", DbType)
log.Printf("%s connect success!", config.DatabaseConfig.DbType)
}
if orm.Eloquent.Error != nil {
@@ -41,4 +42,4 @@ func (e *PgSql) Setup() {
}
orm.Eloquent.LogMode(true)
}
}