service

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IServInterface

type IServInterface interface {
	Exec(fmtSqlStr string) (err error)
	Create(req interface{}, model interface{}) (err error)
	UpdateById(id uint, req interface{}, model interface{}) (err error)
	UpdateById2(id uint, req interface{}, model interface{}) (m map[string]interface{}, err error)
	DeleteByIds(ids []uint, model interface{}) (err error)
	FindById(id uint, model interface{}) (err error)
	FindByIds(ids []uint, model interface{}) (err error)
	FindByKeys(key string, ids interface{}, model interface{}) (err error)
	FindByKeysWithPreload(key string, preloads []string, ids interface{}, model interface{}) (err error)
	Find(query *gorm.DB, page *models.PageInfo, model interface{}) (err error)
	Scan(query *gorm.DB, page *models.PageInfo, model interface{}) (err error)
}

func NewBaseService

func NewBaseService() IServInterface

type Serv

type Serv struct {
	// 只用于查询
	Db *gorm.DB
	// 用于 增 删 改
	Tx *gorm.DB
}

基础数据库单表操作

func (Serv) Create

func (s Serv) Create(req interface{}, model interface{}) (err error)

Create 创建, model需使用指针, 否则可能无法插入数据

func (Serv) DeleteByIds

func (s Serv) DeleteByIds(ids []uint, model interface{}) (err error)

DeleteByIds 批量删除, model需使用指针, 否则可能无法插入数据

func (Serv) Exec

func (s Serv) Exec(fmtSqlStr string) (err error)

func (Serv) Find

func (s Serv) Find(query *gorm.DB, page *models.PageInfo, model interface{}) (err error)

Find 查询, model需使用指针, 否则可能无法绑定数据

func (Serv) FindById

func (s Serv) FindById(id uint, model interface{}) (err error)

FindById 查询指定id, model需使用指针, 否则可能无法绑定数据

func (Serv) FindByIds

func (s Serv) FindByIds(ids []uint, model interface{}) (err error)

FindByIds 查询指定id列表, model需使用指针, 否则可能无法绑定数据

func (Serv) FindByKeys

func (s Serv) FindByKeys(key string, ids interface{}, model interface{}) (err error)

FindByKeys 查询指定key列表, model需使用指针, 否则可能无法绑定数据(如不使用cache可设置为false)

func (Serv) FindByKeysWithPreload

func (s Serv) FindByKeysWithPreload(key string, preloads []string, ids interface{}, model interface{}) (err error)

FindByKeysWithPreload 查询指定key列表, 并且preload其他表, model需使用指针, 否则可能无法绑定数据(如不使用cache可设置为false)

func (Serv) Scan

func (s Serv) Scan(query *gorm.DB, page *models.PageInfo, model interface{}) (err error)

Scan Scan查询, 适用于多表联合查询, model需使用指针, 否则可能无法绑定数据

func (Serv) UpdateById

func (s Serv) UpdateById(id uint, req interface{}, model interface{}) (err error)

func (Serv) UpdateById2

func (s Serv) UpdateById2(id uint, req interface{}, model interface{}) (m map[string]interface{}, err error)

Jump to

Keyboard shortcuts

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