goquery

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2019 License: MIT Imports: 9 Imported by: 0

README

GoQuery

a go query lib base on gorm.

i hate go :)

Documentation

Index

Constants

View Source
const (
	// GT ...
	GT = "gt"
	// GE ...
	GE = "ge"
	// LT ...
	LT = "lt"
	// LE ...
	LE = "le"
	// IN ...
	IN = "in"
	// NN ...
	NN = "not_in"
	// LIKE ...
	LIKE = "like"
	// ILIKE ...
	ILIKE = "ilike"
	// EQ ...
	EQ = "eq"
)

verb

Variables

This section is empty.

Functions

func DB

func DB() *gorm.DB

DB get default db...

func GetDB

func GetDB(name string) *gorm.DB

GetDB ...

func SetDefaultDB

func SetDefaultDB(db *gorm.DB)

SetDefaultDB ...

Types

type Cleanup

type Cleanup func()

func CreateDB

func CreateDB(name, dialect, addr string, isDefault bool) Cleanup

CreateDB ...

type Cond

type Cond struct {
	Op  string
	Col string
	Val string
}

Cond ...

func (*Cond) ToPredicate

func (c *Cond) ToPredicate() *Predicate

ToPredicate ...

type DBSupplier

type DBSupplier = func() *gorm.DB

type PageWrap

type PageWrap struct {
	Data  interface{} `json:"data"`
	Total int64       `json:"total"`
	Size  int64       `json:"size"`
	Page  int64       `json:"page"`
	Pages int64       `json:"pages"`
}

PageWrap ...

type PagedQueryFunc

type PagedQueryFunc func(*QReq) (*PageWrap, error)

func BuildPagedQuery

func BuildPagedQuery(entity interface{}) PagedQueryFunc

func BuildPagedQueryWithDB

func BuildPagedQueryWithDB(db *gorm.DB, entity interface{}) PagedQueryFunc

func BuildPagedQueryWithDBSupplier

func BuildPagedQueryWithDBSupplier(supplier DBSupplier, entity interface{}) PagedQueryFunc

BuildPagedQueryWithDBSupplier eg: entity: &Person{} PagedQueryFunc returns []*Person

func (PagedQueryFunc) Query

func (f PagedQueryFunc) Query(qReq *QReq) (*PageWrap, error)

type Predicate

type Predicate struct {
	Col   string
	Where string
	Val   interface{}
}

Predicate ...

func (*Predicate) Apply

func (p *Predicate) Apply(q *gorm.DB) *gorm.DB

Apply ...

type QReq

type QReq struct {
	// 页码
	Page int64 `json:"page"`
	// 每页显示条数
	Size int64 `json:"size"`
	// 显示的字段列表. 例如: ["name","age","created_at"],为空,则默认显示所有0
	Select []string `json:"select"`
	// 排序, 例如: ["-created_at"] 则表示按照 created_at 降序排列, 默认按照: ["-created_at"] 排序
	Sort []string `json:"sort"`
	// 查询条件,例如: GET /v1/logs?q["level"]=DEBUG
	Q map[string]string `json:"q"`
}

QReq ...

type StringFilter

type StringFilter func(string) bool

func ContainStringFilter

func ContainStringFilter(strs ...string) StringFilter

ContainStringFilter ...

func ExcludeStringFilter

func ExcludeStringFilter(strs ...string) StringFilter

ExcludeStringFilter ...

func (StringFilter) Do

func (f StringFilter) Do(s string) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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