go-goyave / goyave

🍐 The enterprise REST API framework
https://goyave.dev
MIT License
1.58k stars 66 forks source link

Supports multiple database connections #225

Open zKoz210 opened 1 month ago

zKoz210 commented 1 month ago

Proposal

Discussion:

I've worked a lot with Laravel and there is a handy thing like DB::connection() that allows you to connect multiple databases to one project. It would be really cool to see it here!

For example:

  1. I use PostgreSQL as my main transactional database
  2. ClickHouse is used to collect certain development metrics and analytics

And I would like to conveniently be able to set all connections through the configuration and refer to them by name

connection - pgsql connection - ch connection - ch_analytics

System-Glitch commented 1 month ago

This would be an interesting addition indeed. It would require a design phase so it is correctly included in the framework. This will probably involve breaking changes so it would be pushed back to v6.

In the meantime, you can work around this by opening another connection yourself using database.New(cfg, func() *slog.Logger { return server.Logger }) (or manually as usual in a Go project) and exposing this new connection through a service.