2023-01-28 17:21:21 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2023-01-29 14:39:38 +00:00
|
|
|
"strings"
|
2023-01-28 17:45:48 +00:00
|
|
|
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
2023-01-28 17:21:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func dbConnect(username string, password string, address string, port string, database string) *sql.DB {
|
|
|
|
db, err := sql.Open("mysql", username+":"+password+"@tcp("+address+":"+port+")/"+database)
|
2023-01-28 20:43:07 +00:00
|
|
|
errorPanic(err)
|
2023-01-28 17:21:21 +00:00
|
|
|
|
|
|
|
return db
|
|
|
|
}
|
|
|
|
|
|
|
|
func dbClose(database *sql.DB) {
|
|
|
|
database.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
func dbQuerry(database *sql.DB, sqlCode string) *sql.Rows {
|
2023-01-28 18:04:26 +00:00
|
|
|
results, err := database.Query(sqlCode)
|
2023-01-28 20:43:07 +00:00
|
|
|
errorPanic(err)
|
2023-01-28 17:21:21 +00:00
|
|
|
|
|
|
|
return results
|
|
|
|
}
|
2023-01-28 18:52:41 +00:00
|
|
|
|
|
|
|
func ctdoConnect() *sql.DB {
|
|
|
|
dbValues := readDatabaseYML()
|
|
|
|
|
|
|
|
return dbConnect(dbValues.username, dbValues.password, dbValues.address, dbValues.port, dbValues.database)
|
|
|
|
}
|
2023-01-29 14:39:38 +00:00
|
|
|
|
|
|
|
func sqlClean(sqlString string) string {
|
|
|
|
sqlString = strings.ReplaceAll(sqlString, "'", "")
|
|
|
|
sqlString = strings.ReplaceAll(sqlString, "\"", "")
|
|
|
|
|
|
|
|
return sqlString
|
|
|
|
}
|