model

package
v0.2.0-nightly.1552569797 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2019 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ASC sortDirection = iota
	DESC
)

Variables

This section is empty.

Functions

func Connection

func Connection(conn string) (_db *gorm.DB)

func DB

func DB() *gorm.DB

func Initialize

func Initialize()

func NewMysql

func NewMysql(connection string) *mysql

func Prefix added in v0.2.0

func Prefix() string

func Transaction

func Transaction(tf transactionFunc, attempts uint)

Types

type BaseModel added in v0.2.0

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

func (*BaseModel) DB added in v0.2.0

func (bm *BaseModel) DB() *gorm.DB

func (*BaseModel) SetDB added in v0.2.0

func (bm *BaseModel) SetDB(db *gorm.DB)

func (*BaseModel) SetTX added in v0.2.0

func (bm *BaseModel) SetTX(db *gorm.DB)

type BaseModeller added in v0.2.0

type BaseModeller interface {
	DB() *gorm.DB
	SetTX(db *gorm.DB)
}

type Filter

type Filter struct {
	Key string
	Op  string
	Val interface{}
}

type Helper added in v0.2.0

type Helper struct {
	BaseModel
}
var H Helper

func (*Helper) Count added in v0.2.0

func (h *Helper) Count(in Modeller, filterArr []Filter, withTrashed bool) (count uint, err error)

func (*Helper) Create added in v0.2.0

func (h *Helper) Create(out interface{}) error

out must be a struct pointer

func (*Helper) Delete added in v0.2.0

func (h *Helper) Delete(in interface{}, force bool) error

func (*Helper) Exist added in v0.2.0

func (h *Helper) Exist(in Modeller, withTrashed bool) (exist bool)

func (*Helper) First added in v0.2.0

func (h *Helper) First(out interface{}, withTrashed bool) error

out must be a struct pointer

func (*Helper) Q added in v0.2.0

func (h *Helper) Q(filterArr []Filter, sortArr []Sort, limit int, withTrashed bool) *gorm.DB

func (*Helper) Restore added in v0.2.0

func (h *Helper) Restore(in interface{}) error

func (*Helper) Save added in v0.2.0

func (h *Helper) Save(out interface{}, modify interface{}) error

out must be a struct pointer

func (*Helper) SaveByID added in v0.2.0

func (h *Helper) SaveByID(id interface{}, out interface{}, modify interface{}) error

type Model

type Model gorm.DB

func (*Model) Paginate

func (bm *Model) Paginate(model interface{}, c *gin.Context, perPage uint) (pagination Pagination, err error)

Model(*Q(&User{}, data, []Sort{}, 1, false)).Paginate(c, perPage)

type Modeller

type Modeller interface {
	BaseModeller
	Default() interface{}
	ObjArr(filterArr []Filter, sortArr []Sort, limit int, withTrashed bool) (interface{}, error)
	ObjArrPaginate(c *gin.Context, perPage uint, filterArr []Filter, sortArr []Sort, limit int, withTrashed bool) (pagination Pagination, err error)
}

type OrmConfigurator

type OrmConfigurator interface {
	ConnectionArgs() string
	Driver() string
	Prefix() string
}

type Pagination

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

func (*Pagination) Count

func (p *Pagination) Count() uint

func (*Pagination) CurrentPage

func (p *Pagination) CurrentPage() uint

func (*Pagination) FirstItem

func (p *Pagination) FirstItem() interface{}

func (*Pagination) ItemArr

func (p *Pagination) ItemArr() interface{}

func (*Pagination) LastItem

func (p *Pagination) LastItem() interface{}

func (*Pagination) LastPage

func (p *Pagination) LastPage() uint

func (*Pagination) PerPage

func (p *Pagination) PerPage() uint

func (*Pagination) Total

func (p *Pagination) Total() uint

type Sort

type Sort struct {
	Key       string
	Direction sortDirection
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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