--MACRO:RENDER ([a-z_]+) USING ([a-z_]+):--
-- Render table {name} Using view {view}
-- Expect view {view} (renderid TEXT,class TEXT,style TEXT,usr TEXT,id INTEGER)
-- Expect table {name} (id INTEGER,...)
CREATE TABLE IF NOT EXISTS render (id TEXT,class TEXT, style TEXT, usr TEXT);
DROP TRIGGER IF EXISTS {name}_draw; CREATE TRIGGER {name}_draw 
AFTER INSERT ON {name} FOR EACH ROW
BEGIN
    INSERT OR REPLACE INTO render (id,class,style,usr)
    SELECT renderid, class, style, usr FROM {view} 
    WHERE id=new.id;
END;
DROP TRIGGER IF EXISTS {name}_redraw; CREATE TRIGGER {name}_redraw 
AFTER UPDATE ON {name} FOR EACH ROW
BEGIN
    UPDATE render
    SET style = (SELECT style FROM {view} WHERE id=new.id)
    WHERE id = (SELECT renderid FROM {view} WHERE id=new.id);
END;
DROP TRIGGER IF EXISTS {name}_erase; CREATE TRIGGER {name}_erase 
AFTER DELETE ON {name} FOR EACH ROW
BEGIN
    DELETE FROM render 
    WHERE id = (select renderid from {view} where id=new.id);
END;

