mysql

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2021 License: MIT Imports: 7 Imported by: 0

README

使用

go get github.com/wuyan94zl/gowebpkg/mysql

    // 初始化连接池
    config := mysql.Config{
		Host:           "127.0.0.1",
		Port:           3306,
		Username:       "root",
		Password:       "123456",
		Database:       "blog",
		Charset:        "utf8mb4",
		MaxConnect:     100,
		MaxIdleConnect: 25,
		MaxLifeSeconds: 300,
	}
	mysql.ConMysql(config)

    // 使用
    ...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB // 定义 mysql 连接实例

Functions

func AutoMigrate

func AutoMigrate(lists map[string]interface{})

func ConMysql

func ConMysql(config Config)

Types

type Config

type Config struct {
	Host           string
	Port           uint32
	Username       string
	Password       string
	Database       string
	Charset        string
	MaxConnect     int
	MaxIdleConnect int
	MaxLifeSeconds int
}

type Orm

type Orm struct {
	DB *gorm.DB
}

func GetInstance

func GetInstance() *Orm

func (*Orm) Create

func (db *Orm) Create(model interface{}) error

创建数据

func (*Orm) Delete

func (db *Orm) Delete(model interface{}) error

删除数据

func (*Orm) First

func (db *Orm) First(model interface{}, id interface{}, relationship ...string) error

主键查询一条数据

func (*Orm) Get

func (db *Orm) Get(model interface{}, relationship ...string)

查询多条数据

func (*Orm) Limit

func (db *Orm) Limit(offset int, limit int) *Orm

设置查询分页信息

func (*Orm) One

func (db *Orm) One(model interface{}, relationship ...string) error

查询多条数据

func (*Orm) Or

func (db *Orm) Or(where map[string]interface{}) *Orm

func (*Orm) Order

func (db *Orm) Order(orderBy string) *Orm

设置查询排序

func (*Orm) Paginate

func (db *Orm) Paginate(lists *PageList, relationship ...string)

查询分页数据

func (*Orm) Relationship

func (db *Orm) Relationship(relationship []string) *Orm

设置查询关联

func (*Orm) Save

func (db *Orm) Save(model interface{}) error

保存更新数据

func (*Orm) Where

func (db *Orm) Where(where map[string]interface{}) *Orm

type PageList

type PageList struct {
	CurrentPage int64       `json:"current_page"`
	FirstPage   int64       `json:"first_page"`
	LastPage    int64       `json:"last_page"`
	PageSize    int64       `json:"page_size"`
	Total       int64       `json:"total"`
	Data        interface{} `json:"data"`
}

分页返回数

func SetPageList

func SetPageList(data interface{}, currentPage int64, pageSize ...int64) *PageList

type Where

type Where struct {
	Way   string
	Value interface{}
}

Jump to

Keyboard shortcuts

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