uri: = fmt.Sprintf("postgres://%s:%s@%s:%s/%s?search_path=%s", cfg.User, cfg.Password, cfg.Host, cfg.Port, cfg.Database, cfg.Schema)
customLogger: = logger.New(
log.New(os.Stdout, "\r\n", log.LstdFlags),
logger.Config {
SlowThreshold: time.Second,
LogLevel: logger.Error,
IgnoreRecordNotFoundError: true,
Colorful: true,
},
)
db, err: = gorm.Open(postgres.Open(uri), & gorm.Config {
Logger: customLogger,
SkipDefaultTransaction: true,
})
if err != nil {
return nil, err
}
log.Println("Connected to Postgres!")
db.Exec(fmt.Sprintf("CREATE SCHEMA IF NOT EXISTS %s", cfg.Schema))
return db, nil