db

package
v0.0.0-...-8edd1ee Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close() (err error)

关闭数据库。

func GetDB

func GetDB() *gorm.DB

获取数据库连接对象。

func InitMysqlDB

func InitMysqlDB(host, username, password, dbname string, maxOpen, maxIdle int) (err error)

初始化默认mysql数据库

func InitSqliteDB

func InitSqliteDB(dbfile string) (err error)

初始化默认sqlite数据库

func NewMysqlDB

func NewMysqlDB(host, username, password, dbname string, maxOpen, maxIdle int) (d *gorm.DB, err error)

初始化mysql数据库

func NewSqliteDB

func NewSqliteDB(dbfile string) (d *gorm.DB, err error)

初始化sqlite数据库

Types

type Model

type Model struct {
	// 唯一标识
	ID uint `json:"id" gorm:"primary_key"`
	// 创建时间
	CreatedAt int64 `json:"created_at"`
	// 更新时间
	UpdatedAt int64 `json:"updated_at"`
	// 删除时间
	DeletedAt *int64 `sql:"index" json:"deleted_at,omitempty"`
}

自己参照gorm.model定义也可以的,可以重写json tag

type Paginator

type Paginator struct {
	TotalRecord int         `json:"total_record"`
	TotalPage   int         `json:"total_page"`
	Records     interface{} `json:"list"`
	Offset      int         `json:"offset"`
	Limit       int         `json:"limit"`
	Page        int         `json:"page"`
	PrevPage    int         `json:"prev_page"`
	NextPage    int         `json:"next_page"`
}

Paginator 分页返回

func Paging

func Paging(p *Param, result interface{}) *Paginator

Paging 分页

type Param

type Param struct {
	DB      *gorm.DB
	Page    int
	Limit   int
	OrderBy []string
	ShowSQL bool
}

Param 分页参数

Jump to

Keyboard shortcuts

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