watcher/pkg/database/init.go
2024-04-10 17:36:56 +08:00

18 lines
362 B
Go

package database
import (
"fmt"
"github.com/glebarez/sqlite"
"gorm.io/gorm"
"haitao_watcher/pkg/options"
)
func InitDatabase(opt *options.DBOption) (*gorm.DB, error) {
if opt.Timeout == 0 {
opt.Timeout = 3000
}
dialector := sqlite.Open(fmt.Sprintf("%s?_pragma=busy_timeout(%d)", opt.Path, opt.Timeout))
return gorm.Open(dialector, &gorm.Config{})
}