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

REFACTOR: encapsulate DB ops in own methods #111

Open
HilkopterBob opened this issue Oct 18, 2024 · 1 comment
Open

REFACTOR: encapsulate DB ops in own methods #111

HilkopterBob opened this issue Oct 18, 2024 · 1 comment
Labels
refactor Refactor old code
Milestone

Comments

@HilkopterBob
Copy link
Owner

HilkopterBob commented Oct 18, 2024

We should encapsulate external Databases in an Interface (interface DB) with embedded Methods like:

  • sign in
  • connect
  • other CRUD's

this seperates the user (eg. handler) from the product specific implementations.

With that we can select which db-product (eg. surreal, postgres, cassandra) we use to instantiate the db.
This can be selected by an optional config flag (shouldn't be included in preset).

This enables us to slowly migrate from one db to another (if needed) without:

  • touching a hundred different functions
  • having to wait on a migration branch to finish before adding new stuff that depends on db
example(s):

db/db.go:

type Database interface {
    SignIn() error
    Connect() error
    Close() error
    QueryUser(id int) (*User, error)

db/surreal.go, db/postgres.go and db/cassandra.go now only have to implement all methods of Database to for example satisfy a handler that requests a Database from FX:

func GetAllAgentsHandler(db *db.Database){
// logic here
}
@HilkopterBob HilkopterBob added this to the 0.5.0 milestone Oct 18, 2024
@HilkopterBob HilkopterBob added the refactor Refactor old code label Oct 19, 2024
@HilkopterBob
Copy link
Owner Author

If this gets implemented successfully and proves a viable option at this state we can do the same for viper (config management), the tracer (currently OpenTelemetry, but we could use the go built in one for smaller runtime impact during development)

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

No branches or pull requests

1 participant