xormhelper

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

README

BaseFrom : go-xorm

Install

go get -u -v github.com/billmi/xorm-helper

说明 :

此项目初衷,不想把一些MYSQL简单操作复杂化,做为一个扩展工具使用:已简单实现联表等常用操作,一般很少用到的子查询或者复合查询等,后期会继续更新.

以人人可以快速上手使用的心态,进行项目更新~

简要 链接 备注
join生成器 Join 您也可以使用xorm提供的Builder生成
实现xorm常规操作DB,使用map结构化,使用时参考demo Curd 您也可以使用xorm提供的Builder生成
condition生成器 Condition 使用时,请查看Demo
连表分页查询 Pagenation 结果必须关联Pojo-Struct
不分页List List-NoPagenation 结果必须关联Pojo-Struct

ps : test.sql用来测试

Documentation

Index

Constants

View Source
const (
	ListRow   = 15
	LIST_ROWS = 15

	TOTAL_PAGE_FIELD   = "total_page"   //总页数
	PAGE_FIELD         = "page"         //当前页
	ROWS_FIELD         = "rows"         //每页显示数据
	TOTAL_RECORD_FIELD = "total_record" //总数据
)

Variables

This section is empty.

Functions

func CommaPaginator

func CommaPaginator(page int, listRow int, total int) map[string]int

*

ResPageInfo [same]
@author Bill

func PagenationParse

func PagenationParse(page int, limitRow int) string

*

PagenationParse Temp

func PagenationStart

func PagenationStart(page int, limitRow int) int

*

PagenationStart

func QueryBuild

func QueryBuild(querySql string, currPage int, listRows int, usePage bool) string

func QueryTotalBuild

func QueryTotalBuild(tableName string, otherCondi string, alias string) string

Types

type XormHelper

type XormHelper struct {
	Datasource *xorm.Engine
}

*

	Struct XormHelper
    author : Bill

func (*XormHelper) ConditionBuild

func (xormhelper *XormHelper) ConditionBuild(condi map[string]map[string]interface{}) string

* SqlBuildConditon : Test Demo var condi = make(map[string]map[string]interface{}) var inCodi = make(map[string]interface{}) var like = make(map[string]interface{}) var null = make(map[string]interface{}) // null var or = make(map[string]interface{},0)

orCondi["condi"] = fmt.Sprintf("bc.status = %d",0) nullCondi["bc.cv_id"] = nil like["name"] = "Bill" inCodi["type"] = 1 inCodi["title"] = "young" condi["AND"] = inCodi condi["LIKE"] = like condi["OR"] = or condi["NULL"] = null fmt.Print(ConditionBuild(condi)) Condition Builder author : Bill

func (*XormHelper) ConditionJoin

func (xormhelper *XormHelper) ConditionJoin(join [][]string) string

* Test Demo

var data = [][]string{
	{"INNER","b b","b.id = a.id"},
	{"INNER","c c","c.id = b.id"},
}

var base = &DaoBase{} fmt.Print(base.ConditionJoin(data))

Join Builder author : Bill

func (*XormHelper) EditRow

func (xormhelper *XormHelper) EditRow(table string, condi string, params map[string]interface{}) int

* Editor Rows && Return effect rows

func (*XormHelper) GetByPo

func (xormhelper *XormHelper) GetByPo(po interface{}, table string, condi string) interface{}

* find by po Struct

func (*XormHelper) GetDatasource

func (xormhelper *XormHelper) GetDatasource() *xorm.Engine

* GetDatasource

func (*XormHelper) GetLists

func (xormhelper *XormHelper) GetLists(po interface{}, table string, fields string, pk string, alias string, join string, condition string, order string, group string) map[string]interface{}

* List to po

func (*XormHelper) GetPageLists

func (xormhelper *XormHelper) GetPageLists(po interface{}, table string, fields string, pk string, alias string, join string, condition string, order string, group string, page int, listRow int) map[string]interface{}

* PageList to po

func (*XormHelper) InsertRow

func (xormhelper *XormHelper) InsertRow(table string, params map[string]interface{}) (int, bool)

* Insert row && Return new InsertId

func (*XormHelper) SetDatasource

func (xormhelper *XormHelper) SetDatasource(datasource *xorm.Engine)

* SetDatasource

func (*XormHelper) StartTransaction

func (xormhelper *XormHelper) StartTransaction() *xorm.Session

Get Trans Stat

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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