Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateId(resource *Resource, key string, initVal int64) int64
- func NewStruct(name string) interface{}
- func RegisterType(elem interface{})
- func ToMap(in interface{}, tagName string) (map[string]interface{}, error)
- type DeleteOption
- type Filter
- type FindOneOptions
- type FindOptions
- type Inc
- type Operator
- type Resource
- func (resource *Resource) DeleteAny(deleteOption *DeleteOption) error
- func (resource *Resource) DeleteById(tableName string, id primitive.ObjectID) error
- func (instance *Resource) Find(filter bson.M, opts FindOptions) *commons.PagingResponse
- func (instance *Resource) FindById(id string, result interface{}, opts FindOneOptions)
- func (instance *Resource) FindOne(filter bson.M, result interface{}, opts FindOneOptions)
- func (instance *Resource) FindOneWithBson(filterJSON string, result interface{}, opts FindOneOptions)
- func (instance *Resource) FindWithBson(filterJSON string, opts FindOptions) *commons.PagingResponse
- func (instance *Resource) FindWithoutPaging(filter bson.M, opts FindOptions) []bson.M
- func (instance *Resource) Query(pipeline []bson.D, opts FindOptions) *commons.PagingResponse
- func (instance *Resource) QueryWithBson(filterJSON string, opts FindOptions) *commons.PagingResponse
- func (instance *Resource) QueryWithoutPaging(pipeline []bson.D, opts FindOptions) ([]bson.M, error)
- func (resource *Resource) SaveOrUpdateOne(u interface{}, updateOptions ...*UpdateOption) (interface{}, error)
- type Sort
- type UpdateOption
Constants ¶
View Source
const (
SetOnInsert = "setOnInsert"
)
Variables ¶
View Source
var Upsert = true
Functions ¶
func GenerateId ¶ added in v1.0.5
生成id
Types ¶
type DeleteOption ¶
type DeleteOption struct { // 集合名称 CollectionName string // 过滤字段,如果设置则以字段为查询条件进行修改,如果都没有值则失败 Filter []Filter }
集合的定义
type FindOneOptions ¶
func CreateFindOneOptions ¶
func CreateFindOneOptions(collectionName string) *FindOneOptions
func (*FindOneOptions) SetSort ¶
func (op *FindOneOptions) SetSort(sort ...Sort) *FindOneOptions
type FindOptions ¶
type FindOptions struct { commons.PagingRequest FindOneOptions // 返回的数据 Results interface{} }
func (*FindOptions) SetCollectionName ¶
func (op *FindOptions) SetCollectionName(colName string) *FindOptions
func (*FindOptions) SetSort ¶
func (op *FindOptions) SetSort(sort ...Sort) *FindOptions
type Operator ¶
type Operator string
const ( OP_IN Operator = "$in" OP_NIN Operator = "$nin" OP_EQ Operator = "$eq" OP_NE Operator = "$ne" OP_GT Operator = "$gt" OP_GTE Operator = "$gte" OP_LT Operator = "$lt" OP_LTE Operator = "$lte" OP_L_AND Operator = "$and" OP_L_NOT Operator = "$not" OP_L_NOR Operator = "$nor" OP_L_OR Operator = "$or" OP_EL_EXISTS Operator = "$exists" OP_EL_TYPE Operator = "$type" OP_EVA_EXPR Operator = "$expr" OP_EVA_JSONSCHEMA Operator = "$jsonSchema" OP_EVA_MOD Operator = "$mod" OP_EVA_REGEX Operator = "$regex" OP_EVA_TEXT Operator = "$text" OP_EVA_WHERE Operator = "$where" OP_GEO_INTERSECTS Operator = "$geoIntersects" OP_GEO_WITHIN Operator = "$geoWithin" OP_GEO_NEAR Operator = "$near" OP_GEO_NEAR_SPHERE Operator = "$nearSphere" OP_ARRAY_ELEMMATCH Operator = "$elemMatch" )
type Resource ¶
var DbTestInstance *Resource
func (*Resource) DeleteAny ¶
func (resource *Resource) DeleteAny(deleteOption *DeleteOption) error
根据条件删除数据
func (*Resource) DeleteById ¶
根据主键删除数据
func (*Resource) Find ¶
func (instance *Resource) Find(filter bson.M, opts FindOptions) *commons.PagingResponse
@param filterJSON mongo查询语句
func (*Resource) FindById ¶
func (instance *Resource) FindById(id string, result interface{}, opts FindOneOptions)
根据id查找元素
@param id 数据主键
@param result 返回的数据对象,比如 &user
func (*Resource) FindOne ¶
func (instance *Resource) FindOne(filter bson.M, result interface{}, opts FindOneOptions)
@param filterJSON mongo查询语句
func (*Resource) FindOneWithBson ¶
func (instance *Resource) FindOneWithBson(filterJSON string, result interface{}, opts FindOneOptions)
@param filterJSON mongo查询语句
func (*Resource) FindWithBson ¶
func (instance *Resource) FindWithBson(filterJSON string, opts FindOptions) *commons.PagingResponse
@param filterJSON mongo查询语句
func (*Resource) FindWithoutPaging ¶
@param filterJSON mongo查询语句
func (*Resource) Query ¶
func (instance *Resource) Query(pipeline []bson.D, opts FindOptions) *commons.PagingResponse
Example usage:
mongo.Pipeline{ {{"$group", bson.D{{"_id", "$state"}, {"totalPop", bson.D{{"$sum", "$pop"}}}}}}, {{"$match", bson.D{{"totalPop", bson.D{{"$gte", 10*1000*1000}}}}}}, }
func (*Resource) QueryWithBson ¶
func (instance *Resource) QueryWithBson(filterJSON string, opts FindOptions) *commons.PagingResponse
func (*Resource) QueryWithoutPaging ¶
func (*Resource) SaveOrUpdateOne ¶
func (resource *Resource) SaveOrUpdateOne(u interface{}, updateOptions ...*UpdateOption) (interface{}, error)
修改一个数据
type UpdateOption ¶
type UpdateOption struct { // 集合名称 CollectionName *string // 过滤字段,如果设置则以字段为查询条件进行修改,如果都没有值则失败 Filter []string // 自增字段 Inc []Inc }
集合的定义
Click to show internal directories.
Click to hide internal directories.