Skip to Content
Hands-On Software Engineering with Golang
book

Hands-On Software Engineering with Golang

by Achilleas Anagnostopoulos
January 2020
Intermediate to advanced
640 pages
16h 56m
English
Packt Publishing
Content preview from Hands-On Software Engineering with Golang

Iterating links/edges

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Software Architecture with Golang

Hands-On Software Architecture with Golang

Jyotiswarup Raiturkar

Publisher Resources

ISBN: 9781838554491Supplemental Content