I have a read-only MySql DB replica and want to use it for all select-based GORM requests and criteria all over the project (Grails 3.1.16) Is there any beautiful way to override the default DataSource only for the part of GORM methods (e.g. get, find)?
According to the documentation, we can use a particular dataSource for domain/service or use namespace with each method call. But I am looking for a more generic mechanism.
You can use dbresolver. For example:
db.Use(dbresolver.Register(dbresolver.Config{
Replicas: []gorm.Dialector{mysql.Open("read_only_replica")},
}))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With