
CREATE TABLE IF NOT EXISTS cache (
    query TEXT PRIMARY KEY,
    value TEXT,
    stamp TEXT DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS control (
    id TEXT PRIMARY KEY,
    class TEXT NOT NULL,
    count INTEGER,
    stamp TEXT DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX IF NOT EXISTS cache_stamp ON cache ( stamp DESC );
CREATE INDEX IF NOT EXISTS control_stamp ON control ( stamp DESC );

DROP VIEW IF EXISTS view_cache;
DROP VIEW IF EXISTS view_control;

CREATE VIEW view_cache AS
    SELECT query, stamp FROM cache ORDER BY stamp DESC;

CREATE VIEW view_control AS
    SELECT * FROM control ORDER BY stamp DESC;

