-
I am a novice, if only there is a detailed tutorial. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Here's something I just wrote, I will try to include example in the readme soon 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 = self:__get(query)
-- do some sorting or stuff you need.
return entries
end
print(vim.inspect(M:get()))
return M
|
Beta Was this translation helpful? Give feedback.
-
@tami5 Thank you for your help. |
Beta Was this translation helpful? Give feedback.
-
I agree with @kdurant . For what I saw on the example, this library it seems to have pretty advanced and handy ways to manage an sqlite database however it's quite cryptic to read the |
Beta Was this translation helpful? Give feedback.
-
@JeysonFlores 😆 sorry to hear that, yah. it's a library with a style guide missing. Part of the complexity comes from the fact that this library is both a binding and an opinionated wrapper and there is multiple ways to use it. I'd love to create step by step example to explain it all, but I'm afraid I might not be able to. However, I managed to cleanup and add bookmark manager example For now checkout powered by sqlite.lua, it's a good place to start for create something powered by sqlite.lua, some use low level api and other uses the wrapper |
Beta Was this translation helpful? Give feedback.
Here's something I just wrote, I will try to include example in the readme soon