12 Persistence: Relational databases

This chapter covers

  • Relational data models and how to declare them
  • How to design relational models using the Higher-Kinded Data pattern
  • What SQL connectors in Haskell are and what makes them so difficult

We learned a lot about domain models in the previous chapters. In fact, a big part of the book is dedicated to the methodology known as domain-driven design. Although it is a very good and widespread methodology, it hasn’t always been so. Before the idea of designing systems from a domain point of view became popular, developers designed applications starting with a database model. They would first outline a relational representation of the task and then introduce the required data structures in code.

However, this methodology had some flaws. The main disadvantage was that the database representation types had a significant bias in favor of a relational structure, which wasn’t as intuitive as a domain-favored structure could be. Using the database model is not as convenient as using the corresponding domain model. This distinction was reconsidered, and the approach “domain model first, database model second” began to prevail.

12.1 Relational database model

12.1.1 Designing relational database model ADTs

12.1.2 Primary keys and the HKD pattern

12.1.3 Polymorphic ADTs with the HKD pattern

12.2 Relational database subsystem

12.2.1 SQL connectors

12.2.2 The consequences of complexity and high coupling

Summary