2024-05-13 19:58:26 +08:00
|
|
|
package database
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-08-26 16:36:40 +08:00
|
|
|
|
2024-05-13 19:58:26 +08:00
|
|
|
"gorm.io/driver/postgres"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
func InitDatabase(opt *DBOption) (*gorm.DB, error) {
|
|
|
|
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=Asia/Shanghai", opt.Host, opt.User, opt.Password, opt.DBName, opt.Port)
|
|
|
|
return gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
|
|
|
}
|