-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
825d03b
commit 7e53a17
Showing
18 changed files
with
791 additions
and
670 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
dbm-services/redis/db-tools/dbactuator/models/mysqlite/mysqlite.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Package mysqlite TODO | ||
package mysqlite | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/glebarez/sqlite" | ||
"gorm.io/gorm" | ||
|
||
"dbm-services/redis/db-tools/dbactuator/mylog" | ||
"dbm-services/redis/db-tools/dbactuator/pkg/consts" | ||
"dbm-services/redis/db-tools/dbactuator/pkg/util" | ||
) | ||
|
||
func getLocalDbName() (dbname string, err error) { | ||
dbname = filepath.Join(consts.BkDbmonPath, "db", "lucky_boy.db") | ||
return | ||
} | ||
|
||
// GetLocalSqDB TODO | ||
func GetLocalSqDB() (sqDB *gorm.DB, err error) { | ||
dbName, err := getLocalDbName() | ||
if err != nil { | ||
return | ||
} | ||
dbDir := filepath.Dir(dbName) | ||
err = util.MkDirsIfNotExists([]string{dbDir}) | ||
if err != nil { | ||
return | ||
} | ||
util.LocalDirChownMysql(dbDir) | ||
sqDB, err = gorm.Open(sqlite.Open(dbName), &gorm.Config{}) | ||
if err != nil { | ||
err = fmt.Errorf("gorm.Open failed,err:%v,dbname:%s", err, dbName) | ||
mylog.Logger.Info(err.Error()) | ||
return | ||
} | ||
return | ||
} | ||
|
||
// CloseDB TODO | ||
func CloseDB(sqDB *gorm.DB) { | ||
if sqDB != nil { | ||
dbInstance, _ := sqDB.DB() | ||
_ = dbInstance.Close() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.