feat: Support postgresql:// dsn format

This commit is contained in:
Seefs
2025-03-12 21:08:47 +08:00
parent 229738cda9
commit c47d8a10f0

View File

@@ -1,16 +1,17 @@
package model package model
import ( import (
"github.com/glebarez/sqlite"
"gorm.io/driver/mysql"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"log" "log"
"one-api/common" "one-api/common"
"os" "os"
"strings" "strings"
"sync" "sync"
"time" "time"
"github.com/glebarez/sqlite"
"gorm.io/driver/mysql"
"gorm.io/driver/postgres"
"gorm.io/gorm"
) )
var groupCol string var groupCol string
@@ -60,7 +61,7 @@ func chooseDB(envName string) (*gorm.DB, error) {
}() }()
dsn := os.Getenv(envName) dsn := os.Getenv(envName)
if dsn != "" { if dsn != "" {
if strings.HasPrefix(dsn, "postgres://") { if strings.HasPrefix(dsn, "postgres://") || strings.HasPrefix(dsn, "postgresql://") {
// Use PostgreSQL // Use PostgreSQL
common.SysLog("using PostgreSQL as database") common.SysLog("using PostgreSQL as database")
common.UsingPostgreSQL = true common.UsingPostgreSQL = true