Updated all code to use new SafeConn and SafeTX

This commit is contained in:
2025-02-17 21:38:29 +11:00
parent 2c61cec55c
commit 6faf168a6d
2 changed files with 4 additions and 7 deletions

View File

@@ -33,10 +33,7 @@ type Config struct {
// Load the application configuration and get a pointer to the Config object // Load the application configuration and get a pointer to the Config object
func GetConfig(args map[string]string) (*Config, error) { func GetConfig(args map[string]string) (*Config, error) {
err := godotenv.Load(".env") godotenv.Load(".env")
if err != nil {
fmt.Println(err)
}
var ( var (
host string host string
port string port string

View File

@@ -8,7 +8,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
_ "github.com/mattn/go-sqlite3" _ "modernc.org/sqlite"
) )
// Wraps the database handle, providing a mutex to safely manage transactions // Wraps the database handle, providing a mutex to safely manage transactions
@@ -123,7 +123,7 @@ func (conn *SafeConn) Close() error {
// Returns a database connection handle for the DB // Returns a database connection handle for the DB
func OldConnectToDatabase(dbName string) (*sql.DB, error) { func OldConnectToDatabase(dbName string) (*sql.DB, error) {
file := fmt.Sprintf("file:%s.db", dbName) file := fmt.Sprintf("file:%s.db", dbName)
db, err := sql.Open("sqlite3", file) db, err := sql.Open("sqlite", file)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "sql.Open") return nil, errors.Wrap(err, "sql.Open")
} }
@@ -134,7 +134,7 @@ func OldConnectToDatabase(dbName string) (*sql.DB, error) {
// Returns a database connection handle for the DB // Returns a database connection handle for the DB
func ConnectToDatabase(dbName string) (*SafeConn, error) { func ConnectToDatabase(dbName string) (*SafeConn, error) {
file := fmt.Sprintf("file:%s.db", dbName) file := fmt.Sprintf("file:%s.db", dbName)
db, err := sql.Open("sqlite3", file) db, err := sql.Open("sqlite", file)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "sql.Open") return nil, errors.Wrap(err, "sql.Open")
} }