Skip to content

Instantly share code, notes, and snippets.

@elyezer
elyezer / ring_buffer.sql
Last active Apr 6, 2020
How to create a ring buffer table in SQLite
View ring_buffer.sql
-- Example table
CREATE TABLE ring_buffer (id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT);
-- Number 10 on where statement defines the ring buffer's size
CREATE TRIGGER delete_tail AFTER INSERT ON ring_buffer
BEGIN
DELETE FROM ring_buffer WHERE id%10=NEW.id%10 AND id!=NEW.id;
END;
You can’t perform that action at this time.