-
Couldn't load subscription status.
- Fork 1
add support for multiple db #6
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
base: master
Are you sure you want to change the base?
Conversation
| ) | ||
|
|
||
| func main() { | ||
| // Load configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be a file if the environment variable is undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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