jsondb: Add Delete function

This allows database entries to be deleted.

Related: RHEL-60120
This commit is contained in:
Brian C. Lane 2024-04-16 10:24:14 -07:00 committed by Tomáš Hozza
parent fd7dc96d06
commit 5961b69caa
2 changed files with 43 additions and 0 deletions

View file

@ -79,6 +79,14 @@ func (db *JSONDatabase) List() ([]string, error) {
return names, nil
}
// Delete will delete the file from the database
func (db *JSONDatabase) Delete(name string) error {
if len(name) == 0 {
return fmt.Errorf("missing jsondb document name")
}
return os.Remove(filepath.Join(db.dir, name+".json"))
}
// Writes `document` to `name`, overwriting a previous document if it exists.
// `document` must be serializable to JSON.
func (db *JSONDatabase) Write(name string, document interface{}) error {