Documentation
¶
Index ¶
- func GetContextWithTraceID(ctx context.Context) context.Context
- func SplitIndex(pageNumber, pageSize, total int) (canSplit bool, start int, end int)
- type BatchTx
- type Client
- func (c *Client) AfterQuery(ctx context.Context, event *bun.QueryEvent)
- func (c *Client) BeforeQuery(ctx context.Context, event *bun.QueryEvent) context.Context
- func (c *Client) Begin(ctx context.Context) (*bun.Tx, context.CancelFunc, error)
- func (c *Client) Close()
- func (c *Client) Delete(ctx context.Context, model interface{}, id interface{}, tx ...*bun.Tx) (int64, error)
- func (c *Client) GetDB() *bun.DB
- func (c *Client) GetDelete(model interface{}, tx ...*bun.Tx) *bun.DeleteQuery
- func (c *Client) GetInsert(model interface{}, tx ...*bun.Tx) *bun.InsertQuery
- func (c *Client) GetRowsAffected(result sql.Result, err error) (int64, error)
- func (c *Client) GetSelect(model interface{}) *bun.SelectQuery
- func (c *Client) GetSoftDelete(model interface{}, tx ...*bun.Tx) *bun.UpdateQuery
- func (c *Client) GetTx(tx ...*bun.Tx) bun.IDB
- func (c *Client) GetUpdate(model interface{}, tx ...*bun.Tx) *bun.UpdateQuery
- func (c *Client) Insert(ctx context.Context, data interface{}, tx ...*bun.Tx) (int64, error)
- func (c *Client) ParseErr(err error) error
- func (c *Client) QueryAll(ctx context.Context, result interface{}) (int, error)
- func (c *Client) QueryPage(ctx context.Context, result interface{}, filter Filter) (int, error)
- func (c *Client) SoftDelete(ctx context.Context, model interface{}, id interface{}, tx ...*bun.Tx) (int64, error)
- type Config
- type DB
- type Filter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetContextWithTraceID ¶
GetContext getContext with traceId
Types ¶
type Client ¶
func NewDBClient ¶
func (*Client) AfterQuery ¶
func (c *Client) AfterQuery(ctx context.Context, event *bun.QueryEvent)
func (*Client) BeforeQuery ¶
func (*Client) GetDelete ¶
func (c *Client) GetDelete(model interface{}, tx ...*bun.Tx) *bun.DeleteQuery
func (*Client) GetInsert ¶
func (c *Client) GetInsert(model interface{}, tx ...*bun.Tx) *bun.InsertQuery
func (*Client) GetRowsAffected ¶
func (*Client) GetSelect ¶
func (c *Client) GetSelect(model interface{}) *bun.SelectQuery
func (*Client) GetSoftDelete ¶
func (c *Client) GetSoftDelete(model interface{}, tx ...*bun.Tx) *bun.UpdateQuery
func (*Client) GetUpdate ¶
func (c *Client) GetUpdate(model interface{}, tx ...*bun.Tx) *bun.UpdateQuery
type Config ¶
type Config struct {
Dialect string `yaml:"dialect" default:"mysql" json:"dialect"`
Url string `yaml:"url" default:"127.0.0.1:3306" json:"url"`
DbName string `yaml:"dbName" json:"dbName"`
User string `yaml:"user" json:"user"`
Password string `yaml:"password" json:"password"`
EnablePasswordEncrypt bool `yaml:"enablePasswordEncrypt" json:"enablePasswordEncrypt"`
Charset string `yaml:"charset" default:"utf8mb4" json:"charset"`
MaxOpen int `yaml:"maxOpen" default:"200" json:"maxOpen"`
MaxIdle int `yaml:"maxIdle" default:"20" json:"maxIdle"`
ConnMaxLifetime int `yaml:"connMaxLifetime" default:"28800" json:"connMaxLifetime"`
ConnMaxIdleTime time.Duration `yaml:"connMaxIdleTime" json:"connMaxIdleTime" default:"60s"`
Plural bool `yaml:"plural" json:"plural"`
Debug bool `yaml:"debug" json:"debug"`
EnableMetric bool `yaml:"enableMetric" json:"enableMetric"`
TransactionTimeout time.Duration `yaml:"transactionTimeout" json:"transactionTimeout" default:"30s"`
}
type DB ¶
type DB interface {
GetDB() *bun.DB // 获取数据库连接,无事物
GetTx(tx ...*bun.Tx) bun.IDB // 获取数据库连接,如果tx=nil,那么获取的是无事物的连接,否者返回tx。
Begin(ctx context.Context) (*bun.Tx, context.CancelFunc, error) // 获取一个连接,并且开始事务
Close() // 关闭DB
GetSelect(model interface{}) *bun.SelectQuery // 获得通用处理器:查询
GetInsert(model interface{}, tx ...*bun.Tx) *bun.InsertQuery // 获得通用处理器:写入
GetUpdate(model interface{}, tx ...*bun.Tx) *bun.UpdateQuery // 获得通用处理器:更新
GetDelete(model interface{}, tx ...*bun.Tx) *bun.DeleteQuery // 获得通用处理器:删除
GetSoftDelete(model interface{}, tx ...*bun.Tx) *bun.UpdateQuery // 获得通用处理器:逻辑删除
Insert(ctx context.Context, data interface{}, tx ...*bun.Tx) (int64, error) // 通用处理:插入数据(单条及批量处理,批量太大时不要使用)
SoftDelete(ctx context.Context, model interface{}, id interface{}, tx ...*bun.Tx) (int64, error) // 通用处理:逻辑删除(id可以是单个也可以是数组)
Delete(ctx context.Context, model interface{}, id interface{}, tx ...*bun.Tx) (int64, error) // 通用处理:物理删除(id可以是单个也可以是数组)
QueryPage(ctx context.Context, result interface{}, filter Filter) (int, error) // 通用处理:根据条件查询
QueryAll(ctx context.Context, result interface{}) (int, error) // 通用处理:查询全量
GetRowsAffected(result sql.Result, err error) (int64, error) // 通用处理:获取执行结果影响的记录数量
ParseErr(err error) error // 单个数据操作,消化ErrNoRows
}
Click to show internal directories.
Click to hide internal directories.