2024-05-15 23:37:42 +00:00
|
|
|
package migration
|
2024-05-14 21:59:04 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"fmt"
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Connect(user, pass, url, port, dbName string) (*sql.DB, error) {
|
|
|
|
connectionString := user + ":" + pass + "@tcp(" + url + ":" + port + ")/" + dbName
|
|
|
|
|
|
|
|
db, err := sql.Open("mysql", connectionString)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = db.Ping()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Successfully connected!")
|
|
|
|
|
|
|
|
return db, nil
|
|
|
|
}
|