dev-mastery / comments-api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Shouldn't data-access methods return entities ?

paduc opened this issue · comments

return (await result.toArray()).map(({ _id: id, ...found }) => ({

I was wondering if data-access methods should be returning entities. In this case, we could call makeComment on each result to have a list of entities rather than a list a plain javascript objects.

In javascript we can't see the difference, but in a typed language (like Typescript) we would.

Not according to the book:

Typically the data that crosses the boundaries consists of simple data structures. You can use basic structs or simple data transfer objects if you like... or construct it into an object. The important thing is that isolated, simple data structures are passed across the boundaries. We don’t want to cheat and pass Entity objects

Martin, Robert C.. Clean Architecture: A Craftsman's Guide to Software Structure and Design (Robert C. Martin Series) (p. 207). Pearson Education. Kindle Edition.

When saving entity to DB, is it possible to pass the entity to data-access?

// add comment use case file
return commentsDb.insert(comment)