Changed DeleteScannedAssets to work correct and added db tag

This commit is contained in:
David Allen 2024-09-18 14:46:52 -06:00 committed by David Allen
parent 0aa72ce70d
commit e40fd1fc06
Signed by: towk
GPG key ID: 0430CDBE22619155
2 changed files with 11 additions and 11 deletions

View file

@ -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)
}
}