You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
605 B
Go
31 lines
605 B
Go
package database
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"log/slog"
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
)
|
|
|
|
// OpenSqlite3DB is a wrapper
|
|
//
|
|
// TODO wtf dail uses context.Background(). Look into it more
|
|
func OpenSqlite3DB(dbPath string) (*sql.DB, error) {
|
|
full_database_path := "file:" + dbPath + "?cache=shared"
|
|
|
|
slog.Debug(fmt.Sprintf("Using database path: %s", full_database_path))
|
|
|
|
db, err := sql.Open("sqlite3", full_database_path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to open: %s", full_database_path)
|
|
}
|
|
|
|
err = db.Ping()
|
|
if err != nil {
|
|
db.Close()
|
|
return nil, err
|
|
}
|
|
return db, nil
|
|
}
|