Skip to content

Idiom - what to return from Dao/Repository #1620

Answered by m-tabaza
yatesco asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @yatesco

One option is to return ConnectionIO from the functions in the database access trait, since ConnectionIOs can be combined into one ConnectionIO (using .flatMap or a for comprehension) that runs multiple operations on the database on the same connection (or even the same transaction). After combining your ConnectionIOs, it's easy to later turn them into an IO using .transact.

Another option (the one I prefer) is to have the data access trait be parameterized with F[_], and return Fs from all functions. This F could later, for example, be fixed to ConnectionIO in an implementation of the trait.

The functions returning Query or Update could be kept in an object or a package sepa…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@yatesco
Comment options

Answer selected by yatesco
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants