From c47d8a10f0afa2eff8bc22e5dc52b2b309337b8d Mon Sep 17 00:00:00 2001 From: Seefs Date: Wed, 12 Mar 2025 21:08:47 +0800 Subject: [PATCH] feat: Support postgresql:// dsn format --- model/main.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/model/main.go b/model/main.go index c0bf927c..649dac54 100644 --- a/model/main.go +++ b/model/main.go @@ -1,16 +1,17 @@ package model import ( - "github.com/glebarez/sqlite" - "gorm.io/driver/mysql" - "gorm.io/driver/postgres" - "gorm.io/gorm" "log" "one-api/common" "os" "strings" "sync" "time" + + "github.com/glebarez/sqlite" + "gorm.io/driver/mysql" + "gorm.io/driver/postgres" + "gorm.io/gorm" ) var groupCol string @@ -60,7 +61,7 @@ func chooseDB(envName string) (*gorm.DB, error) { }() dsn := os.Getenv(envName) if dsn != "" { - if strings.HasPrefix(dsn, "postgres://") { + if strings.HasPrefix(dsn, "postgres://") || strings.HasPrefix(dsn, "postgresql://") { // Use PostgreSQL common.SysLog("using PostgreSQL as database") common.UsingPostgreSQL = true