Documentation ¶
Index ¶
- type Builder
- func (b *Builder) Any(key string) *cond
- func (b *Builder) AnyMap(key string, m bson.M) *Builder
- func (b *Builder) Auto(queryStruct any) *Builder
- func (b *Builder) AutoWithKey(key string, val any) *Builder
- func (b *Builder) Build() bson.M
- func (b *Builder) Date(key string, defaultFormat ...string) *dateCond
- func (b *Builder) Flush() *Builder
- func (b *Builder) Num(key string) *numCond
- func (b *Builder) Oid(key ...string) *oidCond
- func (b *Builder) Or() *Builder
- func (b *Builder) RemoveCond(key string, acrossOrCond ...bool) *Builder
- func (b *Builder) Str(key string) *strCond
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder represents a filter builder.
func (*Builder) Auto ¶ added in v0.0.12
Auto will construct suitable eq filter as possible as it can.
queryStruct shuold be a stuct contains query fields (optionally with bson tags).
If bson tag is provided on field, the tag will be used as the key of cond, otherwise snake case of field's name will be used as default.
If it's a pointer:
a pointer to a struct: it will try to dereference it.
a nil pointer: do nothing.
*Anything else will lead to a panic.
func (*Builder) AutoWithKey ¶ added in v0.0.12
AutoWithKey try to add eq cond with provided key and val.
If val is a pointer:
Cond will be built if the val is one of following type and the val is non-zero value: - array, slice - bool - string - int, int8 and other ints. - uint, uint8 and other uints. - float32, float64
If val is not a pointer:
Cond will be built if the pointer is not nil.
func (*Builder) Or ¶
Or appends b.curMap to b.condMaps, and b.curMap will be assigned to a new empty map. Thus if finally b.condMaps's len is bigger than 1, then the final filter will wraps all maps into a $or condtion.
func (*Builder) RemoveCond ¶ added in v0.0.18
RemoveCond removes given key that has been added to the builder. Elimination will across all conditions if acrossOrCond is given true.