// Upsert mocks base method
13651
func (m *MockClient) Upsert(arg0 context.Context, arg1 []string, arg2 dosa.DomainObject) error {
	ret := m.ctrl.Call(m, "Upsert", arg0, arg1, arg2)
	ret0, _ := ret[0].(error)
	return ret0
}
1209527
func SaveInsert(t *testing.T, repo grimoire.Repo) {
	tests := []grimoire.Query{
		repo.From(users),
	}

	for _, query := range tests {
		record := User{Name: "save insert", Age: 100}

		t.Run("SaveInsert", func(t *testing.T) {
			assert.Nil(t, query.Save(&record))

			var result User
			assert.Nil(t, query.Find(record.ID).One(&result))
			assert.Equal(t, record, result)
		})
	}
}
1266884
func (be *T) UpsertServer(beSrvCfg engine.Server) (bool, error) {
	be.mu.Lock()
	defer be.mu.Unlock()

	beSrv, err := NewServer(beSrvCfg)
	if err != nil {
		return false, errors.Wrapf(err, "bad config %v", beSrvCfg)
	}
	if i := be.indexOfServer(beSrvCfg.Id); i != -1 {
		if be.srvs[i].URLKey() == beSrv.URLKey() {
			return false, nil
		}
		be.cloneSrvCfgsIfSeen()
		be.srvs[i] = beSrv
		return true, nil
	}
	be.cloneSrvCfgsIfSeen()
	be.srvs = append(be.srvs, beSrv)
	return true, nil
}
668691
func (c *Connector) Upsert(ctx context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue) error {
	if c.Next == nil {
		return NewErrNoMoreConnector()
	}
	return c.Next.Upsert(ctx, ei, values)
}
1371772
func (c *Client) UpsertPassword(user string, password []byte) error {
	_, err := c.PostJSON(
		c.Endpoint("users", user, "web", "password"),
		upsertPasswordReq{
			Password: string(password),
		})
	if err != nil {
		return trace.Wrap(err)
	}

	return nil
}
1223717
func (bk *Backend) UpsertItems(bucket []string, newItems []legacy.Item) error {
	// Open the bucket to work on the items.
	b, err := bk.openBucket(bk.flatten(bucket), os.O_CREATE|os.O_RDWR)
	if err != nil {
		return trace.Wrap(err)
	}
	defer b.Close()

	// Update items in bucket.
	for _, e := range newItems {
		b.updateItem(e.Key, e.Value, e.TTL)
	}

	return nil
}
1202517
func (m *MockStorage) Put(arg0 string, arg1 io.Reader, arg2 int64) error {
	ret := m.ctrl.Call(m, "Put", arg0, arg1, arg2)
	ret0, _ := ret[0].(error)
	return ret0
}
598957
func (s *ProvisioningService) UpsertToken(p services.ProvisionToken) error {
	if err := p.CheckAndSetDefaults(); err != nil {
		return trace.Wrap(err)
	}
	if p.Expiry().IsZero() || p.Expiry().Sub(s.Clock().Now().UTC()) < time.Second {
		p.SetTTL(s.Clock(), defaults.ProvisioningTokenTTL)
	}
	data, err := services.MarshalProvisionToken(p)
	if err != nil {
		return trace.Wrap(err)
	}
	item := backend.Item{
		Key:     backend.Key(tokensPrefix, p.GetName()),
		Value:   data,
		Expires: p.Expiry(),
		ID:      p.GetResourceID(),
	}
	_, err = s.Put(context.TODO(), item)
	if err != nil {
		return trace.Wrap(err)
	}
	return nil
}
1093965
func (s *CombinedPrimitiveSlice) UpsertRecorded(l interface{}) {
	v := s.upsert(l)
	v.recorded = l
	v.recordedSet = true
}
570345
func (t *Tree) Upsert(ctx context.Context, kvp KeyValuePair, txinfo TxInfo) (err error) {
	t.Lock()
	defer t.Unlock()

	root, err := t.eng.LookupRoot(ctx)
	if err != nil {
		return err
	}

	prevRoot := root
	var last *Node

	var path path
	var level Level
	var curr *Node

	// Root might be nil if we're upserting into an empty tree
	if root != nil {
		_, curr, err = t.lookupNode(ctx, root)
		if err != nil {
			return err
		}
	}

	// Find the path from the key up to the root;
	// find by walking down from the root.
	for curr != nil {
		prefix, index := t.cfg.prefixAndIndexAtLevel(level, kvp.Key)
		path.push(step{p: prefix, n: curr, l: level, i: index})
		level++
		last = curr
		if curr.Type == nodeTypeLeaf {
			break
		}
		nxt, err := curr.findChildByIndex(index)
		if err != nil {
			return err
		}
		if nxt == nil {
			break
		}
		_, curr, err = t.lookupNode(ctx, nxt)
		if err != nil {
			return err
		}
	}

	// Figure out what to store at the node where we stopped going down the path.
	var sm *SortedMap
	if last == nil || last.Type == nodeTypeINode {
		sm = newSortedMapFromKeyAndValue(kvp)
		level = 0
	} else if val2 := last.findValueInLeaf(kvp.Key); val2 == nil || !deepEqual(val2, kvp.Value) {
		sm = newSortedMapFromNode(last).replace(kvp)
		level = path.len() - 1
	} else {
		return nil
	}

	// Make a new subtree out of our new node.
	hsh, err := t.hashTreeRecursive(ctx, level, sm, prevRoot)
	if err != nil {
		return err
	}

	path.reverse()

	for _, step := range path.steps {
		if step.n.Type != nodeTypeINode {
			continue
		}
		sm := newChildPointerMapFromNode(step.n).set(step.i, hsh)
		var nodeExported []byte
		hsh, _, nodeExported, err = sm.exportToNode(t.cfg.hasher, prevRoot, step.l)
		if err != nil {
			return err
		}
		err = t.eng.StoreNode(ctx, hsh, nodeExported)
		if err != nil {
			return err
		}
	}
	err = t.eng.CommitRoot(ctx, prevRoot, hsh, txinfo)

	return err
}
808078
func (db *DB) Upsert(list ...interface{}) error {
	return insertObjects(db.Context(), db, db, getUpsert, list, opUpsert)
}
829775
func (p *ExtraStructs) Upsert(param string, paramType reflect.Type) *ExtraStruct {
	t := *p
	for i, extraStruct := range t {
		if extraStruct.FieldName == param {
			t[i].FieldType = paramType
			return t[i]
		}
	}
	extraStruct := &ExtraStruct{
		FieldName: param,
	}
	if paramType != nil {
		extraStruct.FieldType = paramType
	}
	*p = append(t, extraStruct)
	return (*p)[len(*p)-1]
}
763667
func (s *IdentityService) UpsertPassword(user string, password []byte) error {
	if user == "" {
		return trace.BadParameter("missing username")
	}
	err := services.VerifyPassword(password)
	if err != nil {
		return trace.Wrap(err)
	}
	hash, err := bcrypt.GenerateFromPassword(password, bcrypt.DefaultCost)
	if err != nil {
		return trace.Wrap(err)
	}

	err = s.UpsertPasswordHash(user, hash)
	if err != nil {
		return trace.Wrap(err)
	}

	return nil
}
360335
func (m *MockStatefulSetInterface) Update(arg0 *v1.StatefulSet) (*v1.StatefulSet, error) {
	ret := m.ctrl.Call(m, "Update", arg0)
	ret0, _ := ret[0].(*v1.StatefulSet)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
1006460
func (k kvstoreImplementation) upsert(ctx context.Context, key string, value []byte, lease bool) error {
	_, err := kvstore.UpdateIfDifferent(ctx, key, value, lease)
	return err
}
1234239
func (s *IdentityService) UpsertTOTP(user string, secretKey string) error {
	if user == "" {
		return trace.BadParameter("missing user name")
	}

	item := backend.Item{
		Key:   backend.Key(webPrefix, usersPrefix, user, totpPrefix),
		Value: []byte(secretKey),
	}

	_, err := s.Put(context.TODO(), item)
	if err != nil {
		return trace.Wrap(err)
	}

	return nil
}
269455
func (s *CombinedPrimitiveSlice) UpsertLocal(l interface{}) {
	v := s.upsert(l)
	v.local = l
	v.localSet = true
}