nerak repo

This commit is contained in:
2026-07-23 12:14:09 -05:00
committed by nightshade
commit 6d10215122
84 changed files with 5448 additions and 0 deletions
@@ -0,0 +1,26 @@
#include <nerak.h>
#include <sqlite.h>
#include <pubsub.h>
#include <session_auth.h>
config(activity){
middleware(logged_in(), session());
sqlite_config(
"activity_db",
"file:activity.db?mode=rwc",
{"create_activity_table"}
);
subscribe("todo_created", {
sqlite_query({"activity_db", "insert_activity"})
});
resource("activity", "/activity",
.get = {
sqlite_query({"activity_db", "get_activities", "activity"}),
mustache("activity", "activity_s"),
respond("activity_s")
}
);
}
@@ -0,0 +1,13 @@
{{< layout}}
{{$body}}
{{^activity}}
<p>no activity</p>
{{/activity}}
{{#activity}}
<p>activity</p>
{{#.}}
<p>{{action}}: {{title}} ({{created_at}})</p>
{{/.}}
{{/activity}}
{{/body}}
{{/layout}}
@@ -0,0 +1,8 @@
CREATE TABLE IF NOT EXISTS activity (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
action TEXT NOT NULL,
title TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_activity_user_id ON activity(user_id);
@@ -0,0 +1,5 @@
select action, title, created_at
from activity
where user_id = {{user_id}}
order by created_at desc
limit 50;
@@ -0,0 +1,2 @@
insert into activity(user_id, action, title)
values({{user_id}}, 'created', {{title}});