Verbessere Dokumentation
This commit is contained in:
parent
ec24c6c4dc
commit
fe54d76ab2
14 changed files with 75 additions and 34 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
// Connect to a database using or throw an error
|
||||
func Connect(config config.Config) (*sql.DB, error) {
|
||||
switch config.SQL.Type {
|
||||
case "SQLite":
|
||||
|
@ -24,6 +25,7 @@ func Connect(config config.Config) (*sql.DB, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// Connect to a SQLite database and check the connection.
|
||||
func connectSQLite(file string) (*sql.DB, error) {
|
||||
db, err := sql.Open("sqlite3", file)
|
||||
if err != nil {
|
||||
|
@ -32,6 +34,7 @@ func connectSQLite(file string) (*sql.DB, error) {
|
|||
return db, nil
|
||||
}
|
||||
|
||||
// Connect to a Mysql database and check the connection.
|
||||
func connectMysql(user string, password string, address string, port int, database string) (*sql.DB, error) {
|
||||
db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", user, password, address, port, database))
|
||||
if err != nil {
|
||||
|
@ -39,7 +42,6 @@ func connectMysql(user string, password string, address string, port int, databa
|
|||
}
|
||||
|
||||
err = db.Ping()
|
||||
// handle error
|
||||
if err != nil {
|
||||
return db, fmt.Errorf("Error pinging Mysql database: %w", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue