gmorm

package module
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2022 License: BSD-3-Clause-Clear Imports: 12 Imported by: 0

README

gmorm

介绍

golang mongodb ORM

软件架构

软件架构说明

安装教程
  1. xxxx
  2. xxxx
  3. xxxx
使用说明
  1. xxxx
  2. xxxx
  3. xxxx
参与贡献
  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request
特技
  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. Gitee 官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
  4. GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
  5. Gitee 官方提供的使用手册 https://gitee.com/help
  6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/

Documentation

Index

Constants

View Source
const OBJECTID_STR_MAX = "ffffffff0000000000000000"
View Source
const OBJECTID_STR_MIN = "000000000000000000000000"

Variables

View Source
var DefaultPageSize int64 = 10
View Source
var ErrorNoMatchData = errors.New("no match data")
View Source
var ObjectID_MAX primitive.ObjectID
View Source
var ObjectID_MIN primitive.ObjectID

Functions

func ConvertObjID added in v0.4.0

func ConvertObjID(data bson.M) (err error)

func DB

func DB() *mongo.Database

DB get gmorm db

func GetByID added in v0.4.4

func GetByID(idStr string, obj *CollectionModel) (err error)

func InitDAO

func InitDAO(url string, databaseName string) error

InitDAO init the gmorm framework

func ObjectID

func ObjectID(id string) primitive.ObjectID

func SaveOrUpdate added in v0.4.1

func SaveOrUpdate(obj CollectionModel) (err error)

Types

type CollectionModel

type CollectionModel interface {
	CollectionName() string
}

type CollectionWrap

type CollectionWrap struct {
	*mongo.Collection
	ModelType reflect.Type
	Error     error
}

func Model

func Model(obj interface{}) *CollectionWrap

func (*CollectionWrap) Count added in v0.3.4

func (cw *CollectionWrap) Count(count *int64, filters *bson.M) *CollectionWrap

func (*CollectionWrap) DeleteByID

func (cw *CollectionWrap) DeleteByID(idStr string) *CollectionWrap

DeleteByID delete the object whose ID's string is idStr

func (*CollectionWrap) DeleteManyByIDs

func (cw *CollectionWrap) DeleteManyByIDs(idStrs []string) *CollectionWrap

func (*CollectionWrap) FindOneWithBson

func (cw *CollectionWrap) FindOneWithBson(object interface{}, filter *bson.M, options *options.FindOptions) *CollectionWrap

func (*CollectionWrap) FindWithBson

func (cw *CollectionWrap) FindWithBson(objects interface{}, filter *bson.M, options *options.FindOptions) *CollectionWrap

FindWithBson find records into (&slice) with options

func (*CollectionWrap) GetByID added in v0.3.3

func (cw *CollectionWrap) GetByID(idStr string, object interface{}) *CollectionWrap

get the object by idStr [object] must be a pointer to a model

func (*CollectionWrap) SaveOrUpdate

func (cw *CollectionWrap) SaveOrUpdate(object interface{}) *CollectionWrap

SaveOrUpdate object must be a pointer to a model

func (*CollectionWrap) UpdateManyByID

func (cw *CollectionWrap) UpdateManyByID(idStrs []string, updateBsonM *bson.M) *CollectionWrap

type GModle

type GModle struct {
	IDStr string `bson:"-"`
}

type PageInfo added in v0.4.0

type PageInfo struct {
	Page     int64
	PageSize int64
}

type QueryInfo added in v0.4.0

type QueryInfo struct {
	PageInfo *PageInfo
	Filters  bson.M
	Options  options.FindOptions
}

type ResultInfo added in v0.4.0

type ResultInfo[T any] struct {
	TotalCount int64
	TotalPage  int64
	DataList   []T
}

func QueryList added in v0.4.1

func QueryList[T any](obj T, queryInfo *QueryInfo) (ptrResultInfo *ResultInfo[T], err error)

适用Golang 1.18 泛型函数实现通用分页查询

Jump to

Keyboard shortcuts

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