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

Function LoadDBConnByPath

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

Source from the content-addressed store, hash-verified

14)
15
16func LoadDBConnByPath(fullPath, dbName string) *gorm.DB {
17 if _, err := createDirWhenNotExist(true, path.Dir(fullPath)); err != nil {
18 panic(fmt.Errorf("init db dir failed, err: %v", err))
19 }
20 if _, err := os.Stat(fullPath); err != nil {
21 f, err := os.Create(fullPath)
22 if err != nil {
23 panic(fmt.Errorf("init %s db file failed, err: %v", dbName, err))
24 }
25 _ = f.Close()
26 }
27
28 db, err := GetDBWithPath(fullPath)
29 if err != nil {
30 panic(err)
31 }
32 return db
33}
34
35func LoadDBConnByPathWithErr(fullPath, dbName string) (*gorm.DB, error) {
36 if _, err := createDirWhenNotExist(true, path.Dir(fullPath)); err != nil {

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