summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrebecca <ubq323@ubq323.website>2026-09-20 12:36:37 +0100
committerrebecca <ubq323@ubq323.website>2026-09-20 12:36:37 +0100
commite640def8de6d4682ad9973ad818dfe2e11c33998 (patch)
tree9300646f4054b78e42b8a216f01bc85a74c315e3
parentaf8cd453bf63bea136d2b4a71c783ef5542a05ed (diff)
store: expand schemastore
-rw-r--r--store.lua33
1 files changed, 26 insertions, 7 deletions
diff --git a/store.lua b/store.lua
index a970fcb..1d1461f 100644
--- a/store.lua
+++ b/store.lua
@@ -1,5 +1,6 @@
local cqueues = require'cqueues'
local db = require'r.db'
+local schema = require'r.db.schema'
local qw = require'r.qw'
local html = require'r.html'
local T = html.T
@@ -11,18 +12,36 @@ local Queue = require'queue'
local Log = require'log'
local Store = class() -- we only have 1 instance of this, but, ough,
-function Store.make(cls) return setmetatable({
- q = Queue(),
- log = Log"store",
-},cls) end
+function Store.make(cls)
+ schema.schemafy {
+ messages = {
+ {"p_type","text",not nil},
+ {"p_name","text",not nil},
+ {"channel","text",not nil},
+ {"author","text",not nil},
+ {"ts","text",not nil},
+ {"body","text"},
+ },
+ }
+ return setmetatable({
+ q = Queue(),
+ log = Log"store",
+ },cls)
+end
function Store.storing(self)
local conn = db.conn()
for msg in self.q:iter() do
-- needs to go in its own coro
-- so we don't gum up the works while waiting on the db
- conn:exec("insert into messages (ts, body) values (?,?);",
- os.time(), msg.body)
+ conn:exec([[
+ insert into messages (p_type,
+ p_name,channel,author,ts,body)
+ values (?, ?, ?, ?, ?, ?); ]],
+ msg.source_channel.pylon.type,
+ msg.source_channel.pylon.name,
+ msg.source_channel.descriptor,
+ msg.sender,os.time(),msg.body)
self.log("stored",msg.body)
assert(conn:commit()) end end
function Store.store(self, msg) self.q:enqueue(msg) end
@@ -30,7 +49,7 @@ function Store.store(self, msg) self.q:enqueue(msg) end
local function view(req)
local conn <close> = db.conn()
local rows = conn:fetch"select * from messages order by ts asc;"
- local fields = qw"id ts body"
+ local fields = qw"id p_type p_name channel author ts body"
-- list comprehensions? WHAT ARE THOSE?????
local ths={} for i,v in ipairs(fields) do ths[i]=T.th(v) end
local trs={} for ri,r in ipairs(rows) do