db_client 面向接口实现
This commit is contained in:
@ -14,7 +14,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// IWrapperClient 包装的客户端
|
||||
// IWrapperClient 包装的客户端, 包装 IWrapperDatabaseClient
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
@ -27,7 +27,7 @@ type IWrapperClient interface {
|
||||
// BatchAddWithConfigDir 通过具体的配置列表增加数据库实例
|
||||
BatchAddWithConfigDir(cfgDir string, logInstance *zap.Logger, extraFieldList []string) error
|
||||
// GetDBClient 基于数据库标识获取数据库实例
|
||||
GetDBClient(dbFlag string) (*define.DBClient, error)
|
||||
GetDBClient(dbFlag string) (IWrapperDatabaseClient, error)
|
||||
// GetMasterClient 获取主库连接
|
||||
GetMasterClient(ctx context.Context, dbFlag string) (*gorm.DB, error)
|
||||
// GetSlaveClient 获取从库连接
|
||||
|
31
abstract/wrapper_db_client.go
Normal file
31
abstract/wrapper_db_client.go
Normal file
@ -0,0 +1,31 @@
|
||||
// Package abstract ...
|
||||
//
|
||||
// Description : abstract ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2024-08-20 17:59
|
||||
package abstract
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.zhangdeman.cn/zhangdeman/database/define"
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// IWrapperDatabaseClient 包装gorm
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:00 2024/8/20
|
||||
type IWrapperDatabaseClient interface {
|
||||
// Init 初始化客户端连接
|
||||
Init(databaseConfig *define.Database) error
|
||||
// GetMaster 获取master连接
|
||||
GetMaster(ctx context.Context) *gorm.DB
|
||||
// GetSlave 获取slave连接
|
||||
GetSlave(ctx context.Context) *gorm.DB
|
||||
// GetDatabaseClient 获取数据库连接
|
||||
GetDatabaseClient(conf *define.Driver, logInstance *zap.Logger) (*gorm.DB, error)
|
||||
}
|
Reference in New Issue
Block a user