feat: 优化web
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user