Sets
A set is similar to an array, but deduplicates items.
DEFINE FIELD visited ON TABLE traveler TYPE set<record<country>>;
CREATE traveler:one SET visited = [country:canada, country:usa, country:korea, country:japan];
-- Traveler comes back from a trip
UPDATE traveler:one SET visited += country:uk;
-- And again
UPDATE traveler:one SET visited += country:uk;
Response[
{
id: traveler:one,
visited: [
country:canada,
country:usa,
country:korea,
country:japan,
country:uk
]
}
]
A maximum number of items can be specified for a set.
DEFINE FIELD employees ON TABLE team TYPE set<record<employee>, 5>;
CREATE team:my_team SET employees = [employee:one, employee:two, employee:three, employee:four, employee:five];
UPDATE team:my_team SET employees += employee:one;
UPDATE team:my_team SET employees += employee:one;
UPDATE team:my_team SET employees += employee:doesnt_belong;