package db

import (
	"58team_blog/internal/infrastructure"
	"fmt"

	"github.com/jmoiron/sqlx"
	_ "github.com/lib/pq"
)

type Database struct {
	Conn *sqlx.DB
}

func DatabaseInit(config infrastructure.Config) (db *Database, err error) {
	db = &Database{}

	db_setup := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=disable", config.DBUser, config.DBPass, config.DBHost, config.DBPort, config.DBName)
	db.Conn, err = sqlx.Connect("postgres", db_setup)
	if err != nil {
		return nil, err
	}

	return db, nil
}
