18 lines
362 B
Go
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{})
|
|
}
|