2024-04-23 16:52:48 +00:00
|
|
|
package database
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/go-sql-driver/mysql"
|
|
|
|
)
|
|
|
|
|
2024-11-25 20:47:56 +00:00
|
|
|
func GetDatabaseFromConfig(config mysql.Config) *sql.DB {
|
2024-04-23 16:52:48 +00:00
|
|
|
db, err := sql.Open("mysql", config.FormatDSN())
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
if err = db.Ping(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return db
|
|
|
|
}
|