CREATE TABLE eh_favorites (
    gid TEXT NOT NULL,
    token TEXT NOT NULL,
    title TEXT NOT NULL,
    category INTEGER NOT NULL,
    PRIMARY KEY (gid, token)
);

CREATE TABLE eh_favorites_alternatives (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    gid TEXT NOT NULL,
    token TEXT NOT NULL,
    otherGid TEXT NOT NULL,
    otherToken TEXT NOT NULL,
    UNIQUE (gid, token, otherGid, otherToken)
);

CREATE INDEX eh_favorites_alternatives_gid_token_index ON eh_favorites_alternatives(gid, token);
CREATE INDEX eh_favorites_alternatives_other_gid_token_index ON eh_favorites_alternatives(otherGid, otherToken);

selectAll:
SELECT coalesce(a.gid, f.gid), coalesce(a.token, f.token), f.title, f.category, a.otherGid, a.otherToken
FROM eh_favorites AS f
LEFT JOIN eh_favorites_alternatives AS a ON (f.gid = a.gid AND f.token = a.token) OR (f.gid = a.otherGid AND f.token = a.otherToken);

insertEhFavorites:
INSERT INTO eh_favorites (title, gid, token, category) VALUES (?, ?, ?, ?);

deleteAll:
DELETE FROM eh_favorites;

addAlternative:
INSERT INTO eh_favorites_alternatives (gid, token, otherGid, otherToken)
VALUES (:gid, :token, :otherGid, :otherToken);