January 2020
Intermediate to advanced
640 pages
16h 56m
English
To satisfy the list of operations from the previous section, we shall define the Graph interface as follows:
type Graph interface { UpsertLink(link *Link) error FindLink(id uuid.UUID) (*Link, error) UpsertEdge(edge *Edge) error RemoveStaleEdges(fromID uuid.UUID, updatedBefore time.Time) error Links(fromID, toID uuid.UUID, retrievedBefore time.Time) (LinkIterator, error) Edges(fromID, toID uuid.UUID, updatedBefore time.Time) (EdgeIterator, error) }
The first two methods allow us to upsert a Link model and retrieve it from the backing store if we are aware of its ID. In the following code, you can see the definition of the Link type, whose fields match the ones from the ER diagram:
type Link struct ...