Skip to content

Commit

Permalink
refactor(sqlite-wrapper): add specialised get_conf_value
Browse files Browse the repository at this point in the history
  • Loading branch information
jghauser committed Jul 4, 2024
1 parent 6f1cf00 commit 71acb18
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lua/papis/completion/source.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function M:is_available()
local current_filepath = Path(api.nvim_buf_get_name(0))
local filename = current_filepath:basename()

local info_name = db.config:get_value({ id = 1 }, "info_name")
local info_name = db.config:get_conf_value("info_name")
if filename == info_name then
log.trace("we are in a papis info file")
if not tag_delimiter then
Expand Down
6 changes: 3 additions & 3 deletions lua/papis/fs-watcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ end
---Gets all directories in the library_dir
---@return table #A list of all directories in library_dir
local function get_library_dirs()
local library_dir = Path(db.config:get_value({ id = 1 }, "dir"))
local library_dir = Path(db.config:get_conf_value("dir"))
local library_dirs = {}
for path in library_dir:fs_iterdir() do
library_dirs[#library_dirs + 1] = path
Expand All @@ -72,7 +72,7 @@ local function init_fs_watcher(dir_to_watch, is_library_root)
---@param filename string #The name of the file that triggered the event
---@param unwatch_cb function #The callback that stops a watcher
local function do_handle_event(filename, unwatch_cb)
local info_name = db.config:get_value({ id = 1 }, "info_name")
local info_name = db.config:get_conf_value("info_name")
local mtime
local entry_dir
local info_path
Expand Down Expand Up @@ -160,7 +160,7 @@ end
---Starts file system watchers for root dir and all entry dirs
local function start_fs_watchers()
log.debug("Set db state to indicate fswatcher is active")
local library_dir = Path(db.config:get_value({ id = 1 }, "dir"))
local library_dir = Path(db.config:get_conf_value("dir"))
db.state:set_fw_running(uv.os_getpid())

log.debug("Setting up fswatcher for library root directory")
Expand Down
4 changes: 2 additions & 2 deletions lua/papis/papis-storage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ end
---@param paths? table #A list with paths of papis entries
---@return table #A list of { path = path, mtime = mtime } values
function M.get_metadata(paths)
local library_dir = Path(db.config:get_value({ id = 1 }, "dir"))
local info_name = db.config:get_value({ id = 1 }, "info_name")
local library_dir = Path(db.config:get_conf_value("dir"))
local info_name = db.config:get_conf_value("info_name")
if not paths then
paths = {}
for path in library_dir:fs_iterdir() do
Expand Down
5 changes: 5 additions & 0 deletions lua/papis/sqlite-wrapper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ function tbl_methods.config:update()
self:__update({ where = { id = 1 }, set = papis_py_conf_new })
end

---Gets config from Papis and updates the config table with it
function tbl_methods.config:get_conf_value(key)
return self:get_value({ id = 1 }, key)
end

---Gets the pid of the neovim instance that is running file watchers
---@return number? #Pid of the relevant process if they are running, nil if not
function tbl_methods.state:get_fw_running()
Expand Down
4 changes: 2 additions & 2 deletions lua/papis/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ end
-- Open file outside neovim
---@param path string #Path to the file
function M:do_open_file_external(path)
local opentool = require("papis.sqlite-wrapper").config:get_value({ id = 1 }, "opentool")
local opentool = require("papis.sqlite-wrapper").config:get_conf_value("opentool")
local opentool_table = self.do_split_str(opentool, " ")
local command = table.remove(opentool_table, 1)
local args = opentool_table
Expand Down Expand Up @@ -175,7 +175,7 @@ function M:do_open_text_file(papis_id, type)
popup:unmount()
local config = require("papis.config")
local create_new_note_fn = config.create_new_note_fn
local notes_name = db.config:get_value({ id = 1 }, "notes_name")
local notes_name = db.config:get_conf_value("notes_name")
local enable_modules = config.enable_modules
create_new_note_fn(papis_id, notes_name)
if enable_modules["formatter"] then
Expand Down

0 comments on commit 71acb18

Please sign in to comment.