mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
feat: add non-interactive cache editting
This commit is contained in:
parent
3a825f1239
commit
fe76704c22
3 changed files with 97 additions and 13 deletions
21
internal/cache/sqlite/sqlite.go
vendored
21
internal/cache/sqlite/sqlite.go
vendored
|
|
@ -147,3 +147,24 @@ func GetRemoteAssets(path string) ([]magellan.RemoteAsset, error) {
|
|||
}
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func GetRemoteAsset(path string, host string) (*magellan.RemoteAsset, error) {
|
||||
// check if path exists first to prevent creating the database
|
||||
_, exists := util.PathExists(path)
|
||||
if !exists {
|
||||
return nil, fmt.Errorf("no file found")
|
||||
}
|
||||
|
||||
// now check if the file is the SQLite database
|
||||
db, err := sqlx.Open("sqlite3", path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open database: %v", err)
|
||||
}
|
||||
|
||||
results := []magellan.RemoteAsset{}
|
||||
err = db.Select(&results, fmt.Sprintf("SELECT * FROM %s ORDER BY host ASC, port ASC;", TABLE_NAME))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to retrieve assets: %v", err)
|
||||
}
|
||||
return &results[0], nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue