Skip to content

Commit 0e97f37

Browse files
committed
db connection rectification
1 parent 889ff1b commit 0e97f37

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

dbFlow/db.circulation.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,33 @@ package dbflow
22

33
import (
44
"fmt"
5+
"log"
56
"os"
67

78
"gorm.io/driver/postgres"
89
"gorm.io/gorm"
910
)
1011

1112
func ConnectHackDatabase() *gorm.DB {
12-
// Connect to the database
13+
// Load environment variables
1314
dbHost := os.Getenv("SUPABASE_DB_HOST")
1415
dbUsername := os.Getenv("SUPABASE_DB_USERNAME")
1516
dbPassword := os.Getenv("SUPABASE_DB_PASSWORD")
1617
dbName := os.Getenv("SUPABASE_DB_NAME")
1718
dbPort := os.Getenv("SUPABASE_DB_PORT")
1819

1920
// Construct the connection string
20-
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=require TimeZone=Asia/Shanghai",
21-
dbHost, dbUsername, dbPassword, dbName, dbPort)
21+
dsn := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable",
22+
dbHost, dbPort, dbUsername, dbPassword, dbName)
2223

24+
// Attempt to connect to the database
2325
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
2426
if err != nil {
25-
panic("failed to connect database")
27+
log.Fatalf("failed to connect database: %v", err)
2628
}
2729

28-
// // Auto migrate the schema
29-
// db.AutoMigrate(&SlnSui{})
30-
return db
30+
// Optionally, you can enable automatic migrations
31+
// db.AutoMigrate(&YourModel{})
3132

33+
return db
3234
}

0 commit comments

Comments
 (0)