base

package
v0.0.0-...-9b663ca Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2021 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultModel

type DefaultModel struct {
	Model
	ID        uint `gorm:"primarykey"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt sql.NullTime `gorm:"index"`
}

DefaultModel ..

type GraphQLField

type GraphQLField struct {
	FieldMap map[string]bool
	Fields   []string
}

GraphQLField ..

func ForGraphQLField

func ForGraphQLField(queryFields []string, prefix string) GraphQLField

ForGraphQLField get fields from queryFields

func NewGraphQLField

func NewGraphQLField(ctx context.Context, prefix string) GraphQLField

NewGraphQLField get graphql field from context

type Model

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

Model ..

func (*Model) Begin

func (m *Model) Begin()

Begin 开启事务

func (*Model) Commit

func (m *Model) Commit() (err error)

Commit 提交事务

func (*Model) Count

func (m *Model) Count(model interface{}) (total int64, err error)

Count 查询数据总量

func (*Model) Create

func (m *Model) Create(value interface{}) (err error)

Create 新建数据

func (*Model) Delete

func (m *Model) Delete(value interface{}, ids []int64) (err error)

Delete 删除数据

func (*Model) Find

func (m *Model) Find(dest interface{}) error

Find 查找数据

func (*Model) First

func (m *Model) First(dest interface{}) error

First 查找按主键排序第一条数据

func (*Model) FuzzyQuery

func (m *Model) FuzzyQuery(keyword string, field string) Repository

FuzzyQuery 增加模糊查询

func (*Model) GetDB

func (m *Model) GetDB() *gorm.DB

GetDB ..

func (*Model) IDArrayQuery

func (m *Model) IDArrayQuery(ids interface{}, idFieldName ...string) Repository

IDArrayQuery ids查询

func (*Model) IDQuery

func (m *Model) IDQuery(id interface{}, idFieldName ...string) Repository

IDQuery id查询

func (*Model) LeftJoin

func (m *Model) LeftJoin(query string, args ...interface{}) Repository

LeftJoin 左连接

func (*Model) Order

func (m *Model) Order(value interface{}) Repository

Order 排序

func (*Model) Pagination

func (m *Model) Pagination(offset, limit int) Repository

Pagination 分页

func (*Model) Preload

func (m *Model) Preload(query string, args ...interface{}) Repository

Preload 预加载

func (*Model) Raw

func (m *Model) Raw(sql string, result interface{}, value ...interface{}) (err error)

Raw 保存数据

func (*Model) ReSetDB

func (m *Model) ReSetDB()

ReSetDB ..

func (*Model) Rollback

func (m *Model) Rollback()

Rollback 撤回事务

func (*Model) Save

func (m *Model) Save(value interface{}) (err error)

Save 保存数据

func (*Model) Select

func (m *Model) Select(fields []string, omitFields ...string) Repository

Select 选择字段

func (*Model) SelectWithPrefix

func (m *Model) SelectWithPrefix(fields []string, prefix string, omitFields ...string) Repository

SelectWithPrefix 选择字段带上特定前缀

func (*Model) SetDB

func (m *Model) SetDB(db *gorm.DB)

SetDB ..

func (*Model) Sort

func (m *Model) Sort(sorts []*Sort) Repository

Sort 排序

func (*Model) Table

func (m *Model) Table(name string, args ...interface{}) Repository

Table ..

func (*Model) Take

func (m *Model) Take(dest interface{}) error

Take 查找单条数据

func (*Model) Unscoped

func (m *Model) Unscoped() Repository

Save 保存数据

func (*Model) Updates

func (m *Model) Updates(value interface{}) (err error)

Updates 更新数据

func (*Model) Where

func (m *Model) Where(query interface{}, args ...interface{}) Repository

Where where查询

type Repository

type Repository interface {
	SetDB(db *gorm.DB)
	ReSetDB()
	GetDB() *gorm.DB
	Table(name string, args ...interface{}) Repository
	SelectWithPrefix(fields []string, prefix string, omitFields ...string) Repository
	Select(fields []string, omitFields ...string) Repository
	LeftJoin(query string, args ...interface{}) Repository
	FuzzyQuery(keyword string, field string) Repository
	IDQuery(id interface{}, idFieldName ...string) Repository
	IDArrayQuery(ids interface{}, idFieldName ...string) Repository
	Where(query interface{}, args ...interface{}) Repository
	Pagination(offset, limit int) Repository
	Sort(sorts []*Sort) Repository
	Order(value interface{}) Repository
	Preload(query string, args ...interface{}) Repository
	First(dest interface{}) error
	Take(dest interface{}) error
	Find(dest interface{}) error
	Count(model interface{}) (total int64, err error)
	Create(value interface{}) error
	Updates(value interface{}) error
	Delete(value interface{}, ids []int64) error
	Begin()
	Rollback()
	Commit() error
}

Repository 。。

type Search struct {
	Ctx           context.Context
	SearchParam   *SearchParam
	Scheme        string
	SearchService *elastic.SearchService
	BoolQuery     *elastic.BoolQuery
	FilterQueries []elastic.Query
	IgnoreQueries []elastic.Query
}

Search ..

func NewSearch

func NewSearch(ctx context.Context, searchParam *SearchParam, scheme string) *Search

NewSearch ..

func (*Search) Filter

func (s *Search) Filter()

Filter ..

func (*Search) GetAggResults

func (s *Search) GetAggResults(aggsParams []*es.AggsParam,
	result *elastic.SearchResult) []*model.AggResult

GetAggResults ..

func (*Search) GetPageInfo

func (s *Search) GetPageInfo() (int, int)

GetPageInfo ..

type Service

type Service struct {
}

Service base service

func (Service) GetByID

func (s Service) GetByID(r Repository, id uint, columns []string) error

GetByID Get model by id

func (Service) GetConnection

func (s Service) GetConnection(r Repository, searchParam *SearchParam,
	data interface{}, replaceFunc func(field GraphQLField) error, omitFields ...string) (total int64, err error)

GetConnection get list data and total count

func (Service) GetInputFields

func (s Service) GetInputFields(ctx context.Context) []string

GetInputFields from context

func (Service) GetPageInfo

func (s Service) GetPageInfo(searchParam *SearchParam) (int, int)

GetPageInfo ...

func (Service) GetValidIDs

func (s Service) GetValidIDs(r Repository, tableName string, ids []uint) []uint

GetValidIDs ..

func (Service) OldGetConnection deprecated

func (s Service) OldGetConnection(ctx context.Context, r Repository, searchParam *SearchParam,
	data interface{}, replaceFunc func(field GraphQLField) error, omitFields ...string) (total int64, err error)

Deprecated: query params should get from searchParam not context

func (Service) RecordNotExist

func (s Service) RecordNotExist(r Repository, id interface{}, uid ...uint) bool

RecordNotExist ..

func (Service) ToInt64

func (s Service) ToInt64(ids []uint) []int64

ToInt64 change id type from uint to int64

func (Service) ToUintIDs

func (s Service) ToUintIDs(ids []int64) []uint

ToUintIDs change id type from int64 to uint

Jump to

Keyboard shortcuts

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