11 Database and Integration Testing
This chapter covers
- Discovering and extending the sql package.
- Structuring code with external dependencies for improved maintainability.
- Testing approaches for a reliable and stable codebase.
- Designing idiomatic interfaces to achieve modularity and composability.
In the previous chapters, our engineering team at Bite built a link server. However, there are flaws: The server stores links in memory. The product owner, Lina, wants the links preserved in a database long-term, even after the link server is restarted.
Figure 11.1 shows that the team picked the SQLite database for its practicality and lightweightness. Instead of temporarily storing links in memory, Store stores them permanently in SQLite using the sqlx and sql packages.
Figure 11.1 The link server uses Store to store links permanently. Store uses sqlx, which uses Go's database/sql to interact with SQLite.

Go's sql package can communicate with any SQL (or SQL-like, row-oriented) database. It enables our programs to work independently of the underlying SQL database technology. We'll also create the helper sqlx package to work with the sql package (which can help us augment sql with additional functionality, such as logging, tracing, etc.).