// ScriptedUpsert should be set to true if the referenced script
// (defined in Script or ScriptId) should be called to perform an insert.
// The default is false.
779456
func (b *UpdateService) ScriptedUpsert(scriptedUpsert bool) *UpdateService {
	b.scriptedUpsert = &scriptedUpsert
	return b
}
1137338
func (c *Connector) MultiUpsert(ctx context.Context, ei *dosa.EntityInfo, multiValues []map[string]dosa.FieldValue) (result []error, err error) {
	if c.isCacheable(ei) {
		w := func() error {
			for _, values := range multiValues {
				_ = c.removeValueFromFallback(ctx, ei, createCacheKey(ei, values))
			}
			return nil
		}
		_ = c.cacheWrite(w)
	}
	return c.Next.MultiUpsert(ctx, ei, multiValues)
}
391998
func (c *Collection) Upsert(key string, val interface{}, opts *UpsertOptions) (mutOut *MutationResult, errOut error) {
	if opts == nil {
		opts = &UpsertOptions{}
	}

	span := c.startKvOpTrace(opts.ParentSpanContext, "Upsert")
	defer span.Finish()

	ctx, cancel := c.context(opts.Context, opts.Timeout)
	if cancel != nil {
		defer cancel()
	}

	res, err := c.upsert(ctx, span.Context(), key, val, *opts)
	if err != nil {
		return nil, err
	}

	if opts.PersistTo == 0 && opts.ReplicateTo == 0 {
		return res, nil
	}
	return res, c.durability(durabilitySettings{
		ctx:            opts.Context,
		tracectx:       span.Context(),
		key:            key,
		cas:            res.Cas(),
		mt:             res.MutationToken(),
		replicaTo:      opts.ReplicateTo,
		persistTo:      opts.PersistTo,
		forDelete:      false,
		scopeName:      c.scopeName(),
		collectionName: c.name(),
	})
}
544871
func (a *ACLPolicies) Upsert(policy *ACLPolicy, q *WriteOptions) (*WriteMeta, error) {
	if policy == nil || policy.Name == "" {
		return nil, fmt.Errorf("missing policy name")
	}
	wm, err := a.client.write("/v1/acl/policy/"+policy.Name, policy, nil, q)
	if err != nil {
		return nil, err
	}
	return wm, nil
}
254055
func (tx *Tx) UpsertContext(ctx context.Context, list ...interface{}) error {
	return insertObjects(ctx, tx.DB, tx, getUpsert, list, opUpsert)
}
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
}
1096826
func (p *RequestParams) Upsert(param string, paramType *reflect.StructField) {
	if p == nil {
		return
	}
	t := *p
	for i, reqparam := range t {
		if reqparam.FieldName == param {
			if paramType != nil {
				t[i].FieldType = *paramType
			}
			return
		}
	}
	reqparam := RequestParam{
		FieldName: param,
	}
	if paramType != nil {
		reqparam.FieldType = *paramType
	}
	*p = append(t, reqparam)
}
1250546
func (r *BulkUpdateRequest) DocAsUpsert(docAsUpsert bool) *BulkUpdateRequest {
	r.docAsUpsert = &docAsUpsert
	r.source = nil
	return r
}
1234499
func (fn *ScriptFunction) Script(script *Script) *ScriptFunction {
	fn.script = script
	return fn
}
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)
}
1093965
func (s *CombinedPrimitiveSlice) UpsertRecorded(l interface{}) {
	v := s.upsert(l)
	v.recorded = l
	v.recordedSet = true
}
965570
func (t *Transaction) Script(script *redis.Script, args redis.Args, handler ReplyHandler) {
	t.actions = append(t.actions, &Action{
		kind:    scriptAction,
		script:  script,
		args:    args,
		handler: handler,
	})
}
665499
func (h *sqlHelper) Upsert(
	logger lager.Logger,
	q Queryable,
	table string,
	attributes SQLAttributes,
	wheres string,
	whereBindings ...interface{},
) (bool, error) {
	res, err := h.Update(
		logger,
		q,
		table,
		attributes,
		wheres,
		whereBindings...,
	)
	if err != nil {
		return false, err
	}

	rowsAffected, err := res.RowsAffected()
	if err != nil {
		// this should never happen
		logger.Error("failed-getting-rows-affected", err)
		return false, err
	}

	if rowsAffected > 0 {
		return false, nil
	}

	res, err = h.Insert(
		logger,
		q,
		table,
		attributes,
	)
	if err != nil {
		return false, err
	}

	return true, nil
}
974625
func (s *Bucket) upsert(item *Item) error {
	if s == nil {
		return fmt.Errorf("nil storage bucket")
	}

	if item == nil {
		return fmt.Errorf("nil item")
	}

	if item.ID == "" {
		return fmt.Errorf("missing item ID")
	}

	// Look for an item with matching key and don't modify the collection
	// while iterating
	foundIdx := -1
	for itemIdx, bucketItems := range s.Items {
		if bucketItems.ID == item.ID {
			foundIdx = itemIdx
			break
		}
	}

	// If there is no match, append the item, otherwise update it
	if foundIdx == -1 {
		s.Items = append(s.Items, item)
	} else {
		s.Items[foundIdx] = item
	}

	return nil
}
1361846
func (c *Connector) MultiUpsert(ctx context.Context, ei *dosa.EntityInfo, values []map[string]dosa.FieldValue) ([]error, error) {
	// Note we do not lock here. This is representative of the behavior one would see in a deployed environment
	var errs []error
	for _, v := range values {
		errs = append(errs, c.Upsert(ctx, ei, v))
	}

	return errs, nil
}
273989
func (t *transaction) script(script *redis.Script, args redis.Args, handler replyHandler) {
	t.actions = append(t.actions, &action{
		kind:    actionScript,
		script:  script,
		args:    args,
		handler: handler,
	})
}
1272856
func (w *Wrapper) UpsertProxy(s services.Server) error {
	return w.Write.UpsertProxy(s)
}