From 2ebbe7de630d1e1e23adb7ac773806f8f354f978 Mon Sep 17 00:00:00 2001 From: Pulkit Kathuria Date: Thu, 16 Jan 2025 13:44:05 +0900 Subject: [PATCH] feat: uniq db auto --- pkg/database.go | 7 +++++++ pkg/watcher.go | 4 +--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/database.go b/pkg/database.go index 7101860..d0c1e9d 100644 --- a/pkg/database.go +++ b/pkg/database.go @@ -2,6 +2,7 @@ package pkg import ( "database/sql" + "fmt" "log/slog" "os" "time" @@ -29,6 +30,12 @@ func InitDB(dbName string) (*sql.DB, error) { return db, nil } +func GetUniqDBName(f Flags) string { + suffix := Hash(fmt.Sprintf("%s-%s-%s-%s-%d", f.FilePath, f.Match, f.Ignore, f.MSTeamsHook, f.Every)) + ".sqlite" + dbName := f.DBPath + "." + suffix + return dbName +} + func DeleteDB(dbName string) error { if _, err := os.Stat(dbName); err == nil { if err := os.Remove(dbName); err != nil { diff --git a/pkg/watcher.go b/pkg/watcher.go index ac452eb..6e7d725 100644 --- a/pkg/watcher.go +++ b/pkg/watcher.go @@ -3,7 +3,6 @@ package pkg import ( "bufio" "database/sql" - "fmt" "io" "os" "regexp" @@ -29,8 +28,7 @@ func NewWatcher( filePath string, f Flags, ) (*Watcher, error) { - suffix := Hash(fmt.Sprintf("%s-%s-%s-%s-%d", f.FilePath, f.Match, f.Ignore, f.MSTeamsHook, f.Every)) + ".sqlite" - dbName := f.DBPath + "." + suffix + dbName := GetUniqDBName(f) db, err := InitDB(dbName) if err != nil { return nil, err