mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Changed DeleteScannedAssets to work correct and added db tag
This commit is contained in:
parent
ff80934134
commit
534ca9d49a
1 changed files with 1 additions and 17 deletions
18
internal/cache/sqlite/sqlite.go
vendored
18
internal/cache/sqlite/sqlite.go
vendored
|
|
@ -2,7 +2,6 @@ package sqlite
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/davidallendj/magellan/internal/util"
|
"github.com/davidallendj/magellan/internal/util"
|
||||||
magellan "github.com/davidallendj/magellan/pkg"
|
magellan "github.com/davidallendj/magellan/pkg"
|
||||||
|
|
@ -78,22 +77,7 @@ func DeleteScannedAssets(path string, assets ...magellan.RemoteAsset) error {
|
||||||
}
|
}
|
||||||
tx = db.MustBegin()
|
tx = db.MustBegin()
|
||||||
for _, asset := range assets {
|
for _, asset := range assets {
|
||||||
// skip if neither host nor port are specified
|
sql := fmt.Sprintf(`DELETE FROM %s WHERE host=:host AND port=:port;`, TABLE_NAME)
|
||||||
if asset.Host == "" && asset.Port <= 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
sql := fmt.Sprintf(`DELETE FROM %s`, TABLE_NAME)
|
|
||||||
where := []string{}
|
|
||||||
if asset.Port > 0 {
|
|
||||||
where = append(where, "port=:port")
|
|
||||||
}
|
|
||||||
if asset.Host != "" {
|
|
||||||
where = append(where, "host=:host")
|
|
||||||
}
|
|
||||||
if len(where) <= 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
sql += fmt.Sprintf(" WHERE %s;", strings.Join(where, " AND "))
|
|
||||||
_, err := tx.NamedExec(sql, &asset)
|
_, err := tx.NamedExec(sql, &asset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("failed to execute DELETE transaction: %v\n", err)
|
fmt.Printf("failed to execute DELETE transaction: %v\n", err)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue