sprechstunden-go/sqldb/sqldb.go

33 lines
463 B
Go
Raw Normal View History

2022-08-29 20:58:19 +00:00
package sqldb
import (
"database/sql"
"log"
2022-08-29 20:58:19 +00:00
_ "github.com/go-sql-driver/mysql"
2022-08-29 20:58:19 +00:00
_ "github.com/mattn/go-sqlite3"
)
func ConnectSQLite(file string) *sql.DB {
db, err := sql.Open("sqlite3", file)
2022-08-29 20:58:19 +00:00
if err != nil {
log.Fatal(err)
2022-08-29 20:58:19 +00:00
}
return db
}
func ConnectMysql(connection string) *sql.DB {
db, err := sql.Open("mysql", connection)
if err != nil {
log.Fatal(err)
}
err = db.Ping()
// handle error
if err != nil {
log.Fatal(err)
}
return db
}