feat: Database type support
This commit is contained in:
1 parent
ab34ba8aad
commit
a6970e9c67
20 files changed
+190
-301
No files matched your search
+5
-5
@@ -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 SqLite struct {
|
||||
@@ -16,8 +17,7 @@ func (*SqLite) Open(dbType string, conn string) (db *gorm.DB, err error) {
|
||||
}
|
||||
|
||||
func (e *SqLite) GetConnect() string {
|
||||
|
||||
return ""
|
||||
return config.DatabaseConfig.SqLite.MasterConn
|
||||
}
|
||||
|
||||
func (e *SqLite) Setup() {
|
||||
@@ -28,12 +28,12 @@ func (e *SqLite) Setup() {
|
||||
db = new(SqLite)
|
||||
orm.SqLiteConn = db.GetConnect()
|
||||
log.Info(orm.SqLiteConn)
|
||||
orm.Eloquent, err = db.Open(DbType, orm.SqLiteConn)
|
||||
orm.Eloquent, err = db.Open(config.DatabaseConfig.DbType, orm.SqLiteConn)
|
||||
|
||||
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 {
|
||||
|
||||
Reference in new issue
Block a user