basemodel

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseModel

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

func (*BaseModel) GetSession

func (m *BaseModel) GetSession() *xorm.Session

func (*BaseModel) Init

func (m *BaseModel) Init(opts ...Option)

func (*BaseModel) PageList

func (m *BaseModel) PageList(query *PageQuery, items interface{}) (int64, error)

List with page

type Filters

type Filters map[string]List

type List

type List []interface{}

Funnel screening condition For example, "filters":{"user_state":[0,1],"phone_state":[0]} means "where user_state in(0,1) and phone_state = 0"

type Option

type Option func(o *Options)

func WithCtx

func WithCtx(ctx context.Context) Option

func WithDefaultOrder

func WithDefaultOrder(orders ...Order) Option

func WithDefaultPageSize

func WithDefaultPageSize(page, size int) Option

func WithSession

func WithSession(session *xorm.Session) Option

type Options

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

type Order

type Order map[string]int

Order condition 1 = ASC, -1 = DESC For example, "orders":[{"created_at":1},{"id":-1}] means "order by created_at asc, id desc"

type Orders

type Orders []Order

type PageQuery

type PageQuery struct {
	Page       int
	Size       int
	Q          Q
	Filters    Filters
	Orders     Orders
	ExtraQuery QueryHandler
}

List query with page For example,

{
 "page": 1,
 "size": 20,
 "q": "x",
 "orders": [
   {
     "created_at": 1
   },
   {
     "id": -1
   }
 ],
 "filters": {
   "user_state": [
     0,
     1
   ],
   "phone_state": [
     0
   ]
 }
}

type Q

type Q map[string][]string

Fuzzy search For example, "sheldon": []string{"username", "phone"} means "username like %sheldon% or phone like %sheldon%"

type Query

type Query struct {
	Q          Q
	Filters    Filters
	Orders     Orders
	ExtraQuery QueryHandler
}

List query without page

type QueryHandler

type QueryHandler func(session *xorm.Session)

Jump to

Keyboard shortcuts

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