wgm

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FindPageOptionSyncPool = sync.Pool{
	New: func() interface{} {
		return new(FindPageOption)
	},
}

Functions

func Aggregate added in v1.0.1

func Aggregate(m IDefaultModel, pipeline any, result any) error

Aggregate @param m: 查询合集 @param pipeline: 聚合管道,必须为数组 @param result: 查询结果,必须为指向数组的指针 @Description: 聚合查询,详情见 https://www.mongodb.com/docs/manual/aggregation/

func CloseAll

func CloseAll()

func Col

func Col(name string) *qmgo.Collection

func Ctx

func Ctx() context.Context

func Delete

func Delete(m IDefaultModel) error

func Distinct

func Distinct(m IDefaultModel, filter any, field string, result any) error

Distinct @param m: 查询合集 @param filter: 查询前过滤doc @param field: 去重字段 @param resultSlice: 查询结果,必须为指向数组的指针 @Description: 去重查询,详情见 https://docs.mongodb.com/manual/reference/command/distinct/

func ExistInDB

func ExistInDB(m IDefaultModel, filter any) bool

ExistInDB 查询是否存在数据库 m 查询的合集 filter 查询条件,查询全部文档使用 nil,查询条件使用 bson.M bool 是否存在

func FindById

func FindById(colName string, id string, res any) (bool, error)

func FindOne

func FindOne(m IDefaultModel, filter map[string]any) (hasResult bool)

FindOne 查询符合条件的第一条数据 m 查询的合集,结果也会被绑定在这 filter 查询条件,查询全部文档使用 nil,查询条件使用 bson.M hasResult 是否查询到结果

func FindPage added in v1.0.1

func FindPage(m IDefaultModel, filter any, res any, pageSize int64, currentPage int64) (totalDoc int64, totalPage int64)

FindPage 数据库分页查询 m 查询的合集 filter 查询条件,查询全部文档使用 nil,查询条件使用 bson.M res 结果集指针,必须为指向切片的指针!!! pageSize 页面大小 currentPage 当前页面 totalDoc 总数据数量 totalPage 总页面数量

func FindPageWithOption added in v1.0.1

func FindPageWithOption(m IDefaultModel, filter any, res any, pageSize int64, currentPage int64, option *FindPageOption) (totalDoc int64, totalPage int64)

FindPageWithOption 数据库多条件分页查询 m 查询的合集 filter 查询条件,查询全部文档使用 nil,查询条件使用 bson.M res 结果集指针,必须为指向切片的指针!!! pageSize 页面大小 currentPage 当前页面 totalDoc 总数据数量 totalPage 总页面数量

func InitWgm

func InitWgm(connectionUri string, databaseName string) error

func Insert

func IsNoResult

func IsNoResult(err error) bool

IsNoResult 是否结果不存在 err 数据库查询后返回的 err bool 结果,true 为未查询到数据,反之亦然

func MustHexToObjectId

func MustHexToObjectId(strId string) primitive.ObjectID

func Ping

func Ping() error

func Update

func Update(m IDefaultModel, filter ...map[string]any) error

func Updater

func Updater(m any) *updater

Updater creates a new updater instance, can be used for chain call

Types

type DefaultModel

type DefaultModel struct {
	Id             primitive.ObjectID `bson:"_id" json:"id"`
	CreateTime     int64              `bson:"create_time" json:"create_time"`
	LastModifyTime int64              `bson:"last_modify_time" json:"last_modify_time"`
}

func (*DefaultModel) BeforeInsert

func (m *DefaultModel) BeforeInsert(ctx context.Context) error

func (*DefaultModel) BeforeUpdate

func (m *DefaultModel) BeforeUpdate(ctx context.Context) error

func (*DefaultModel) BeforeUpsert

func (m *DefaultModel) BeforeUpsert(ctx context.Context) error

func (*DefaultModel) ColName

func (m *DefaultModel) ColName() string

ColName 获取所对应结构体的 collection 名称

func (*DefaultModel) GetId

func (m *DefaultModel) GetId() string

GetId 获取当前结构体的 id 字段内容Hex

func (*DefaultModel) GetObjectID

func (m *DefaultModel) GetObjectID() primitive.ObjectID

func (*DefaultModel) PutId

func (m *DefaultModel) PutId(id string)

PutId 讲 Hex id 转为 ObjectId 然后填充至结构体

type FindPageOption added in v1.0.1

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

func NewFindPageOption added in v1.0.1

func NewFindPageOption() *FindPageOption

func (*FindPageOption) SetSelectField added in v1.0.1

func (o *FindPageOption) SetSelectField(bson interface{}) *FindPageOption

SetSelectField @param fieldStr bson @Description: 初始化Select, bson.M{"age": 1} means that only the age field is displayed bson.M{"age": 0} means to display other fields except age

func (*FindPageOption) SetSortField added in v1.0.1

func (o *FindPageOption) SetSortField(field ...string) *FindPageOption

SetSortField @param field []string @Description: 初始化SortField, {"age", "-name"}, first sort by age in ascending order, then sort by name in descending order

type IDefaultModel

type IDefaultModel interface {
	ColName() string
	GetId() string
	GetObjectID() primitive.ObjectID
	PutId(id string)
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

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