sqlx

package
v1.0.20 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2023 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DEFALUT_DB_OPTION      = "charset=utf8mb4&parseTime=True&loc=Local"
	DEFALUT_MAX_IDLE_CONNS = 10
	DEFAULT_MAX_OPEN_CONNS = 100
	DEFAULT_LOG_MODE       = "Info"
)

Variables

View Source
var (
	ErrRecordNotFound = gorm.ErrRecordNotFound
)

Functions

func NewWriter

func NewWriter(w logger.Writer) *writer

Types

type Config added in v1.0.12

type Config struct {
	IP           string `yaml:"ip"`             // 服务器地址
	Port         string `yaml:"port"`           // 端口
	DB           string `yaml:"db"`             // 数据库名
	Name         string `yaml:"username"`       // 数据库用户名
	Password     string `yaml:"password"`       // 数据库密码
	Option       string `yaml:"option"`         // 高级配置
	MaxIdleConns int    `yaml:"max-idle-conns"` // 空闲中的最大连接数
	MaxOpenConns int    `yaml:"max-open-conns"` // 打开到数据库的最大连接数
	LogMode      string `yaml:"log-mode"`       // 是否开启Gorm全局日志
}

func (*Config) DNS added in v1.0.12

func (m *Config) DNS() string

type Option

type Option func(db *gorm.DB) error

func OrderOption

func OrderOption(order string) Option

func PageOption

func PageOption(page, pageSize int) Option

type PageInfo

type PageInfo struct {
	Page     int `json:"page" form:"page"`         // 页码
	PageSize int `json:"pageSize" form:"pageSize"` // 每页大小
}

type SqlConn

type SqlConn interface {
	DB() *gorm.DB
	Raw(sql string, values ...interface{}) *gorm.DB
	//TODO 携带trace相关逻辑
	RawCtx(ctx context.Context, sql string, values ...interface{}) *gorm.DB
	Insert(val interface{}) error
	InsertCtx(ctx context.Context, val interface{}) error
	FindOne(id int64, out interface{}) error
	FindOneByFilter(filter map[string]interface{}, out interface{}, opts ...Option) error
	FindByFilter(filter map[string]interface{}, out interface{}, opts ...Option) error
	//更新记录,包含零值字段
	Save(val interface{}) *gorm.DB
	//更新记录,非零值字段
	Updates(val interface{}) *gorm.DB
	//根据条件更新记录
	UpdateByFilter(model interface{}, filter map[string]interface{}, upVal map[string]interface{}) *gorm.DB
	//删除主键记录
	Delete(model interface{}, id int64) error
	//根据条件删除记录
	DeleteByFilter(model interface{}, filter map[string]interface{}) error
}

func NewConn

func NewConn(conf Config) (SqlConn, error)

Jump to

Keyboard shortcuts

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