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