Skip to content

Commit

Permalink
revert: put back the reinitialize db
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed Dec 16, 2024
1 parent 60bb492 commit b89c15c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
23 changes: 7 additions & 16 deletions pkg/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,12 @@ import (
_ "github.com/glebarez/go-sqlite" // nolint: revive
)

var (
db *sql.DB
)

func InitDB(dbName string) (*sql.DB, error) {
var err error
if db == nil {
slog.Info("Initializing database", "dbName", dbName)
db, err = sql.Open("sqlite", dbName)
if err != nil {
slog.Error("Error opening database", "error", err.Error())
return nil, err
}
} else {
slog.Info("Database already initialized")
slog.Info("Initializing database", "dbName", dbName)
db, err := sql.Open("sqlite", dbName)
if err != nil {
slog.Error("Error opening database", "error", err.Error())
return nil, err
}

_, err = db.Exec(`
Expand All @@ -47,8 +38,8 @@ func InitDB(dbName string) (*sql.DB, error) {
slog.Error("Error creating plot table", "error", err.Error())
return nil, err
}
db.SetMaxOpenConns(10)
db.SetMaxIdleConns(10)
db.SetMaxOpenConns(5)
db.SetMaxIdleConns(5)
db.SetConnMaxLifetime(time.Hour)

return db, nil
Expand Down
3 changes: 1 addition & 2 deletions pkg/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,5 @@ func (w *Watcher) saveState() error {
}

func (w *Watcher) Close() error {
// return w.db.Close()
return nil
return w.db.Close()
}

0 comments on commit b89c15c

Please sign in to comment.