···22local M = {}
3344-- import clipboard functions
55-local clipboard = require("yankbank.clipboard")
55+-- local clipboard = require("yankbank.clipboard")
66local data = require("yankbank.data")
77local helpers = require("yankbank.helpers")
88···2222 -- clipboard.add_yank(yanks, reg_types, text, reg_type, opts)
23232424 -- stop if yank table is empty
2525- if #yanks == 0 then
2525+ if #yanks == 0 and #reg_types then
2626 print("No yanks to show.")
2727 return nil, nil, nil
2828 end
···118118 local k = vim.tbl_deep_extend("force", default_keymaps, opts.keymaps or {})
119119120120 -- merge default and options keymap tables
121121- opts.registers = vim.tbl_deep_extend("force", default_registers, opts.registers or {})
121121+ opts.registers =
122122+ vim.tbl_deep_extend("force", default_registers, opts.registers or {})
122123123124 -- check table for number behavior option (prefix or jump, default to prefix)
124125 opts.num_behavior = opts.num_behavior or "prefix"
+4-3
lua/yankbank/persistence.lua
···22local M = {}
3344local persistence = {}
55+local db = nil
5667---add entry from bank to
78---@param entry string|table
···1314 elseif opts.persist_type == "file" then
1415 persistence.add_to_bankfile(opts.persist_path, entry, reg_type)
1516 elseif opts.persist_type == "sqlite" then
1616- -- TODO: implement sqlite persist
1717+ persistence.add_to_yanktable(db, entry, reg_type)
1718 end
1819end
1920···3536 reg_types
3637 )
3738 elseif opts.persist_type == "sqlite" then
3838- -- TODO:
3939 persistence = require("yankbank.persistence.sql")
4040- persistence.init_db(yanks, reg_types, opts.persist_path)
4040+ db = persistence.init_db(yanks, reg_types, opts.persist_path)
4141+ return yanks, reg_types
4142 end
42434344 return {}, {}
+14-8
lua/yankbank/persistence/sql.lua
···2233local sqlite = require("sqlite.db")
4455--- @TODO: yank primary key?
55+-- TODO: yank primary key?
66-- integer tracking for table position not controlled by sqlite3
7788--- create db table for yanks, PK is row id and will increment automatically
88+---create db table for yanks, PK is row id and will increment automatically
99-- @param existing_yanks table
1010+-- @param reg_types table
1011-- @param uri string
1112-- @return sqlite_db
1212-function M.init_db(existing_yanks, uri)
1313+function M.init_db(existing_yanks, reg_types, uri)
1314 local db = sqlite({
1415 uri = uri,
1516 })
···2324 })
2425 local status = db:status()
25262727+ db:insert("yanks", { yank_content = existing_yanks, reg_type = reg_types })
2828+2629 if status ~= nil then
2730 print("yankbank db error: ", status.code)
2831 end
2929- -- @TODO: add functionality to add existing yanks to the db table "yanks"
3232+ -- TODO: add functionality to add existing yanks to the db table "yanks"
3033 db:close()
3134 return db
3235end
···68716972function M.remove_by_yank_index(db, index)
7073 db:open()
7171- local ret = db:select("yanks", { order_by = { asc = "id" }})
7474+ local ret = db:select("yanks", { order_by = { asc = "id" } })
7275 local id_to_remove = ret[index].id
7376 local del = db:delete("yanks", { where = { id = id_to_remove } })
7777+ if del ~= nil then
7878+ return del
7979+ end
7480 local status = db:status()
7581 db:close()
7682 return status == nil
7783end
78847985-- test function for db operations
8080-local function test_db()
8181- local test_db = M.init_db({}, "/tmp/test_yankbank.db")
8686+local function test_database()
8787+ local test_db = M.init_db({}, {}, "/tmp/test_yankbank.db")
8288 -- print(vim.inspect(test_db))
8389 M.add_to_yanktable(test_db, "Sample Yank", "reg")
8490 print(vim.inspect(M.get_yanks(test_db)))
···9197 print(vim.inspect(M.get_yanks(test_db)))
9298end
93999494--- test_db()
100100+test_database()
9510196102return M