Driving the Database Layer
In this chapter, we will implement a database adapter for one of our ports in the domain model, represented by the WordRepository
interface. This will allow our domain model to fetch words to guess from a real database, in this case, using the popular open source database Postgres. We will test-drive both the database setup and the code that accesses the database. To help us do that, we will use a test framework that is designed to simplify writing database integration tests, called DBRider.
By the end of the chapter, we will have written an integration test against a running database, implemented the fetchesWordByNumber()
method from the WordRepository
interface, and used the JDBI database access library to help us. We will create a database user with permissions on a table storing words to guess. We will create that table, then write a SQL query that JDBI will use to retrieve the word we are looking for. We will use a named parameter SQL query to avoid...