添加PGSQL后端

This commit is contained in:
2025-05-19 13:40:32 +08:00
parent e2ff3e7021
commit 52a9d40792
3 changed files with 48 additions and 19 deletions

View File

@@ -2,6 +2,7 @@ package db
import (
"fmt"
"gorm.io/driver/postgres"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"os"
@@ -12,13 +13,15 @@ import (
var err error
func Connect() {
if config.DB.Type == "SQLite" {
switch config.DB.Type {
case "SQLite":
connectSQLite()
} else {
fmt.Println("sorry,we support SQLite only so far,check **DB.Type** entry in the config file")
os.Exit(1)
case "PostgreSQL":
connectPGSQL()
default:
panic("DBType error")
}
Main.AutoMigrate(&model.Member{})
Main.AutoMigrate(&model.Member{}, &model.Tweak{})
}
func connectSQLite() {
@@ -30,3 +33,10 @@ func connectSQLite() {
}
}
func connectPGSQL() {
Main, err = gorm.Open(postgres.Open(config.DB.Path))
if err != nil {
panic(err)
}
}