add delete issues for deleting all issues

add db for interactig directly with db
This commit is contained in:
Robin Olsen
2026-02-12 19:58:23 +01:00
parent 08ded5384c
commit f9fe03a451

View File

@@ -2,6 +2,7 @@ package service
import (
"context"
"database/sql"
"fmt"
"os"
"time"
@@ -24,6 +25,7 @@ type Config struct {
type Services struct {
Config Config
DB *sql.DB
Beads *BeadsService
Statistics *StatisticsService
}
@@ -36,6 +38,12 @@ func NewServices(ctx context.Context, config Config) (*Services, func(), error)
os.Exit(0)
}
db, err := sql.Open("sqlite3", config.BeadsDBPath)
if err != nil {
return nil, nil, err
}
cleanupFuncs = append(cleanupFuncs, func() { db.Close() })
store, err := beads.NewSQLiteStorage(ctx, config.BeadsDBPath)
if err != nil {
return nil, nil, err
@@ -59,6 +67,7 @@ func NewServices(ctx context.Context, config Config) (*Services, func(), error)
}
return &Services{
DB: db,
Beads: beadsSvc,
Statistics: statSvc,
Config: config,
@@ -92,3 +101,13 @@ func initialized(beadsPath string) bool {
}
return true
}
func (s *Services) DeleteIssues() error {
var deleteIssues = "DELETE FROM issues;"
if _, err := s.DB.Exec(deleteIssues); err != nil {
return err
}
return nil
}