42 lines
1.1 KiB
Lua
42 lines
1.1 KiB
Lua
local migrate = require "migrate"
|
|
|
|
local DB_FILENAME = "peachy.db"
|
|
sqlite3 = require "lsqlite3"
|
|
|
|
function OpenDB(req)
|
|
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
|
|
|
|
local db = sqlite3.open(DB_FILENAME)
|
|
db:exec("PRAGMA journal_mode=WAL")
|
|
db:exec("PRAGMA foreign_keys")
|
|
-- migrate.migrate(db)
|
|
|
|
fm = require "fullmoon"
|
|
schema = require "schema"
|
|
fm.sessionOptions.secret = false
|
|
fm.setTemplate({ "/.tmpl/", tmpl = "fmt" })
|
|
|
|
fm.setRoute("/", fm.servePath("index.lua"))
|
|
fm.setRoute("*", fm.servePath)
|
|
|
|
fm.run()
|
|
|
|
ProgramPort(0)
|
|
LaunchBrowser() |