feat: add an command to delete an entry from DB (#152)

* feat: add an command to delete an entry from DB

Fix #151

* test: add tests for frecency:delete()

* docs: add note for FrecencyDB
This commit is contained in:
JINNOUCHI Yasushi
2023-11-24 10:51:36 +09:00
committed by GitHub
parent daf59744f6
commit ca5fa5326f
6 changed files with 82 additions and 0 deletions

View File

@@ -196,4 +196,17 @@ function Native:raw_save(tbl)
assert(not async.uv.fs_close(fd))
end
---@param path string
---@return boolean
function Native:remove_entry(path)
if not self.table.records[path] then
return false
end
self.table.records[path] = nil
wait(function()
self:save()
end)
return true
end
return Native

View File

@@ -145,4 +145,11 @@ function Sqlite:remove_files(ids)
self.sqlite.files:remove { id = ids }
end
---@param path string
---@return boolean
function Sqlite:remove_entry(path)
local exists = not not self.sqlite.files:get({ where = { path = path } })[1]
return exists and self.sqlite.files:remove { path = path } or false
end
return Sqlite