From e40fd1fc069e52e339d2a01320e705eef5c18b2f Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Wed, 18 Sep 2024 14:46:52 -0600 Subject: [PATCH] Changed DeleteScannedAssets to work correct and added db tag --- internal/cache/sqlite/sqlite.go | 12 ++++++------ pkg/scan.go | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/cache/sqlite/sqlite.go b/internal/cache/sqlite/sqlite.go index e653aa0..b9884c1 100644 --- a/internal/cache/sqlite/sqlite.go +++ b/internal/cache/sqlite/sqlite.go @@ -62,8 +62,8 @@ func InsertScannedAssets(path string, assets ...magellan.RemoteAsset) error { return nil } -func DeleteScannedAssets(path string, results ...magellan.RemoteAsset) error { - if results == nil { +func DeleteScannedAssets(path string, assets ...magellan.RemoteAsset) error { + if assets == nil { return fmt.Errorf("no assets found") } db, err := sqlx.Open("sqlite3", path) @@ -71,11 +71,11 @@ func DeleteScannedAssets(path string, results ...magellan.RemoteAsset) error { return fmt.Errorf("failed to open database: %v", err) } tx := db.MustBegin() - for _, state := range results { - sql := fmt.Sprintf(`DELETE FROM %s WHERE host = :host, port = :port;`, TABLE_NAME) - _, err := tx.NamedExec(sql, &state) + for _, asset := range assets { + sql := fmt.Sprintf(`DELETE FROM %s WHERE host=:host AND port=:port;`, TABLE_NAME) + _, err := tx.NamedExec(sql, &asset) if err != nil { - fmt.Printf("failed to execute transaction: %v\n", err) + fmt.Printf("failed to execute DELETE transaction: %v\n", err) } } diff --git a/pkg/scan.go b/pkg/scan.go index 58785ca..e86e16d 100644 --- a/pkg/scan.go +++ b/pkg/scan.go @@ -16,11 +16,11 @@ import ( ) type RemoteAsset struct { - Host string `json:"host"` - Port int `json:"port"` - Protocol string `json:"protocol"` - State bool `json:"state"` - Timestamp time.Time `json:"timestamp"` + Host string `db:"host" json:"host"` + Port int `db:"port" json:"port"` + Protocol string `db:"protocol" json:"protocol"` + State bool `db:"state" json:"state"` + Timestamp time.Time `db:"timestamp" json:"timestamp"` } // ScanParams is a collection of commom parameters passed to the CLI