2022-08-29 20:58:19 +00:00
|
|
|
package sqldb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2022-09-12 17:42:45 +00:00
|
|
|
"log"
|
2022-08-29 20:58:19 +00:00
|
|
|
|
2022-09-12 17:42:45 +00:00
|
|
|
_ "github.com/go-sql-driver/mysql"
|
2022-08-29 20:58:19 +00:00
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
|
)
|
|
|
|
|
2022-09-12 17:42:45 +00:00
|
|
|
func ConnectSQLite(file string) *sql.DB {
|
|
|
|
db, err := sql.Open("sqlite3", file)
|
2022-08-29 20:58:19 +00:00
|
|
|
if err != nil {
|
2022-09-12 17:42:45 +00:00
|
|
|
log.Fatal(err)
|
2022-08-29 20:58:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return db
|
|
|
|
}
|
2022-09-12 17:42:45 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|