Open HilkopterBob opened 3 days ago
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)
We should encapsulate external Databases in an Interface (
interface DB
) with embedded Methods like: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:
example(s):
db/db.go: ```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: ```go func GetAllAgentsHandler(db *db.Database){ // logic here } ```