update

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2025 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Index

Constants

View Source
const (
	UpdateTypeSet         = "$set"
	UpdateTypeInc         = "$inc"
	UpdateTypeUnset       = "$unset"
	UpdateTypeSetOnInsert = "$setOnInsert"
)
View Source
const MongodbFieldSplit = "."

Variables

This section is empty.

Functions

This section is empty.

Types

type Selector added in v0.0.3

type Selector struct {
	// contains filtered or unexported fields
}

func (*Selector) Has added in v0.0.4

func (this *Selector) Has(key string) bool

Has 是否被选择

func (*Selector) Omit added in v0.0.3

func (this *Selector) Omit(columns ...string) bool

Omit specify fields that you want to ignore when creating, updating and querying

func (*Selector) Projection added in v0.0.3

func (this *Selector) Projection(sch *schema.Schema) map[string]bool

Projection 获取字段,如果sch!=nil && this.selector == SelectorTypeOmit 全部翻转成 Select模式 FindOneAndUpdate 时有用,其他模式传nil

func (*Selector) Release added in v0.0.3

func (this *Selector) Release()

func (*Selector) Select added in v0.0.3

func (this *Selector) Select(columns ...string) bool

Select specify fields that you want when querying, creating, updating

type SelectorType added in v0.0.3

type SelectorType int8
const (
	SelectorTypeNone SelectorType = iota
	SelectorTypeOmit
	SelectorTypeSelect
)

type SetOnInsert

type SetOnInsert interface {
	SetOnInsert() (map[string]any, error)
}

type Update

type Update map[string]bson.M

func Build

func Build(i any, sch *schema.Schema, filter *Selector, includeZeroValue bool) (update Update, upsert bool, err error)

Build 使用当前模型,将map bson.m Struct 转换成Update 如果设置了model i为bson.m可以使用数据库名和model名 selects 针对Struct更新时选择,或者忽略的字段,如果为空,更新所有非零值字段

func BuildWithStmt added in v1.2.2

func BuildWithStmt(stmt iStmt) (update Update, upsert bool, err error)

func New

func New() Update

func NewFromMap added in v1.1.0

func NewFromMap(v map[string]any) Update

func (Update) Any

func (u Update) Any(t, k string, v interface{})

func (Update) Convert

func (u Update) Convert(t string, i interface{}) error

func (Update) Get added in v1.1.0

func (u Update) Get(opt string, k string) (v any, ok bool)

func (Update) Has

func (u Update) Has(opt string, filed string) bool

func (Update) Inc

func (u Update) Inc(k string, v interface{})

func (Update) MSet added in v1.1.0

func (u Update) MSet(vs map[string]any)

func (Update) Max

func (u Update) Max(k string, v interface{})

func (Update) Min

func (u Update) Min(k string, v interface{})

func (Update) Pop

func (u Update) Pop(k string, v interface{})

func (Update) Projection

func (u Update) Projection() bson.M

func (Update) Pull

func (u Update) Pull(k string, v interface{})

func (Update) Push

func (u Update) Push(k string, v interface{})

func (Update) Remove added in v1.1.0

func (u Update) Remove(opt string, k string)

func (Update) Set

func (u Update) Set(k string, v interface{})

func (Update) SetOnInert

func (u Update) SetOnInert(k string, v interface{})

func (Update) String

func (u Update) String() string

func (Update) Transform added in v0.0.4

func (u Update) Transform(sch *schema.Schema) Update

Transform 转换成数据库字段名

func (Update) Unset added in v1.0.5

func (u Update) Unset(k string)

Jump to

Keyboard shortcuts

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