Skip to content

Instantly share code, notes, and snippets.

@SergKolo
Created July 19, 2020 05:03
Show Gist options
  • Save SergKolo/6ef483461892c1095aad51e480faab86 to your computer and use it in GitHub Desktop.
Save SergKolo/6ef483461892c1095aad51e480faab86 to your computer and use it in GitHub Desktop.
Simple "ring buffer" table. Mainly intended to be the most basic example of how logging can be implemented in SQLite
DROP TABLE IF EXISTS ring_log;
CREATE TABLE ring_log (
timestamp INT,
data TEXT
);
CREATE TRIGGER remove_oldest BEFORE INSERT ON ring_log
WHEN ( SELECT COUNT(*)>5 FROM ring_log )
BEGIN
DELETE FROM ring_log WHERE timestamp in ( SELECT timestamp FROM ring_log LIMIT 1 );
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment