Conversation
| ) | ||
|
|
||
| func main() { | ||
| // Load configuration |
There was a problem hiding this comment.
could be a file if the environment variable is undefined
There was a problem hiding this comment.
`Yes, it could be a file, but in general it supposed to work with environmental variables provided by the tool using the server (Roo Code, Cline etc)
But let's have it implemented this way for the future extension 👍
| // ConnectDBs establishes connections to multiple PostgreSQL databases. | ||
| func ConnectDBs(configs map[string]Config) (map[string]*sql.DB, error) { | ||
| dbs := make(map[string]*sql.DB) | ||
| var firstErr error |
There was a problem hiding this comment.
I'd suggest to have a bag of errors here (var errBag []error) to process a case when more than one DB is throwing an error.
| db, err := sql.Open("postgres", connStr) | ||
| if err != nil { | ||
| if firstErr == nil { | ||
| firstErr = fmt.Errorf("failed to connect to database %s: %v", name, err) |
There was a problem hiding this comment.
and errBag = append(errBag, fmt.Errorf(...)) here
| dbs, err := config.ConnectDBs(configs) | ||
| if err != nil { | ||
| log.Fatalf("Failed to connect to the database: %v", err) | ||
| log.Printf("Warning: some database connections failed: %v", err) |
There was a problem hiding this comment.
maybe %+v here for better representation for bag of error
or even helper function to iterate over a bug and construct pseudo table or something like this, wdyt?
fix #3
this is not the final code, just to show you how it could be