import 'resources.drift';

CREATE TABLE IF NOT EXISTS recents(
    resource_id TEXT NOT NULL PRIMARY KEY REFERENCES resources(id),
    accessed DATETIME NOT NULL
);

CREATE INDEX IF NOT EXISTS recent_accesses ON recents(accessed DESC);

selectRecents: SELECT r.* FROM recents h INNER JOIN resources r ON h.resource_id = r.id WHERE r.deleted IS NULL AND r.parent IS NOT NULL ORDER BY h.accessed DESC;