Data Access Object

No Change
assess
First Added:July 1, 2026 Updated: July 29, 2026

Data Access Object. Is a Design Pattern that hides persistence behind an interface so domain code does not depend on SQL or driver details.

Summary

Garden stance: We assess Data Access Object for our estate.

Key points:

TopicNotes
Typical APIfindById, save, delete, list/query methods scoped to one aggregate or table group
ImplementationRaw SQL + driver, query builder, or ORM session hidden inside the DAO class
TestingSwap DAO for in-memory or fake implementation; keep domain tests free of a live DB when possible
MigrationsDDL lives in Sqitch (or Flyway-style tools), not scattered in DAO methods

Backends

BackendDAO hides
DatabaseSQL, parameters, connection handling, row mapping
FilesystemPaths, directories, open/read/write, permissions
Remote serviceHTTP/gRPC clients, retries, auth, response parsing; same-host daemons via IPC
Serialized stateJSON, protobuf, or other encode/decode at the boundary

Swap backends by replacing the DAO implementation while keeping the interface stable. Domain services should not branch on storage type.

Common Shapes

StyleScopeTrade-off
One DAO per tableThin CRUD around a single tableSimple; joins may leak into services
One DAO per aggregateRoot entity plus related rowsClearer domain boundary; more custom SQL
Generic DAOReusable CRUD base classFast start; tends toward anemic queries

Failure Modes

  • DAO becomes a dumping ground for every query in the system
  • Interface mirrors the database schema one-to-one while the domain model diverges
  • “DAO” label on top of a full ORM with no real abstraction boundary
  • Missing transaction boundaries when multiple DAO calls must commit together
  • Serialization logic scattered in services instead of centralized in the DAO

Related Garden Items

Details

TopicNotes
Typical APIfindById, save, delete, list/query methods scoped to one aggregate or table group
ImplementationRaw SQL + driver, query builder, or ORM session hidden inside the DAO class
TestingSwap DAO for in-memory or fake implementation; keep domain tests free of a live DB when possible
MigrationsDDL lives in Sqitch (or Flyway-style tools), not scattered in DAO methods

Backends

BackendDAO hides
DatabaseSQL, parameters, connection handling, row mapping
FilesystemPaths, directories, open/read/write, permissions
Remote serviceHTTP/gRPC clients, retries, auth, response parsing; same-host daemons via IPC
Serialized stateJSON, protobuf, or other encode/decode at the boundary

Swap backends by replacing the DAO implementation while keeping the interface stable. Domain services should not branch on storage type.

Common Shapes

StyleScopeTrade-off
One DAO per tableThin CRUD around a single tableSimple; joins may leak into services
One DAO per aggregateRoot entity plus related rowsClearer domain boundary; more custom SQL
Generic DAOReusable CRUD base classFast start; tends toward anemic queries

Failure Modes

  • DAO becomes a dumping ground for every query in the system
  • Interface mirrors the database schema one-to-one while the domain model diverges
  • “DAO” label on top of a full ORM with no real abstraction boundary
  • Missing transaction boundaries when multiple DAO calls must commit together
  • Serialization logic scattered in services instead of centralized in the DAO

Related Garden Items