mirror of
https://github.com/kristoferssolo/telescope-frecency.nvim.git
synced 2025-10-21 20:10:38 +00:00
refactor
This commit is contained in:
parent
f2802ba34c
commit
aa93b2f8e6
@ -9,6 +9,9 @@ end
|
|||||||
-- TODO: pass in max_timestamps from db.lua
|
-- TODO: pass in max_timestamps from db.lua
|
||||||
local MAX_TIMESTAMPS = 10
|
local MAX_TIMESTAMPS = 10
|
||||||
|
|
||||||
|
local db_table = {}
|
||||||
|
db_table.files = "files"
|
||||||
|
db_table.timestamps = "timestamps"
|
||||||
--
|
--
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
@ -23,13 +26,9 @@ function M:new()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M:bootstrap(opts)
|
function M:bootstrap(opts)
|
||||||
|
if self.db then return end
|
||||||
|
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
if self.db then
|
|
||||||
print("sql wrapper already initialised")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
self.max_entries = opts.max_entries or 2000
|
self.max_entries = opts.max_entries or 2000
|
||||||
|
|
||||||
-- create the db if it doesn't exist
|
-- create the db if it doesn't exist
|
||||||
@ -42,15 +41,15 @@ function M:bootstrap(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local first_run = false
|
local first_run = false
|
||||||
if not self.db:exists("files") then
|
if not self.db:exists(db_table.files) then
|
||||||
first_run = true
|
first_run = true
|
||||||
-- create tables if they don't exist
|
-- create tables if they don't exist
|
||||||
self.db:create("files", {
|
self.db:create(db_table.files, {
|
||||||
id = {"INTEGER", "PRIMARY", "KEY"},
|
id = {"INTEGER", "PRIMARY", "KEY"},
|
||||||
count = "INTEGER",
|
count = "INTEGER",
|
||||||
path = "TEXT"
|
path = "TEXT"
|
||||||
})
|
})
|
||||||
self.db:create("timestamps", {
|
self.db:create(db_table.timestamps, {
|
||||||
id = {"INTEGER", "PRIMARY", "KEY"},
|
id = {"INTEGER", "PRIMARY", "KEY"},
|
||||||
file_id = "INTEGER",
|
file_id = "INTEGER",
|
||||||
timestamp = "REAL"
|
timestamp = "REAL"
|
||||||
@ -88,15 +87,15 @@ local cmd = {
|
|||||||
local queries = {
|
local queries = {
|
||||||
file_add_entry = {
|
file_add_entry = {
|
||||||
cmd = cmd.insert,
|
cmd = cmd.insert,
|
||||||
cmd_data = "files"
|
cmd_data = db_table.files
|
||||||
},
|
},
|
||||||
file_delete_entry = {
|
file_delete_entry = {
|
||||||
cmd = cmd.delete,
|
cmd = cmd.delete,
|
||||||
cmd_data = "files"
|
cmd_data = db_table.files
|
||||||
},
|
},
|
||||||
file_get_entries = {
|
file_get_entries = {
|
||||||
cmd = cmd.select,
|
cmd = cmd.select,
|
||||||
cmd_data = "files"
|
cmd_data = db_table.files
|
||||||
},
|
},
|
||||||
file_update_counter = {
|
file_update_counter = {
|
||||||
cmd = cmd.eval,
|
cmd = cmd.eval,
|
||||||
@ -108,11 +107,11 @@ local queries = {
|
|||||||
},
|
},
|
||||||
timestamp_delete_entry = {
|
timestamp_delete_entry = {
|
||||||
cmd = cmd.delete,
|
cmd = cmd.delete,
|
||||||
cmd_data = "timestamps"
|
cmd_data = db_table.timestamps
|
||||||
},
|
},
|
||||||
timestamp_get_all_entries = {
|
timestamp_get_all_entries = {
|
||||||
cmd = cmd.select,
|
cmd = cmd.select,
|
||||||
cmd_data = "timestamps",
|
cmd_data = db_table.timestamps,
|
||||||
},
|
},
|
||||||
timestamp_get_all_entry_ages = {
|
timestamp_get_all_entry_ages = {
|
||||||
cmd = cmd.eval,
|
cmd = cmd.eval,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user