Conversation
47408a5 to
115ceb4
Compare
|
I'm testing it, there are a serious bug kkharji/sqlite.lua#112 😨. I'll get back to shortly you |
Oh I see, thanks for letting me know :) |
|
Okay it seems like there wasn't any issue and that instead of passing entries I passed self. local has_sqlite, sqlite = pcall(require, "sqlite")
if not has_sqlite then
print "Couldn't find sqlite.lua. Cannot use persistent history"
return nil
end
---@class NeoclipEntry @entry content
---@field regtype string
---@field contents string[]
---@field filetype string
---@class NeoClipTable: sqlite_tbl
local M = sqlite.tbl("neoclip", {
id = true,
regtype = "text",
contents = "luatable",
filetype = "text",
})
function M:init(config)
config = config or {}
local db_path = config.db_path or vim.fn.stdpath "data" .. "/databases/neoclip.sqlite3"
self:set_db(sqlite.new(db_path)) --- directory ensuring should be out of this module
end
M:init() --- called outside the module to set user db path
---Insert new neclip entry
---@param entry NeoclipEntry[] | NeoclipEntry
function M:insert(entry)
-- do some pre processing before inserting a row
return self:__insert(entry)
end
M:insert {
{
contents = { "line 1", " line 2", "line 3" },
filetype = "lua",
regtype = "l",
},
{
contents = { "some other string" },
filetype = "lua",
regtype = "l",
},
}
---Get content using {query} if non-nil
---@param query sqlite_query_select|nil @(look into lua-dev.nvim to get autocomletion)
---@return NeoclipEntry[]
function M:get(query)
local entries = M:__get(query)
-- do some sorting or stuff you need.
return entries
end
print(vim.inspect(M:get()))
return M
|
|
@tami5 Hmm, I see, so is this branch working for you now? I'm not sure I fully understood what the difference was. |
Yes this worked for me. the pervious implementation I couldn't figure out what's wrong. Does this work on you machine |
|
@tami5 This current branch does not work for me for some reason, but I haven't had time yet to look into it again. I should try the code-sample you shared above and see if it works better 👍 |
|
@tami5 I tried this again and using your code above but cannot get it working. I first tried as it is and then it complained that the table object doesn't have the method |
Yah the lsp error is because __get and other private function is not expose to emmy lsp. but it works fine. Try to delete db file. I just pasted the content and did luaf % and it works okay |
|
Not lsp error, an actual runtime error. I did delete the db file. Not sure what's going on here. |
this really weird, how did u install sqlite, luarocks? and is it update to latest version? |
|
@tami5 I came back to this today. If I try to run the above example exactly as is using Also if I delete the file beforehand. I installed sqlite using My |
Oh I can confirm this bug, let me investigated and fix it. Thanks |
This what happens with dealing with function that can take self or other. Refs: AckslD/nvim-neoclip.lua#20
|
wow schema wasn't even getting passed 😵💫. Thanks @AckslD, I would have never found such a bug |
|
Oh I see, great that you found it :) It might have been related to another issue I had when trying something else, namely I did something like: local db = sqlite.new(db_path)
db:open()
local tbl = sqlite.tbl("neoclip", {
id = true,
regtype = "text",
contents = "luatable",
filetype = "text",
}, db)
tbl:set_db(db)ie I set the but then when calling However if I didn't pass |
|
Hmmm this shouldn't happen, users should be able change/switch db at runtime without issues, let me open an issue to track it later. FYI: db:tbl("neoclip", {...}) to avoid explicitly injecting a db at tbl definition. |
|
Thanks for the fix @tami5! Things seems to work as intended now 🎉 |
9df7309 to
9bf5492
Compare
No description provided.