use sql.nvim lib methods for table creation

This commit is contained in:
Senghan Bright 2021-01-15 18:47:31 +01:00
parent 9cf45fcbac
commit 231810a114

View File

@ -9,23 +9,6 @@ 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
-- TODO: prioritize files in project root!
local schemas = {[[
CREATE TABLE IF NOT EXISTS files (
id INTEGER PRIMARY KEY,
count INTEGER,
path TEXT
);
]],
[[
CREATE TABLE IF NOT EXISTS timestamps (
id INTEGER PRIMARY KEY,
file_id INTEGER,
timestamp REAL,
FOREIGN KEY(file_id) REFERENCES files(id)
);
]]}
local queries = { local queries = {
["file_add_entry"] = "INSERT INTO files (path, count) values(:path, 1);", ["file_add_entry"] = "INSERT INTO files (path, count) values(:path, 1);",
@ -77,9 +60,20 @@ function M:bootstrap(opts)
end end
-- create tables if they don't exist -- create tables if they don't exist
for _, s in pairs(schemas) do self.db:create("files", {
self.db:eval(s) ensure = true,
end id = {"integer", "primary", "key"},
count = "integer",
path = "text"
})
self.db:create("timestamps", {
ensure = true,
id = {"integer", "primary", "key"},
file_id = "integer",
count = "integer",
timestamp = "real"
-- FOREIGN KEY(file_id) REFERENCES files(id)
})
self.db:close() self.db:close()
end end