mirror of
https://github.com/songquanpeng/one-api.git
synced 2026-01-01 20:45:57 +08:00
feat: support PG-SQL
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
"one-api/common"
|
||||
"os"
|
||||
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var DB *gorm.DB
|
||||
@@ -40,7 +42,13 @@ func CountTable(tableName string) (num int64) {
|
||||
|
||||
func InitDB() (err error) {
|
||||
var db *gorm.DB
|
||||
if os.Getenv("SQL_DSN") != "" {
|
||||
if os.Getenv("POSTGRES_DSN") != "" {
|
||||
// Use PostgreSQL
|
||||
common.SysLog("using PostgreSQL as database")
|
||||
db, err = gorm.Open(postgres.Open(os.Getenv("POSTGRES_DSN")), &gorm.Config{
|
||||
PrepareStmt: true, // precompile SQL
|
||||
})
|
||||
} else if os.Getenv("SQL_DSN") != "" {
|
||||
// Use MySQL
|
||||
common.SysLog("using MySQL as database")
|
||||
db, err = gorm.Open(mysql.Open(os.Getenv("SQL_DSN")), &gorm.Config{
|
||||
|
||||
Reference in New Issue
Block a user