Skip to content

Commit

Permalink
feat: correctly handle multiple simultaneous sessions with db
Browse files Browse the repository at this point in the history
  • Loading branch information
ptdewey committed Aug 25, 2024
1 parent 59cd263 commit cf06962
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lua/yankbank/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ local default_opts = {

--- wrapper function for main plugin functionality
---@param opts table
--- TODO: read from persistent database if sql persist is set (allow multi-session sync)
local function show_yank_bank(opts)
yanks = persistence.get_yanks(opts) or yanks

-- initialize buffer and populate bank
local bufnr, display_lines, line_yank_map =
menu.create_and_fill_buffer(yanks, reg_types, opts)
Expand Down
8 changes: 8 additions & 0 deletions lua/yankbank/persistence.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ function M.add_entry(entry, reg_type, opts)
end
end

--- get current state of yanks in persistent storage
---@param opts table
function M.get_yanks(opts)
if opts.persist_type == "sqlite" then
return persistence:get_bank()
end
end

---initialize bank persistence
---@param opts table
---@return table
Expand Down
2 changes: 0 additions & 2 deletions lua/yankbank/persistence/sql.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ function data:get_bank()
return yanks, reg_types
end

-- FIX: correctly handle multiple sessions open at once

--- set up database persistence
---@param opts table
---@return sqlite_tbl data
Expand Down

0 comments on commit cf06962

Please sign in to comment.