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

Function GetDBWithPath

agent/utils/common/sqlite.go:62–94  ·  view source on GitHub ↗
(dbPath string)

Source from the content-addressed store, hash-verified

60}
61
62func GetDBWithPath(dbPath string) (*gorm.DB, error) {
63 db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{
64 DisableForeignKeyConstraintWhenMigrating: true,
65 Logger: newLogger(),
66 })
67 if err != nil {
68 return nil, err
69 }
70
71 sqlDB, err := db.DB()
72 if err != nil {
73 return nil, err
74 }
75
76 sqlDB.SetMaxOpenConns(4)
77 sqlDB.SetMaxIdleConns(1)
78 sqlDB.SetConnMaxLifetime(0)
79 sqlDB.SetConnMaxIdleTime(0)
80
81 if err := db.Exec("PRAGMA journal_mode = WAL;").Error; err != nil {
82 return nil, err
83 }
84 if err := db.Exec("PRAGMA synchronous = NORMAL;").Error; err != nil {
85 return nil, err
86 }
87 if err := db.Exec("PRAGMA busy_timeout = 5000;").Error; err != nil {
88 return nil, err
89 }
90 if err := db.Exec("PRAGMA temp_store = MEMORY;").Error; err != nil {
91 return nil, err
92 }
93 return db, nil
94}
95
96func newLogger() logger.Interface {
97 return logger.New(

Callers 2

LoadDBConnByPathFunction · 0.70
LoadDBConnByPathWithErrFunction · 0.70

Calls 1

newLoggerFunction · 0.70

Tested by

no test coverage detected