func (o *UserAccount) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error {
	if o == nil {
		return errors.New("models: no user_account provided for upsert")
	}
	currTime := time.Now().In(boil.GetLocation())

	if o.CreatedAt.IsZero() {
		o.CreatedAt = currTime
	}

	if err := o.doBeforeUpsertHooks(ctx, exec); err != nil {
		return err
	}

	nzDefaults := queries.NonZeroDefaultSet(userAccountColumnsWithDefault, o)

	// Build cache key in-line uglily - mysql vs psql problems
	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)

	userAccountUpsertCacheMut.RLock()
	cache, cached := userAccountUpsertCache[key]
	userAccountUpsertCacheMut.RUnlock()

	var err error

	if !cached {
		insert, ret := insertColumns.InsertColumnSet(
			userAccountColumns,
			userAccountColumnsWithDefault,
			userAccountColumnsWithoutDefault,
			nzDefaults,
		)
		update := updateColumns.UpdateColumnSet(
			userAccountColumns,
			userAccountPrimaryKeyColumns,
		)

		if len(update) == 0 {
			return errors.New("models: unable to upsert user_account, could not build update column list")
		}

		conflict := conflictColumns
		if len(conflict) == 0 {
			conflict = make([]string, len(userAccountPrimaryKeyColumns))
			copy(conflict, userAccountPrimaryKeyColumns)
		}
		cache.query = buildUpsertQueryCockroachDB(dialect, "\"user_account\"", updateOnConflict, ret, update, conflict, insert)

		cache.valueMapping, err = queries.BindMapping(userAccountType, userAccountMapping, insert)
		if err != nil {
			return err
		}
		if len(ret) != 0 {
			cache.retMapping, err = queries.BindMapping(userAccountType, userAccountMapping, 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 // CockcorachDB doesn't return anything when there's no update
		}
	} else {
		_, err = exec.ExecContext(ctx, cache.query, vals...)
	}
	if err != nil {
		return errors.Wrap(err, "models: unable to upsert user_account")
	}

	if !cached {
		userAccountUpsertCacheMut.Lock()
		userAccountUpsertCache[key] = cache
		userAccountUpsertCacheMut.Unlock()
	}

	return o.doAfterUpsertHooks(ctx, exec)
}
// 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 *UserAccount) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error {
	if o == nil {
		return errors.New("models: no user_account provided for upsert")
	}
	currTime := time.Now().In(boil.GetLocation())
	if o.CreatedAt.IsZero() {
		o.CreatedAt = currTime
	}
	if err := o.doBeforeUpsertHooks(ctx, exec); err != nil {
		return err
	}
	nzDefaults := queries.NonZeroDefaultSet(userAccountColumnsWithDefault, 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)
	userAccountUpsertCacheMut.RLock()
	cache, cached := userAccountUpsertCache[key]
	userAccountUpsertCacheMut.RUnlock()
	var err error
	if !cached {
		insert, ret := insertColumns.InsertColumnSet(
			userAccountColumns,
			userAccountColumnsWithDefault,
			userAccountColumnsWithoutDefault,
			nzDefaults,
		)
		update := updateColumns.UpdateColumnSet(
			userAccountColumns,
			userAccountPrimaryKeyColumns,
		)
		if len(update) == 0 {
			return errors.New("models: unable to upsert user_account, could not build update column list")
		}
		conflict := conflictColumns
		if len(conflict) == 0 {
			conflict = make([]string, len(userAccountPrimaryKeyColumns))
			copy(conflict, userAccountPrimaryKeyColumns)
		}
		cache.query = buildUpsertQueryCockroachDB(dialect, "\"user_account\"", updateOnConflict, ret, update, conflict, insert)
		cache.valueMapping, err = queries.BindMapping(userAccountType, userAccountMapping, insert)
		if err != nil {
			return err
		}
		if len(ret) != 0 {
			cache.retMapping, err = queries.BindMapping(userAccountType, userAccountMapping, 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 user_account")
	}
	if !cached {
		userAccountUpsertCacheMut.Lock()
		userAccountUpsertCache[key] = cache
		userAccountUpsertCacheMut.Unlock()
	}
	return o.doAfterUpsertHooks(ctx, exec)
}
func ( o * UserAccount ) Upsert ( ctx context . Context , exec boil . ContextExecutor , updateOnConflict bool , conflictColumns [ ] string , updateColumns , insertColumns boil . Columns ) error { if o == nil { return errors . New ( " " ) } currTime := time . Now ( ) . In ( boil . GetLocation ( ) ) if o . CreatedAt . IsZero ( ) { o . CreatedAt = currTime } if err := o . doBeforeUpsertHooks ( ctx , exec ) ; err != nil { return err } nzDefaults := queries . NonZeroDefaultSet ( userAccountColumnsWithDefault , 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 ) userAccountUpsertCacheMut . RLock ( ) cache , cached := userAccountUpsertCache [ key ] userAccountUpsertCacheMut . RUnlock ( ) var err error if ! cached { insert , ret := insertColumns . InsertColumnSet ( userAccountColumns , userAccountColumnsWithDefault , userAccountColumnsWithoutDefault , nzDefaults , ) update := updateColumns . UpdateColumnSet ( userAccountColumns , userAccountPrimaryKeyColumns , ) if len ( update ) == 0 { return errors . New ( " " ) } conflict := conflictColumns if len ( conflict ) == 0 { conflict = make ( [ ] string , len ( userAccountPrimaryKeyColumns ) ) copy ( conflict , userAccountPrimaryKeyColumns ) } cache . query = buildUpsertQueryCockroachDB ( dialect , " \" \" " , updateOnConflict , ret , update , conflict , insert ) cache . valueMapping , err = queries . BindMapping ( userAccountType , userAccountMapping , insert ) if err != nil { return err } if len ( ret ) != 0 { cache . retMapping , err = queries . BindMapping ( userAccountType , userAccountMapping , 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 { userAccountUpsertCacheMut . Lock ( ) userAccountUpsertCache [ key ] = cache userAccountUpsertCacheMut . 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