Documentation ¶
Index ¶
- Variables
- func CheckUpdateContent(update bson.M) error
- func DeletedTime(update bson.M) bson.M
- func ExcludeDeleted(selector bson.M) bson.M
- func InitToGlobal(url string) error
- func NewObjectID() primitive.ObjectID
- func ObjectIDHex(s string) primitive.ObjectID
- func UpdatedTime(update bson.M) bson.M
- type Clienter
- type DefaultClient
- func (d *DefaultClient) Aggregate(collection string, matchStage primitive.D, groupStage primitive.D) ([]bson.M, error)
- func (d *DefaultClient) Close() error
- func (d *DefaultClient) Count(collection string, query bson.M) (int64, error)
- func (d *DefaultClient) CountAll(collection string, query bson.M) (int64, error)
- func (d *DefaultClient) DeleteAll(collection string, query bson.M) (int64, error)
- func (d *DefaultClient) DeleteAllCompletely(collection string, query bson.M) (int64, error)
- func (d *DefaultClient) DeleteOne(collection string, query bson.M) error
- func (d *DefaultClient) DeleteOneCompletely(collection string, query bson.M) error
- func (d *DefaultClient) EnsureIndexes(collection string, indexes []string) error
- func (d *DefaultClient) EnsureUniques(collection string, uniques []string) error
- func (d *DefaultClient) FindAll(collection string, result interface{}, query bson.M, fields bson.M, page int64, ...) error
- func (d *DefaultClient) FindOne(collection string, result interface{}, query bson.M, fields bson.M) error
- func (d *DefaultClient) GetQmgoClient(collection string) *qmgo.QmgoClient
- func (d *DefaultClient) Insert(collection string, doc interface{}) error
- func (d *DefaultClient) InsertMany(collection string, docs []interface{}) error
- func (d *DefaultClient) Transaction(collection string, callback func(sessCtx context.Context) (interface{}, error)) (interface{}, error)
- func (d *DefaultClient) UpdateAll(collection string, query bson.M, update bson.M) (int64, error)
- func (d *DefaultClient) UpdateOne(collection string, query bson.M, update bson.M) error
- func (d *DefaultClient) WithLog() Clienter
- type PublicFields
- type PublicFieldsInt
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNotFoundStr 错误 ErrNotFoundStr = qmgo.ErrNoSuchDocuments.Error() )
Functions ¶
func CheckUpdateContent ¶
CheckUpdateContent 执行更新操作之前先判断有没有$操作符
func InitToGlobal ¶
InitToGlobal 初始化mongodb,全局使用,只适用对单个mongodb操作,如果不指定数据库,默认数据库名为test
形式一:localhost 或 localhost:27017 形式二:mongodb://localhost:27017/database_name 或 mongodb://localhost1:port,localhost2:port/database_name 形式三:mongodb://user:password@localhost:27017/database_name 或 mongodb://user:password@localhost1:port,localhost2:port/database_name
Types ¶
type Clienter ¶
type Clienter interface { WithLog() Clienter Close() error Insert(collection string, doc interface{}) error InsertMany(collection string, docs []interface{}) error FindOne(collection string, result interface{}, query bson.M, fields bson.M) error FindAll(collection string, result interface{}, query bson.M, fields bson.M, skip int64, limit int64, sort ...string) error UpdateOne(collection string, query bson.M, update bson.M) error UpdateAll(collection string, query bson.M, update bson.M) (int64, error) DeleteOne(collection string, query bson.M) error DeleteAll(collection string, query bson.M) (int64, error) DeleteOneCompletely(collection string, query bson.M) error DeleteAllCompletely(collection string, query bson.M) (int64, error) Count(collection string, query bson.M) (int64, error) CountAll(collection string, query bson.M) (int64, error) EnsureIndexes(collection string, indexes []string) error EnsureUniques(collection string, uniques []string) error Aggregate(collection string, matchStage primitive.D, groupStage primitive.D) ([]bson.M, error) Transaction(collection string, callback func(sessCtx context.Context) (interface{}, error)) (interface{}, error) GetQmgoClient(collection string) *qmgo.QmgoClient }
Clienter 提供外部调用的接口
type DefaultClient ¶
type DefaultClient struct {
// contains filtered or unexported fields
}
DefaultClient mgo的客户端对象
func (*DefaultClient) Aggregate ¶
func (d *DefaultClient) Aggregate(collection string, matchStage primitive.D, groupStage primitive.D) ([]bson.M, error)
Aggregate 聚合查询
func (*DefaultClient) DeleteAllCompletely ¶
DeleteAllCompletely 删除所有匹配的记录,包括标记性删除的记录
func (*DefaultClient) DeleteOne ¶
func (d *DefaultClient) DeleteOne(collection string, query bson.M) error
DeleteOne 标记性删除一条记录
func (*DefaultClient) DeleteOneCompletely ¶
func (d *DefaultClient) DeleteOneCompletely(collection string, query bson.M) error
DeleteOneCompletely 删除一条记录,包括标记性删除的记录
func (*DefaultClient) EnsureIndexes ¶
func (d *DefaultClient) EnsureIndexes(collection string, indexes []string) error
EnsureIndexes 设置普通索引
func (*DefaultClient) EnsureUniques ¶
func (d *DefaultClient) EnsureUniques(collection string, uniques []string) error
EnsureUniques 设置唯一索引
func (*DefaultClient) FindAll ¶
func (d *DefaultClient) FindAll(collection string, result interface{}, query bson.M, fields bson.M, page int64, limit int64, sort ...string) error
FindAll 查找符合条件的多条记录,这里参数skip表示页码,limit表示每页多少行数据
func (*DefaultClient) FindOne ¶
func (d *DefaultClient) FindOne(collection string, result interface{}, query bson.M, fields bson.M) error
FindOne 查找一条记录
func (*DefaultClient) GetQmgoClient ¶
func (d *DefaultClient) GetQmgoClient(collection string) *qmgo.QmgoClient
GetQmgoClient 获取client对象
func (*DefaultClient) Insert ¶
func (d *DefaultClient) Insert(collection string, doc interface{}) error
Insert 插入一条新数据
func (*DefaultClient) InsertMany ¶
func (d *DefaultClient) InsertMany(collection string, docs []interface{}) error
InsertMany 插入多条新数据
func (*DefaultClient) Transaction ¶
func (d *DefaultClient) Transaction(collection string, callback func(sessCtx context.Context) (interface{}, error)) (interface{}, error)
Transaction 事务
type PublicFields ¶
type PublicFields struct { ID primitive.ObjectID `bson:"_id" json:"id"` // 唯一ID CreatedAt time.Time `bson:"createdAt" json:"createdAt"` // 创建时间 UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"` // 修改时间 DeletedAt *time.Time `bson:"deletedAt,omitempty" json:"deletedAt,omitempty"` // 删除时间 }
PublicFields 公共字段
func (*PublicFields) SetFieldsValue ¶
func (p *PublicFields) SetFieldsValue()
SetFieldsValue 设置公共字段值,在插入数据时使用
type PublicFieldsInt ¶
type PublicFieldsInt struct { ID int64 `bson:"_id" json:"id,string"` // 唯一ID CreatedAt time.Time `bson:"createdAt" json:"createdAt"` // 创建时间 UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"` // 修改时间 DeletedAt *time.Time `bson:"deletedAt,omitempty" json:"deletedAt,omitempty"` // 删除时间 }
PublicFieldsInt 设置公共字段值,自定id,在插入数据时使用
func (*PublicFieldsInt) SetFieldsValue ¶
func (m *PublicFieldsInt) SetFieldsValue(newID int64)
SetFieldsValue 初始化
Click to show internal directories.
Click to hide internal directories.