MCPcopy Index your code
hub / github.com/1Panel-dev/1Panel / LoadDBConnByPathWithErr

Function LoadDBConnByPathWithErr

agent/utils/common/sqlite.go:35–52  ·  view source on GitHub ↗
(fullPath, dbName string)

Source from the content-addressed store, hash-verified

33}
34
35func LoadDBConnByPathWithErr(fullPath, dbName string) (*gorm.DB, error) {
36 if _, err := createDirWhenNotExist(true, path.Dir(fullPath)); err != nil {
37 return nil, fmt.Errorf("init db dir failed, err: %v", err)
38 }
39 if _, err := os.Stat(fullPath); err != nil {
40 f, err := os.Create(fullPath)
41 if err != nil {
42 return nil, fmt.Errorf("init %s db file failed, err: %v", dbName, err)
43 }
44 _ = f.Close()
45 }
46
47 db, err := GetDBWithPath(fullPath)
48 if err != nil {
49 return nil, fmt.Errorf("init %s db failed, err: %v", dbName, err)
50 }
51 return db, nil
52}
53
54func CloseDB(db *gorm.DB) {
55 sqlDB, err := db.DB()

Callers

nothing calls this directly

Calls 5

createDirWhenNotExistFunction · 0.85
GetDBWithPathFunction · 0.70
CreateMethod · 0.65
CloseMethod · 0.65
StatMethod · 0.45

Tested by

no test coverage detected