update

package
v1.0.0-beta.13 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldOPType

type FieldOPType string

FieldOPType is the field operator passed in the Update API.

const (
	Set   FieldOPType = "$set"
	UnSet FieldOPType = "$unset"
)

type FieldOperator

type FieldOperator struct {
	Op    FieldOPType
	Input jsoniter.RawMessage
}

A FieldOperator can be of the following type: { "$set": { <field1>: <value1>, ... } } { "$incr": { <field1>: <value> } } { "$unset": ["d"] }.

func NewFieldOperator

func NewFieldOperator(op FieldOPType, val jsoniter.RawMessage) *FieldOperator

NewFieldOperator returns a FieldOperator.

type FieldOperatorFactory

type FieldOperatorFactory struct {
	FieldOperators map[string]*FieldOperator
}

The FieldOperatorFactory has all the field operators passed in the Update API request. The factory implements a MergeAndGet method to convert the input to the output JSON that needs to be persisted in the database.

func BuildFieldOperators

func BuildFieldOperators(reqFields []byte) (*FieldOperatorFactory, error)

BuildFieldOperators un-marshals request "fields" present in the Update API and returns a FieldOperatorFactory The FieldOperatorFactory has the logic to remove/merge the JSON passed in the input and the one present in the database.

func (*FieldOperatorFactory) MergeAndGet

func (factory *FieldOperatorFactory) MergeAndGet(existingDoc jsoniter.RawMessage) (jsoniter.RawMessage, error)

MergeAndGet method to converts the input to the output after applying all the operators. First "$set" operation is applied and then "$unset" which means if a field is present in both $set and $unset then it won't be stored in the resulting document.

Jump to

Keyboard shortcuts

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