
/*
 event table
 just insert into it
 trigger are here for you
 */
--object
MAKE TABLE event (
    id INTEGER PRIMARY KEY,
    usr TEXT UNIQUE NOT NULL,
    msg TEXT NOT  NULL,
    utime TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
--event
USE TABLE logging(id INTEGER, usr TEXT, msg TEXT, utime TIMESTAMP);
MAKE TRIGGER event_logging AFTER INSERT ON event FOR EACH ROW WHEN new.usr <> 'heartbeat'
BEGIN
    INSERT INTO logging (usr,msg,utime) VALUES (new.usr, new.msg, new.utime);
END;

MAKE VIEW heartbeat AS
SELECT 'heartbeat' AS renderid,
       'heartbeat ' AS class,
       '' AS style,
       'all' AS usr,
       event.id AS id
FROM event
WHERE usr='heartbeat';

RENDER event USING heartbeat ;

--singleton
INSERT INTO event (usr,msg) VALUES ('heartbeat','begin');

