// Upsert attempts an insert using an executor, and does an update or ignore on conflict.
// See boil.Columns documentation for how to properly use updateColumns and insertColumns.
Upsert attempts an insert using an executor, and does an update or ignore on conflict.
See boil.Columns documentation for how to properly use updateColumns and insertColumns.
// Upsert attempts an insert using an executor and does an update or ignore on conflict . // See boil . Columns documentation for how to properly use updateColumns and insertColumns .
func (o *PollsMessage) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error {
	if o == nil {
		return errors.New("models: no polls_messages provided for upsert")
	}
	if err := o.doBeforeUpsertHooks(ctx, exec); err != nil {
		return err
	}
	nzDefaults := queries.NonZeroDefaultSet(pollsMessageColumnsWithDefault, o)
	buf := strmangle.GetBuffer()
	if updateOnConflict {
		buf.WriteByte('t')
	} else {
		buf.WriteByte('f')
	}
	buf.WriteByte('.')
	for _, c := range conflictColumns {
		buf.WriteString(c)
	}
	buf.WriteByte('.')
	buf.WriteString(strconv.Itoa(updateColumns.Kind))
	for _, c := range updateColumns.Cols {
		buf.WriteString(c)
	}
	buf.WriteByte('.')
	buf.WriteString(strconv.Itoa(insertColumns.Kind))
	for _, c := range insertColumns.Cols {
		buf.WriteString(c)
	}
	buf.WriteByte('.')
	for _, c := range nzDefaults {
		buf.WriteString(c)
	}
	key := buf.String()
	strmangle.PutBuffer(buf)
	pollsMessageUpsertCacheMut.RLock()
	cache, cached := pollsMessageUpsertCache[key]
	pollsMessageUpsertCacheMut.RUnlock()
	var err error
	if !cached {
		insert, ret := insertColumns.InsertColumnSet(
			pollsMessageColumns,
			pollsMessageColumnsWithDefault,
			pollsMessageColumnsWithoutDefault,
			nzDefaults,
		)
		update := updateColumns.UpdateColumnSet(
			pollsMessageColumns,
			pollsMessagePrimaryKeyColumns,
		)
		if len(update) == 0 {
			return errors.New("models: unable to upsert polls_messages, could not build update column list")
		}
		conflict := conflictColumns
		if len(conflict) == 0 {
			conflict = make([]string, len(pollsMessagePrimaryKeyColumns))
			copy(conflict, pollsMessagePrimaryKeyColumns)
		}
		cache.query = buildUpsertQueryCockroachDB(dialect, "\"polls_messages\"", updateOnConflict, ret, update, conflict, insert)
		cache.valueMapping, err = queries.BindMapping(pollsMessageType, pollsMessageMapping, insert)
		if err != nil {
			return err
		}
		if len(ret) != 0 {
			cache.retMapping, err = queries.BindMapping(pollsMessageType, pollsMessageMapping, ret)
			if err != nil {
				return err
			}
		}
	}
	value := reflect.Indirect(reflect.ValueOf(o))
	vals := queries.ValuesFromMapping(value, cache.valueMapping)
	var returns []interface{}
	if len(cache.retMapping) != 0 {
		returns = queries.PtrsFromMapping(value, cache.retMapping)
	}
	if boil.DebugMode {
		_, _ = fmt.Fprintln(boil.DebugWriter, cache.query)
		_, _ = fmt.Fprintln(boil.DebugWriter, vals)
	}
	if len(cache.retMapping) != 0 {
		err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...)
		if err == sql.ErrNoRows {
			err = nil 
		}
	} else {
		_, err = exec.ExecContext(ctx, cache.query, vals...)
	}
	if err != nil {
		return errors.Wrap(err, "models: unable to upsert polls_messages")
	}
	if !cached {
		pollsMessageUpsertCacheMut.Lock()
		pollsMessageUpsertCache[key] = cache
		pollsMessageUpsertCacheMut.Unlock()
	}
	return o.doAfterUpsertHooks(ctx, exec)
}
func ( o * PollsMessage ) Upsert ( ctx context . Context , exec boil . ContextExecutor , updateOnConflict bool , conflictColumns [ ] string , updateColumns , insertColumns boil . Columns ) error { if o == nil { return errors . New ( " " ) } if err := o . doBeforeUpsertHooks ( ctx , exec ) ; err != nil { return err } nzDefaults := queries . NonZeroDefaultSet ( pollsMessageColumnsWithDefault , o ) buf := strmangle . GetBuffer ( ) if updateOnConflict { buf . WriteByte ( 't' ) } else { buf . WriteByte ( 'f' ) } buf . WriteByte ( '.' ) for _ , c := range conflictColumns { buf . WriteString ( c ) } buf . WriteByte ( '.' ) buf . WriteString ( strconv . Itoa ( updateColumns . Kind ) ) for _ , c := range updateColumns . Cols { buf . WriteString ( c ) } buf . WriteByte ( '.' ) buf . WriteString ( strconv . Itoa ( insertColumns . Kind ) ) for _ , c := range insertColumns . Cols { buf . WriteString ( c ) } buf . WriteByte ( '.' ) for _ , c := range nzDefaults { buf . WriteString ( c ) } key := buf . String ( ) strmangle . PutBuffer ( buf ) pollsMessageUpsertCacheMut . RLock ( ) cache , cached := pollsMessageUpsertCache [ key ] pollsMessageUpsertCacheMut . RUnlock ( ) var err error if ! cached { insert , ret := insertColumns . InsertColumnSet ( pollsMessageColumns , pollsMessageColumnsWithDefault , pollsMessageColumnsWithoutDefault , nzDefaults , ) update := updateColumns . UpdateColumnSet ( pollsMessageColumns , pollsMessagePrimaryKeyColumns , ) if len ( update ) == 0 { return errors . New ( " " ) } conflict := conflictColumns if len ( conflict ) == 0 { conflict = make ( [ ] string , len ( pollsMessagePrimaryKeyColumns ) ) copy ( conflict , pollsMessagePrimaryKeyColumns ) } cache . query = buildUpsertQueryCockroachDB ( dialect , " \" \" " , updateOnConflict , ret , update , conflict , insert ) cache . valueMapping , err = queries . BindMapping ( pollsMessageType , pollsMessageMapping , insert ) if err != nil { return err } if len ( ret ) != 0 { cache . retMapping , err = queries . BindMapping ( pollsMessageType , pollsMessageMapping , ret ) if err != nil { return err } } } value := reflect . Indirect ( reflect . ValueOf ( o ) ) vals := queries . ValuesFromMapping ( value , cache . valueMapping ) var returns [ ] interface { } if len ( cache . retMapping ) != 0 { returns = queries . PtrsFromMapping ( value , cache . retMapping ) } if boil . DebugMode { _ , _ = fmt . Fprintln ( boil . DebugWriter , cache . query ) _ , _ = fmt . Fprintln ( boil . DebugWriter , vals ) } if len ( cache . retMapping ) != 0 { err = exec . QueryRowContext ( ctx , cache . query , vals ... ) . Scan ( returns ... ) if err == sql . ErrNoRows { err = nil } } else { _ , err = exec . ExecContext ( ctx , cache . query , vals ... ) } if err != nil { return errors . Wrap ( err , " " ) } if ! cached { pollsMessageUpsertCacheMut . Lock ( ) pollsMessageUpsertCache [ key ] = cache pollsMessageUpsertCacheMut . Unlock ( ) } return o . doAfterUpsertHooks ( ctx , exec ) }
Upsert attempts an insert using an executor, and does an update or ignore on conflict.
Upsert attempts an insert using an executor and does an update or ignore on conflict .
// Build cache key in-line uglily - mysql vs psql problems // CockcorachDB doesn't return anything when there's no update