You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently working on a project where I need to implement a custom policy for DBResolver that takes into account the zone information of each database connection. The goal is to preferentially select a connection from a specific zone when resolving the connection pool.
I've created a custom struct DBWithZone that embeds *gorm.DB, includes a Zone field and implements the gorm.ConnPool interface. I've also implemented a custom policy NearZonePolicy that attempts to select a DBWithZone from the connection pool based on the preferred zone.
However, I've encountered an issue where the gorm.ConnPool in the Resolve method of my custom policy is actually of type *sql.DB, and I can't directly convert it to my DBWithZone type.
In the Resolve method, the type assertion pool.(*DBWithZone) fails because pool is of type *sql.DB.
I'm looking for a way to associate each gorm.ConnPool (or *sql.DB) with its corresponding zone information so that I can implement my custom policy. Is there a recommended way to achieve this with GORM DBResolver? Any guidance would be greatly appreciated.
Maybe we need a factory func to let Gorm know how to create a customized gorm.ConnPool implementation instead of *sql.DB.
Thank you.
The text was updated successfully, but these errors were encountered:
I'm currently working on a project where I need to implement a custom policy for DBResolver that takes into account the zone information of each database connection. The goal is to preferentially select a connection from a specific zone when resolving the connection pool.
I've created a custom struct
DBWithZone
that embeds*gorm.DB
, includes aZone
field and implements thegorm.ConnPool
interface. I've also implemented a custom policyNearZonePolicy
that attempts to select aDBWithZone
from the connection pool based on the preferred zone.However, I've encountered an issue where the
gorm.ConnPool
in theResolve
method of my custom policy is actually of type*sql.DB
, and I can't directly convert it to myDBWithZone
type.Here's a simplified version of my code:
In the
Resolve
method, the type assertionpool.(*DBWithZone)
fails becausepool
is of type*sql.DB
.I'm looking for a way to associate each
gorm.ConnPool
(or*sql.DB
) with its corresponding zone information so that I can implement my custom policy. Is there a recommended way to achieve this with GORM DBResolver? Any guidance would be greatly appreciated.Maybe we need a factory func to let Gorm know how to create a customized
gorm.ConnPool
implementation instead of*sql.DB
.Thank you.
The text was updated successfully, but these errors were encountered: