Skip to content

Commit

Permalink
feat: uniq db auto
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed Jan 16, 2025
1 parent 8dc322e commit 2ebbe7d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 7 additions & 0 deletions pkg/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pkg

import (
"database/sql"
"fmt"
"log/slog"
"os"
"time"
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions pkg/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pkg
import (
"bufio"
"database/sql"
"fmt"
"io"
"os"
"regexp"
Expand All @@ -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
Expand Down

0 comments on commit 2ebbe7d

Please sign in to comment.