mysql

package
v0.0.0-...-9903bea Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(dest interface{}, query string, args ...interface{}) error

func GetDB

func GetDB() *sqlx.DB

func GetPlaceholderByFields

func GetPlaceholderByFields(fields string) string

func GetPlaceholderN

func GetPlaceholderN(n int) string

func Init

func Init(cfg Config) (err error)

func Insert

func Insert(sql string, args ...interface{}) (int, error)

func IsNoRowsErr

func IsNoRowsErr(err error) bool

Types

type Config

type Config struct {
	Addr    string
	Port    int
	User    string
	Passwd  string
	DBName  string
	CharSet string

	DialTimeout string
	// I/O read timeout. The value must be a decimal number with a unit suffix ("ms", "s", "m", "h"), such as "30s", "0.5m" or "1m30s". default:0 不超时
	ReadTimeout string
	// I/O write timeout. The value must be a decimal number with a unit suffix ("ms", "s", "m", "h"), such as "30s", "0.5m" or "1m30s".  default:0 即不超时
	WriteTimeout string
}

type PageHelper

type PageHelper struct {
	// contains filtered or unexported fields
}

PageHelper 目的是做一些通用的限制, 如:

  1. 参数校验
  2. limit参数生成

func NewPageHelper

func NewPageHelper(po, ps int) *PageHelper

func (*PageHelper) FromTo

func (p *PageHelper) FromTo() (x, y int)

FromTo 返回数据位置 [x, y] 注意 左右都是闭区间

func (*PageHelper) GetLimitParams

func (p *PageHelper) GetLimitParams() (x int, y int)

GetLimitParams 返回sql中limit x, y

func (*PageHelper) GetTotal

func (p *PageHelper) GetTotal() int

func (*PageHelper) HasNext

func (p *PageHelper) HasNext() bool

func (*PageHelper) SetOffset

func (p *PageHelper) SetOffset(off int)

SetOffset 设置额外起点 例如:共81条数据,获取 第3页(每页10条)时

offset = 0,则sql的limit为 20, 10
offset = 5,则sql的limit为 25, 10

func (*PageHelper) SetTotal

func (p *PageHelper) SetTotal(total int)

Jump to

Keyboard shortcuts

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