Documentation ¶
Index ¶
- Variables
- func ConvertEntityToMap(entity interface{}) (map[string]interface{}, error)
- func GetTrans(ctx context.Context) (context.Context, *sql.Tx)
- func NewTrans(ctx context.Context, tx *sql.Tx) context.Context
- func Transaction(c context.Context, m *MysqlDB, fn func(ctx context.Context) error) error
- type Config
- type MysqlDB
- type Source
- type SqlBuilder
- func (s *SqlBuilder) Delete(ctx context.Context, table string, where map[string]interface{}) (int64, error)
- func (s *SqlBuilder) ExecuteSql(ctx context.Context, sqlStr string, bindMap map[string]interface{}) (int64, error)
- func (s *SqlBuilder) Find(ctx context.Context, entity interface{}, table string, ...) error
- func (s *SqlBuilder) FindAll(ctx context.Context, entity interface{}, table string, ...) error
- func (s *SqlBuilder) Insert(ctx context.Context, table string, entity interface{}) (int64, error)
- func (s *SqlBuilder) QuerySql(ctx context.Context, sqlStr string, bindMap map[string]interface{}, ...) error
- func (s *SqlBuilder) Update(ctx context.Context, table string, where, update map[string]interface{}) (int64, error)
Constants ¶
This section is empty.
Variables ¶
View Source
var Provider = wire.NewSet(NewConfig, NewSqlBuilder)
Provider
Functions ¶
func ConvertEntityToMap ¶
ConvertEntityToMap
Types ¶
type Config ¶
type Config struct { WDB Source `json:"wdb" mapstructure:"wdb"` RDBs []Source `json:"rdbs" mapstructure:"rdbs"` DBName string `json:"db_name" mapstructure:"db_name"` MaxOpenConn int `json:"max_open_conn" mapstructure:"max_open_conn"` MaxIdleConn int `json:"max_idle_conn" mapstructure:"max_idle_conn"` MaxLifetime int `json:"max_lifetime" mapstructure:"max_lifetime"` }
Config DB基础配置
type MysqlDB ¶
type MysqlDB struct {
// contains filtered or unexported fields
}
MysqlDB 数据库管理器 读写分离 仅对同一业务库
func NewMysqlDB ¶
NewMysqlDB 根据基础配置 初始化数据库
type Source ¶
type Source struct { Host string `json:"host" mapstructure:"host"` User string `json:"user" mapstructure:"user"` Pass string `json:"pass" mapstructure:"pass"` }
Source DB部署实例数据源配置
type SqlBuilder ¶
type SqlBuilder struct { DB *MysqlDB Query *query // contains filtered or unexported fields }
SqlBuilder
func NewSqlBuilder ¶
NewSqlBuilder
func (*SqlBuilder) Delete ¶
func (s *SqlBuilder) Delete(ctx context.Context, table string, where map[string]interface{}) (int64, error)
Delete deletes matched records in COLUMNS
func (*SqlBuilder) ExecuteSql ¶
func (s *SqlBuilder) ExecuteSql(ctx context.Context, sqlStr string, bindMap map[string]interface{}) (int64, error)
ExecuteSql by native sql
func (*SqlBuilder) Find ¶
func (s *SqlBuilder) Find(ctx context.Context, entity interface{}, table string, where map[string]interface{}, selectFields ...[]string) error
Find gets one record from table by condition "where"
func (*SqlBuilder) FindAll ¶
func (s *SqlBuilder) FindAll(ctx context.Context, entity interface{}, table string, where map[string]interface{}, selectFields ...[]string) error
FindAll gets multiple records from table by condition "where"
Click to show internal directories.
Click to hide internal directories.