Browse Source

支持多个db

liuchangshun 1 year ago
parent
commit
af666aafa4
1 changed files with 8 additions and 0 deletions
  1. 8 0
      lxDb/db.go

+ 8 - 0
lxDb/db.go

@@ -36,6 +36,14 @@ func GetDB(c *gin.Context, dbName ...string) *gorm.DB {
 	return DBS[d].WithContext(ctx)
 	return DBS[d].WithContext(ctx)
 }
 }
 
 
+func GetDB2(dbName ...string) *gorm.DB {
+	d := "one"
+	if len(dbName) != 0 {
+		d = dbName[0]
+	}
+	return DBS[d]
+}
+
 func InitDBS(env string, conf []DbConfig) {
 func InitDBS(env string, conf []DbConfig) {
 	DBS = map[string]*gorm.DB{}
 	DBS = map[string]*gorm.DB{}
 	if len(conf) == 1 {
 	if len(conf) == 1 {