standard

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Driver          string // 数据库驱动
	Source          string // 数据库源
	ConnMaxLifeTime int    // 数据库最大连接时长
	MaxIdleConns    int
	MaxOpenConns    int
	Slave           []struct{ Source string } // 数据库备用源
	Log             Log                       // 数据库日志
}

数据库配置

type Connecter

type Connecter interface {
	// 连接
	Connect(config *Config) (*Wrapper, error)
}

连接标准

type IBuilder

type IBuilder interface {
	// 添加
	Add(ctx context.Context, value interface{}) error
	// 更新
	Update(ctx context.Context, attrs ...interface{}) error
	// 删除
	Delete(ctx context.Context, value interface{}, where ...interface{}) error
	// 查询单条
	Find(ctx context.Context, out interface{}, where ...interface{}) error
	// 查询多条
	Get(ctx context.Context, out interface{}, where ...interface{}) error
	// 统计
	Count(ctx context.Context, value interface{}) error
	// 查询且条件
	Where(query interface{}, args ...interface{}) IBuilder
	// 查询或条件
	Or(query interface{}, args ...interface{}) IBuilder
	// 查询定位
	Offset(offset interface{}) IBuilder
	// 查询区间
	Limit(limit interface{}) IBuilder
	// 排序
	Order(value interface{}, reorder ...bool) IBuilder
	// 事务开始
	Begin(ctx context.Context) (IBuilder, error)
	// 事务回滚
	Rollback() error
	// 事务提交
	Commit() error
	// 模型
	Model(value interface{}) IBuilder
	// 检查数据是否为空
	IsEmpty(e error) bool
	// 检查是否为写库
	IsWrite() bool
	// 检查是否在事物中
	IsStartTx() bool
	// 日志
	SetLogger(log Logger) IBuilder
	// Exec
	Exec(ctx context.Context, sql string, values ...interface{}) error
	// Query
	Query(ctx context.Context, dest interface{}, sql string, values ...interface{}) error
}

builder标准

type Log

type Log struct {
	Mode int    // 数据库日志:0-无日志, 1-写日志, 2-读写日志
	Cat  string // 日志类别
}

数据库日志配置

type Logger

type Logger interface {
	Print(v ...interface{})
}

日志标准

type Wrapper

type Wrapper struct {
	sync.Mutex
	// contains filtered or unexported fields
}

数据库包装类

func NewWrap

func NewWrap(dsn IBuilder, slave ...IBuilder) *Wrapper

func (*Wrapper) Read

func (wrapper *Wrapper) Read() IBuilder

读库

func (*Wrapper) Write

func (wrapper *Wrapper) Write() IBuilder

写库

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL