Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repository design pattern for database access #44

Open
NikolasHaimerl opened this issue Jan 29, 2025 · 1 comment
Open

Repository design pattern for database access #44

NikolasHaimerl opened this issue Jan 29, 2025 · 1 comment

Comments

@NikolasHaimerl
Copy link
Contributor

          What do you think about using a Repository design pattern, where we have a Repository interface providing the data access methods, and a Repository implementation that holds the reference to the pgPool instance?

See what I did in piece-indexer:

https://github.com/filecoin-station/piece-indexer/blob/main/repository/lib/redis-repository.js

There is nothing wrong with your functional-programming approach here, it's a valid direction too.

Originally posted by @bajtos in #39 (comment)

@NikolasHaimerl
Copy link
Contributor Author

NikolasHaimerl commented Feb 4, 2025

@bajtos In light of the recent discussion of moving the database access layer: Do we want to proceed with the repository design pattern. The way I see it, we would still need to either have very specific read functions in the repository class or we use a generic method (similar to loadDeals) and only provide constant strings that defined the specific query details in the data layer. Something like this:

export const QUERY_DEAL_WITH_HIGHEST_ACTIVATED_AT_EPOCH:string ="..."
export class PostgreSQLClass{
...
read(query:string,parameters:[]string) -> Promise<Array<ActiveDealDbEntry>>
...

and we then call it like so:

repository.read(QUERY_DEAL_WITH_HIGHEST_ACTIVATED_AT_EPOCH,[...])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant