peachy/assets/.init.lua

40 lines
1.1 KiB
Lua
Raw Normal View History

2024-06-10 23:40:10 +00:00
local migrate = require "migrate"
2024-07-06 17:41:55 +00:00
local DB_FILENAME = "peachy.db"
sqlite3 = require "lsqlite3"
2024-08-02 23:06:56 +00:00
2024-08-06 04:46:43 +00:00
function OpenDB(req)
2024-08-02 23:06:56 +00:00
local appID <const> = utf8.codepoint("🍑")
local filename = req.session.filename
if not filename then
error "no file selected"
end
local db = sqlite3.open(filename, sqlite3.OPEN_READWRITE)
if not db then
db, errcode, errmsg = sqlite3.open(filename)
if errcode then error(errmsg) end
errcode = db:exec(string.format("PRAGMA application_id=%d", appID))
if errcode ~= sqlite3.OK then error(db:errmsg()) end
end
local currentAppID
for id in db:urows("PRAGMA application_id") do currentAppID = id end
if currentAppID ~= appID then error("not a Peachy database") end
schema.setup(db)
req.db = db
end
2024-07-06 17:41:55 +00:00
local db = sqlite3.open(DB_FILENAME)
2024-07-06 19:14:08 +00:00
db:exec("PRAGMA journal_mode=WAL")
db:exec("PRAGMA foreign_keys")
-- migrate.migrate(db)
2024-06-10 23:40:10 +00:00
2024-06-10 04:28:01 +00:00
fm = require "fullmoon"
2024-08-02 23:06:56 +00:00
schema = require "schema"
fm.sessionOptions.secret = false
2024-08-06 04:46:43 +00:00
fm.setTemplate({ "/.tmpl/", tmpl = "fmt" })
2024-08-06 04:46:43 +00:00
fm.setRoute("/", fm.servePath("index.lua"))
fm.setRoute("*", fm.servePath)
fm.run()