// SetupPostgreDatabase establishes the connexion with the PostgreSQL database
SetupPostgreDatabase establishes the connexion with the PostgreSQL database
// SetupPostgreDatabase establishes the connexion with the PostgreSQL database
func (a *API) SetupPostgreDatabase() (*gorm.DB, error) {
	connectionURI := fmt.Sprintf(
		"sslmode=disable dbname=%s host=%s port=%s user=%s password=%s",
		a.Config.GetString("postgres_db_name"),
		a.Config.GetString("postgres_db_addr"),
		a.Config.GetString("postgres_db_port"),
		a.Config.GetString("postgres_db_user"),
		a.Config.GetString("postgres_db_password"),
	)
	db, err := gorm.Open("postgres", connectionURI)
	if err != nil {
		return nil, err
	}
	debugDatabase := a.Config.GetBool("debug_database")
	db.LogMode(debugDatabase)
	db.DB().SetConnMaxLifetime(time.Minute * 5)
	db.DB().SetMaxIdleConns(5)
	db.DB().SetMaxOpenConns(5)
	a.PostgreDatabase = db
	return db, nil
}
func ( a * API ) SetupPostgreDatabase ( ) ( * gorm . DB , error ) { connectionURI := fmt . Sprintf ( " " , a . Config . GetString ( " " ) , a . Config . GetString ( " " ) , a . Config . GetString ( " " ) , a . Config . GetString ( " " ) , a . Config . GetString ( " " ) , ) db , err := gorm . Open ( " " , connectionURI ) if err != nil { return nil , err } debugDatabase := a . Config . GetBool ( " " ) db . LogMode ( debugDatabase ) db . DB ( ) . SetConnMaxLifetime ( time . Minute * 5 ) db . DB ( ) . SetMaxIdleConns ( 5 ) db . DB ( ) . SetMaxOpenConns ( 5 ) a . PostgreDatabase = db return db , nil }
SetupPostgreDatabase establishes the connexion with the PostgreSQL database
SetupPostgreDatabase establishes the connexion with the PostgreSQL database
// Debug database logs