← ClaudeAtlas

data-source-patternslisted

Choosing how code reaches the database — Table Data Gateway, Row Data Gateway, Active Record or Data Mapper — from the shape of the domain logic rather than from framework habit, and knowing what each one couples together. Use when a new module's persistence approach is being chosen, when entities carry both business rules and save() methods, when JPA is being applied to a schema that fights it, when SQL is scattered through service classes, when a "DAO" layer duplicates what the ORM already provides, when the domain model's shape is visibly dictated by the tables, when bulk or reporting work is being forced through an ORM, or when a team is arguing Active Record versus Data Mapper in the abstract. Does not cover where business logic lives (domain-logic-organization), the ORM's runtime behaviour — unit of work, identity map, lazy load (orm-behavioral-patterns), the column-level mapping decisions (orm-structural-mapping), or the collection-shaped abstraction over aggregates (repository-pattern).
robsonkades/agent-skills · ★ 2 · Data & Documents · score 75
Install: claude install-skill robsonkades/agent-skills
# Data Source Patterns ## Purpose Pick the data-access pattern that matches the logic it will serve, and know precisely what each one couples to what. Inspect both **who owns database access** and how independently the object model must evolve from the schema. Shape alone does not classify a pattern. The failure this prevents is choosing by default — JPA entities for everything because the starter is on the classpath, or a hand-rolled DAO layer because the previous project had one — and then fighting the consequences for years in code that looks like a mapping problem but is a pattern-selection problem. ## The four patterns ```text Table Data Gateway one gateway for a table or view; its SQL lives there; methods take and return primitives or record sets. No domain objects, no per-row identity. Row Data Gateway one object per row; it holds the row's data and knows how to load and save itself. No business logic — that distinction is the whole point. Active Record Row Data Gateway plus the business logic for that row. Object shape follows table shape; persistence is a method on the object. Data Mapper a separate mapper moves data between objects and tables. The objects know nothing about persistence, so the two shapes may diverge freely. ``` An ORM like JPA/Hib