January 2020
Intermediate to advanced
640 pages
16h 56m
English
To select the links that correspond to a particular partition and whose retrieved timestamp is older than the provided value, we will use the following query:
SELECT id, url, retrieved_at FROM links WHERE id >= $1 AND id < $2 AND retrieved_at < $3
The implementation of the Links method is shown in the following listing:
func (c *CockroachDBGraph) Links(fromID, toID uuid.UUID, accessedBefore time.Time) (graph.LinkIterator, error) { rows, err := c.db.Query(linksInPartitionQuery, fromID, toID, accessedBefore.UTC()) if err != nil { return nil, xerrors.Errorf("links: %w", err) } return &linkIterator{rows: rows}, nil }
As you can see, the method executes the query with the specified arguments and returns a linkIterator