Documentation
¶
Index ¶
- Variables
- func Aggregate(m IDefaultModel, pipeline any, result any) error
- func CloseAll()
- func Col(name string) *qmgo.Collection
- func Ctx() context.Context
- func Delete(m IDefaultModel) error
- func Distinct(m IDefaultModel, filter any, field string, result any) error
- func ExistInDB(m IDefaultModel, filter any) bool
- func FindById(colName string, id string, res any) (bool, error)
- func FindOne(m IDefaultModel, filter map[string]any) (hasResult bool)
- func FindPage(m IDefaultModel, filter any, res any, pageSize int64, currentPage int64) (totalDoc int64, totalPage int64)
- func FindPageWithOption(m IDefaultModel, filter any, res any, pageSize int64, currentPage int64, ...) (totalDoc int64, totalPage int64)
- func InitWgm(connectionUri string, databaseName string) error
- func Insert(m IDefaultModel) (*qmgo.InsertOneResult, error)
- func IsNoResult(err error) bool
- func MustHexToObjectId(strId string) primitive.ObjectID
- func Ping() error
- func Update(m IDefaultModel, filter ...map[string]any) error
- func Updater(m any) *updater
- type DefaultModel
- func (m *DefaultModel) BeforeInsert(ctx context.Context) error
- func (m *DefaultModel) BeforeUpdate(ctx context.Context) error
- func (m *DefaultModel) BeforeUpsert(ctx context.Context) error
- func (m *DefaultModel) ColName() string
- func (m *DefaultModel) GetId() string
- func (m *DefaultModel) GetObjectID() primitive.ObjectID
- func (m *DefaultModel) PutId(id string)
- type FindPageOption
- type IDefaultModel
Constants ¶
This section is empty.
Variables ¶
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 Col ¶
func Col(name string) *qmgo.Collection
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 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 Insert ¶
func Insert(m IDefaultModel) (*qmgo.InsertOneResult, error)
func IsNoResult ¶
IsNoResult 是否结果不存在 err 数据库查询后返回的 err bool 结果,true 为未查询到数据,反之亦然
func MustHexToObjectId ¶
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) 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