01
Data Access Approaches
The trade-off between a direct query and a mapper, the points where the object model and the relational model do not line up, the repository pattern that hides the persistence detail, composing queries, the saturation behavior of a connection pool, and running schema migrations forward and backward.
- 01 Direct Query and Mapper Building the same list two ways: hand-written SQL versus a small mapper that generates SQL from a declared mapping, counting the generated queries, and the control-versus-repetition trade-off between the two approaches.
- 02 Object–Relational Impedance Mismatch The four points where the object model and the relational model do not line up: identity, inheritance, relation direction, and granularity. Each mismatch is measured and shown together with the mapping decision that closes it.
- 03 Repository Pattern The repository pattern, which gathers the persistence detail behind a single interface: testing business rules with a fake repository and no database, applying the same contract to two implementations, and measuring the persistence leak per module.
- 04 Query Objects and Specifications Turning a criterion into an object: each specification produces its own SQL fragment and bound values, combines with and-or-not, the same criterion works as an in-memory predicate, and identifiers are limited with an allowlist.
- 05 Connection Pool Managing a connection as an expensive resource: measuring the opening cost, a fixed-size pool and queue, measuring the relationship between pool size and wait time with parallel requests, the queue timeout at saturation, and carrying over session state.
- 06 Schema Migrations Splitting a schema change into versioned steps: forward and backward migration scripts, the version table, the atomic rollback of a failed step, and changing a column without an outage through an expand-write-contract scheme.