Created
July 19, 2020 05:03
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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