func (s *Sharding) switchConn(db *gorm.DB) {
// Support ignore sharding in some case, like:
// When DoubleWrite is enabled, we need to query database schema
// information by table name during the migration.
if _, ok := db.Get(ShardingIgnoreStoreKey); !ok {
s.ConnPool = &ConnPool{ConnPool: db.Statement.ConnPool, sharding: s, currentDB: db} // 记录当前的db实例
db.Statement.ConnPool = s.ConnPool
}
}
Describe the feature
替换原sql, gorm 追踪记录新的sql内容
Motivation
希望执行分表后生成新的sql记录到日志中,而不是原来的sql。
Related Issues
conn_pool.go
sharding.go