Skip to content

Conversation

@bclermont
Copy link
Contributor

@bclermont bclermont commented Apr 23, 2025

fix #3

this is not the final code, just to show you how it could be

@bclermont bclermont changed the title add support for multiple db add support for multiple db fix #3 Apr 23, 2025
@bclermont bclermont changed the title add support for multiple db fix #3 add support for multiple db Apr 23, 2025
)

func main() {
// Load configuration
Copy link
Contributor Author

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

Copy link
Owner

@habuvo habuvo Apr 24, 2025

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
Copy link
Owner

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)
Copy link
Owner

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)
Copy link
Owner

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?

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

Successfully merging this pull request may close these issues.

Support multiple PostgreSQL databases at the same time

2 participants