Building WordRepository and GameRepository Adapters
Learn about database design, accessing the database, and GameRepository implementation.
We'll cover the following
In this lesson, we’ll use the popular database library Jdbi to implement the fetchWordByNumber()
method of interface WordRepository
and make our failing integration test pass.
An external system, like a database, is accessed through a port in the domain model. The code that is specific to that external system is contained in an adapter. Our failing test enables us to write the database access code to fetch a word to guess.
Database design
A little bit of database design thinking needs to be done before we begin writing code. For the task at hand, it’s enough to note that we’ll store all available words to guess in a database table named word
. This table will have two columns. There will be a primary key named word_number
and a five-letter word in a column named word.
Let’s test-drive this out:
We run the test to reveal that the
word
table does not exist:
Get hands-on with 1400+ tech skills courses.