feat 数据库改为pgsql
Some checks failed
Build image / build (push) Failing after 15s

This commit is contained in:
timerzz 2024-05-12 16:35:46 +08:00
parent dcebdb399e
commit dcd21a0cd9
2 changed files with 8 additions and 9 deletions

View File

@ -2,16 +2,12 @@ package database
import (
"fmt"
"github.com/glebarez/sqlite"
"gorm.io/driver/postgres"
"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{})
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=Asia/Shanghai", opt.Host, opt.User, opt.Password, opt.DBName, opt.Port)
return gorm.Open(postgres.Open(dsn), &gorm.Config{})
}

View File

@ -1,6 +1,9 @@
package options
type DBOption struct {
Path string `json:"path"`
Timeout int `json:"timeout"`
Host string `yaml:"host"`
User string `yaml:"user"`
Password string `yaml:"password"`
Port string `yaml:"port"`
DBName string `yaml:"dbname"`
}