18 lines
373 B
Go
18 lines
373 B
Go
package db
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"giter.top/smart/pkg/config"
|
|
"gorm.io/driver/postgres"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// pg sql 数据库连接
|
|
func NewPgSQLDB(cfg *config.Config) (*gorm.DB , error) {
|
|
db, err := gorm.Open(postgres.Open(cfg.Data.Database.DSN), &gorm.Config{})
|
|
if err != nil {
|
|
return nil, errors.New("failed to connect to postgres database")
|
|
}
|
|
return db, nil
|
|
} |