// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.

package models

import (
	"context"
	"database/sql"
	"fmt"
	"reflect"
	"strconv"
	"strings"
	"sync"
	"time"

	"github.com/aarondl/null/v8"
	"github.com/aarondl/sqlboiler/v4/boil"
	"github.com/aarondl/sqlboiler/v4/queries"
	"github.com/aarondl/sqlboiler/v4/queries/qm"
	"github.com/aarondl/sqlboiler/v4/queries/qmhelper"
	"github.com/aarondl/strmangle"
	"github.com/friendsofgo/errors"
)

// GroupLog is an object representing the database table.
type GroupLog struct {
	LogID             int32     `boil:"log_id" json:"log_id" toml:"log_id" yaml:"log_id"`
	UserName          string    `boil:"user_name" json:"user_name" toml:"user_name" yaml:"user_name"`
	PreferredUserName string    `boil:"preferred_user_name" json:"preferred_user_name" toml:"preferred_user_name" yaml:"preferred_user_name"`
	Logs              string    `boil:"logs" json:"logs" toml:"logs" yaml:"logs"`
	CreatedAt         time.Time `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
	UpdatedAt         time.Time `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"`
	DeletedAt         null.Time `boil:"deleted_at" json:"deleted_at,omitempty" toml:"deleted_at" yaml:"deleted_at,omitempty"`

	R *groupLogR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L groupLogL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}

var GroupLogColumns = struct {
	LogID             string
	UserName          string
	PreferredUserName string
	Logs              string
	CreatedAt         string
	UpdatedAt         string
	DeletedAt         string
}{
	LogID:             "log_id",
	UserName:          "user_name",
	PreferredUserName: "preferred_user_name",
	Logs:              "logs",
	CreatedAt:         "created_at",
	UpdatedAt:         "updated_at",
	DeletedAt:         "deleted_at",
}

var GroupLogTableColumns = struct {
	LogID             string
	UserName          string
	PreferredUserName string
	Logs              string
	CreatedAt         string
	UpdatedAt         string
	DeletedAt         string
}{
	LogID:             "group_logs.log_id",
	UserName:          "group_logs.user_name",
	PreferredUserName: "group_logs.preferred_user_name",
	Logs:              "group_logs.logs",
	CreatedAt:         "group_logs.created_at",
	UpdatedAt:         "group_logs.updated_at",
	DeletedAt:         "group_logs.deleted_at",
}

// Generated where

var GroupLogWhere = struct {
	LogID             whereHelperint32
	UserName          whereHelperstring
	PreferredUserName whereHelperstring
	Logs              whereHelperstring
	CreatedAt         whereHelpertime_Time
	UpdatedAt         whereHelpertime_Time
	DeletedAt         whereHelpernull_Time
}{
	LogID:             whereHelperint32{field: "\"group_logs\".\"log_id\""},
	UserName:          whereHelperstring{field: "\"group_logs\".\"user_name\""},
	PreferredUserName: whereHelperstring{field: "\"group_logs\".\"preferred_user_name\""},
	Logs:              whereHelperstring{field: "\"group_logs\".\"logs\""},
	CreatedAt:         whereHelpertime_Time{field: "\"group_logs\".\"created_at\""},
	UpdatedAt:         whereHelpertime_Time{field: "\"group_logs\".\"updated_at\""},
	DeletedAt:         whereHelpernull_Time{field: "\"group_logs\".\"deleted_at\""},
}

// GroupLogRels is where relationship names are stored.
var GroupLogRels = struct {
}{}

// groupLogR is where relationships are stored.
type groupLogR struct {
}

// NewStruct creates a new relationship struct
func (*groupLogR) NewStruct() *groupLogR {
	return &groupLogR{}
}

// groupLogL is where Load methods for each relationship are stored.
type groupLogL struct{}

var (
	groupLogAllColumns            = []string{"log_id", "user_name", "preferred_user_name", "logs", "created_at", "updated_at", "deleted_at"}
	groupLogColumnsWithoutDefault = []string{}
	groupLogColumnsWithDefault    = []string{"log_id", "user_name", "preferred_user_name", "logs", "created_at", "updated_at", "deleted_at"}
	groupLogPrimaryKeyColumns     = []string{"log_id"}
	groupLogGeneratedColumns      = []string{}
)

type (
	// GroupLogSlice is an alias for a slice of pointers to GroupLog.
	// This should almost always be used instead of []GroupLog.
	GroupLogSlice []*GroupLog
	// GroupLogHook is the signature for custom GroupLog hook methods
	GroupLogHook func(context.Context, boil.ContextExecutor, *GroupLog) error

	groupLogQuery struct {
		*queries.Query
	}
)

// Cache for insert, update and upsert
var (
	groupLogType                 = reflect.TypeOf(&GroupLog{})
	groupLogMapping              = queries.MakeStructMapping(groupLogType)
	groupLogPrimaryKeyMapping, _ = queries.BindMapping(groupLogType, groupLogMapping, groupLogPrimaryKeyColumns)
	groupLogInsertCacheMut       sync.RWMutex
	groupLogInsertCache          = make(map[string]insertCache)
	groupLogUpdateCacheMut       sync.RWMutex
	groupLogUpdateCache          = make(map[string]updateCache)
	groupLogUpsertCacheMut       sync.RWMutex
	groupLogUpsertCache          = make(map[string]insertCache)
)

var (
	// Force time package dependency for automated UpdatedAt/CreatedAt.
	_ = time.Second
	// Force qmhelper dependency for where clause generation (which doesn't
	// always happen)
	_ = qmhelper.Where
)

var groupLogAfterSelectMu sync.Mutex
var groupLogAfterSelectHooks []GroupLogHook

var groupLogBeforeInsertMu sync.Mutex
var groupLogBeforeInsertHooks []GroupLogHook
var groupLogAfterInsertMu sync.Mutex
var groupLogAfterInsertHooks []GroupLogHook

var groupLogBeforeUpdateMu sync.Mutex
var groupLogBeforeUpdateHooks []GroupLogHook
var groupLogAfterUpdateMu sync.Mutex
var groupLogAfterUpdateHooks []GroupLogHook

var groupLogBeforeDeleteMu sync.Mutex
var groupLogBeforeDeleteHooks []GroupLogHook
var groupLogAfterDeleteMu sync.Mutex
var groupLogAfterDeleteHooks []GroupLogHook

var groupLogBeforeUpsertMu sync.Mutex
var groupLogBeforeUpsertHooks []GroupLogHook
var groupLogAfterUpsertMu sync.Mutex
var groupLogAfterUpsertHooks []GroupLogHook

// doAfterSelectHooks executes all "after Select" hooks.
func (o *GroupLog) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

	for _, hook := range groupLogAfterSelectHooks {
		if err := hook(ctx, exec, o); err != nil {
			return err
		}
	}

	return nil
}

// doBeforeInsertHooks executes all "before insert" hooks.
func (o *GroupLog) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

	for _, hook := range groupLogBeforeInsertHooks {
		if err := hook(ctx, exec, o); err != nil {
			return err
		}
	}

	return nil
}

// doAfterInsertHooks executes all "after Insert" hooks.
func (o *GroupLog) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

	for _, hook := range groupLogAfterInsertHooks {
		if err := hook(ctx, exec, o); err != nil {
			return err
		}
	}

	return nil
}

// doBeforeUpdateHooks executes all "before Update" hooks.
func (o *GroupLog) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

	for _, hook := range groupLogBeforeUpdateHooks {
		if err := hook(ctx, exec, o); err != nil {
			return err
		}
	}

	return nil
}

// doAfterUpdateHooks executes all "after Update" hooks.
func (o *GroupLog) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

	for _, hook := range groupLogAfterUpdateHooks {
		if err := hook(ctx, exec, o); err != nil {
			return err
		}
	}

	return nil
}

// doBeforeDeleteHooks executes all "before Delete" hooks.
func (o *GroupLog) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

	for _, hook := range groupLogBeforeDeleteHooks {
		if err := hook(ctx, exec, o); err != nil {
			return err
		}
	}

	return nil
}

// doAfterDeleteHooks executes all "after Delete" hooks.
func (o *GroupLog) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

	for _, hook := range groupLogAfterDeleteHooks {
		if err := hook(ctx, exec, o); err != nil {
			return err
		}
	}

	return nil
}

// doBeforeUpsertHooks executes all "before Upsert" hooks.
func (o *GroupLog) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

	for _, hook := range groupLogBeforeUpsertHooks {
		if err := hook(ctx, exec, o); err != nil {
			return err
		}
	}

	return nil
}

// doAfterUpsertHooks executes all "after Upsert" hooks.
func (o *GroupLog) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

	for _, hook := range groupLogAfterUpsertHooks {
		if err := hook(ctx, exec, o); err != nil {
			return err
		}
	}

	return nil
}

// AddGroupLogHook registers your hook function for all future operations.
func AddGroupLogHook(hookPoint boil.HookPoint, groupLogHook GroupLogHook) {
	switch hookPoint {
	case boil.AfterSelectHook:
		groupLogAfterSelectMu.Lock()
		groupLogAfterSelectHooks = append(groupLogAfterSelectHooks, groupLogHook)
		groupLogAfterSelectMu.Unlock()
	case boil.BeforeInsertHook:
		groupLogBeforeInsertMu.Lock()
		groupLogBeforeInsertHooks = append(groupLogBeforeInsertHooks, groupLogHook)
		groupLogBeforeInsertMu.Unlock()
	case boil.AfterInsertHook:
		groupLogAfterInsertMu.Lock()
		groupLogAfterInsertHooks = append(groupLogAfterInsertHooks, groupLogHook)
		groupLogAfterInsertMu.Unlock()
	case boil.BeforeUpdateHook:
		groupLogBeforeUpdateMu.Lock()
		groupLogBeforeUpdateHooks = append(groupLogBeforeUpdateHooks, groupLogHook)
		groupLogBeforeUpdateMu.Unlock()
	case boil.AfterUpdateHook:
		groupLogAfterUpdateMu.Lock()
		groupLogAfterUpdateHooks = append(groupLogAfterUpdateHooks, groupLogHook)
		groupLogAfterUpdateMu.Unlock()
	case boil.BeforeDeleteHook:
		groupLogBeforeDeleteMu.Lock()
		groupLogBeforeDeleteHooks = append(groupLogBeforeDeleteHooks, groupLogHook)
		groupLogBeforeDeleteMu.Unlock()
	case boil.AfterDeleteHook:
		groupLogAfterDeleteMu.Lock()
		groupLogAfterDeleteHooks = append(groupLogAfterDeleteHooks, groupLogHook)
		groupLogAfterDeleteMu.Unlock()
	case boil.BeforeUpsertHook:
		groupLogBeforeUpsertMu.Lock()
		groupLogBeforeUpsertHooks = append(groupLogBeforeUpsertHooks, groupLogHook)
		groupLogBeforeUpsertMu.Unlock()
	case boil.AfterUpsertHook:
		groupLogAfterUpsertMu.Lock()
		groupLogAfterUpsertHooks = append(groupLogAfterUpsertHooks, groupLogHook)
		groupLogAfterUpsertMu.Unlock()
	}
}

// One returns a single groupLog record from the query.
func (q groupLogQuery) One(ctx context.Context, exec boil.ContextExecutor) (*GroupLog, error) {
	o := &GroupLog{}

	queries.SetLimit(q.Query, 1)

	err := q.Bind(ctx, exec, o)
	if err != nil {
		if errors.Is(err, sql.ErrNoRows) {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "models: failed to execute a one query for group_logs")
	}

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

	return o, nil
}

// All returns all GroupLog records from the query.
func (q groupLogQuery) All(ctx context.Context, exec boil.ContextExecutor) (GroupLogSlice, error) {
	var o []*GroupLog

	err := q.Bind(ctx, exec, &o)
	if err != nil {
		return nil, errors.Wrap(err, "models: failed to assign all query results to GroupLog slice")
	}

	if len(groupLogAfterSelectHooks) != 0 {
		for _, obj := range o {
			if err := obj.doAfterSelectHooks(ctx, exec); err != nil {
				return o, err
			}
		}
	}

	return o, nil
}

// Count returns the count of all GroupLog records in the query.
func (q groupLogQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
	var count int64

	queries.SetSelect(q.Query, nil)
	queries.SetCount(q.Query)

	err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
	if err != nil {
		return 0, errors.Wrap(err, "models: failed to count group_logs rows")
	}

	return count, nil
}

// Exists checks if the row exists in the table.
func (q groupLogQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
	var count int64

	queries.SetSelect(q.Query, nil)
	queries.SetCount(q.Query)
	queries.SetLimit(q.Query, 1)

	err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
	if err != nil {
		return false, errors.Wrap(err, "models: failed to check if group_logs exists")
	}

	return count > 0, nil
}

// GroupLogs retrieves all the records using an executor.
func GroupLogs(mods ...qm.QueryMod) groupLogQuery {
	mods = append(mods, qm.From("\"group_logs\""))
	q := NewQuery(mods...)
	if len(queries.GetSelect(q)) == 0 {
		queries.SetSelect(q, []string{"\"group_logs\".*"})
	}

	return groupLogQuery{q}
}

// FindGroupLog retrieves a single record by ID with an executor.
// If selectCols is empty Find will return all columns.
func FindGroupLog(ctx context.Context, exec boil.ContextExecutor, logID int32, selectCols ...string) (*GroupLog, error) {
	groupLogObj := &GroupLog{}

	sel := "*"
	if len(selectCols) > 0 {
		sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
	}
	query := fmt.Sprintf(
		"select %s from \"group_logs\" where \"log_id\"=$1", sel,
	)

	q := queries.Raw(query, logID)

	err := q.Bind(ctx, exec, groupLogObj)
	if err != nil {
		if errors.Is(err, sql.ErrNoRows) {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "models: unable to select from group_logs")
	}

	if err = groupLogObj.doAfterSelectHooks(ctx, exec); err != nil {
		return groupLogObj, err
	}

	return groupLogObj, nil
}

// Insert a single record using an executor.
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
func (o *GroupLog) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
	if o == nil {
		return errors.New("models: no group_logs provided for insertion")
	}

	var err error
	if !boil.TimestampsAreSkipped(ctx) {
		currTime := time.Now().In(boil.GetLocation())

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

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

	nzDefaults := queries.NonZeroDefaultSet(groupLogColumnsWithDefault, o)

	key := makeCacheKey(columns, nzDefaults)
	groupLogInsertCacheMut.RLock()
	cache, cached := groupLogInsertCache[key]
	groupLogInsertCacheMut.RUnlock()

	if !cached {
		wl, returnColumns := columns.InsertColumnSet(
			groupLogAllColumns,
			groupLogColumnsWithDefault,
			groupLogColumnsWithoutDefault,
			nzDefaults,
		)

		cache.valueMapping, err = queries.BindMapping(groupLogType, groupLogMapping, wl)
		if err != nil {
			return err
		}
		cache.retMapping, err = queries.BindMapping(groupLogType, groupLogMapping, returnColumns)
		if err != nil {
			return err
		}
		if len(wl) != 0 {
			cache.query = fmt.Sprintf("INSERT INTO \"group_logs\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
		} else {
			cache.query = "INSERT INTO \"group_logs\" %sDEFAULT VALUES%s"
		}

		var queryOutput, queryReturning string

		if len(cache.retMapping) != 0 {
			queryReturning = fmt.Sprintf(" RETURNING \"%s\"", strings.Join(returnColumns, "\",\""))
		}

		cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
	}

	value := reflect.Indirect(reflect.ValueOf(o))
	vals := queries.ValuesFromMapping(value, cache.valueMapping)

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, cache.query)
		fmt.Fprintln(writer, vals)
	}

	if len(cache.retMapping) != 0 {
		err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
	} else {
		_, err = exec.ExecContext(ctx, cache.query, vals...)
	}

	if err != nil {
		return errors.Wrap(err, "models: unable to insert into group_logs")
	}

	if !cached {
		groupLogInsertCacheMut.Lock()
		groupLogInsertCache[key] = cache
		groupLogInsertCacheMut.Unlock()
	}

	return o.doAfterInsertHooks(ctx, exec)
}

// Update uses an executor to update the GroupLog.
// See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates.
// Update does not automatically update the record in case of default values. Use .Reload() to refresh the records.
func (o *GroupLog) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
	if !boil.TimestampsAreSkipped(ctx) {
		currTime := time.Now().In(boil.GetLocation())

		o.UpdatedAt = currTime
	}

	var err error
	if err = o.doBeforeUpdateHooks(ctx, exec); err != nil {
		return 0, err
	}
	key := makeCacheKey(columns, nil)
	groupLogUpdateCacheMut.RLock()
	cache, cached := groupLogUpdateCache[key]
	groupLogUpdateCacheMut.RUnlock()

	if !cached {
		wl := columns.UpdateColumnSet(
			groupLogAllColumns,
			groupLogPrimaryKeyColumns,
		)

		if !columns.IsWhitelist() {
			wl = strmangle.SetComplement(wl, []string{"created_at"})
		}
		if len(wl) == 0 {
			return 0, errors.New("models: unable to update group_logs, could not build whitelist")
		}

		cache.query = fmt.Sprintf("UPDATE \"group_logs\" SET %s WHERE %s",
			strmangle.SetParamNames("\"", "\"", 1, wl),
			strmangle.WhereClause("\"", "\"", len(wl)+1, groupLogPrimaryKeyColumns),
		)
		cache.valueMapping, err = queries.BindMapping(groupLogType, groupLogMapping, append(wl, groupLogPrimaryKeyColumns...))
		if err != nil {
			return 0, err
		}
	}

	values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, cache.query)
		fmt.Fprintln(writer, values)
	}
	var result sql.Result
	result, err = exec.ExecContext(ctx, cache.query, values...)
	if err != nil {
		return 0, errors.Wrap(err, "models: unable to update group_logs row")
	}

	rowsAff, err := result.RowsAffected()
	if err != nil {
		return 0, errors.Wrap(err, "models: failed to get rows affected by update for group_logs")
	}

	if !cached {
		groupLogUpdateCacheMut.Lock()
		groupLogUpdateCache[key] = cache
		groupLogUpdateCacheMut.Unlock()
	}

	return rowsAff, o.doAfterUpdateHooks(ctx, exec)
}

// UpdateAll updates all rows with the specified column values.
func (q groupLogQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
	queries.SetUpdate(q.Query, cols)

	result, err := q.Query.ExecContext(ctx, exec)
	if err != nil {
		return 0, errors.Wrap(err, "models: unable to update all for group_logs")
	}

	rowsAff, err := result.RowsAffected()
	if err != nil {
		return 0, errors.Wrap(err, "models: unable to retrieve rows affected for group_logs")
	}

	return rowsAff, nil
}

// UpdateAll updates all rows with the specified column values, using an executor.
func (o GroupLogSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
	ln := int64(len(o))
	if ln == 0 {
		return 0, nil
	}

	if len(cols) == 0 {
		return 0, errors.New("models: update all requires at least one column argument")
	}

	colNames := make([]string, len(cols))
	args := make([]interface{}, len(cols))

	i := 0
	for name, value := range cols {
		colNames[i] = name
		args[i] = value
		i++
	}

	// Append all of the primary key values for each column
	for _, obj := range o {
		pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), groupLogPrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}

	sql := fmt.Sprintf("UPDATE \"group_logs\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 1, colNames),
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, groupLogPrimaryKeyColumns, len(o)))

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, sql)
		fmt.Fprintln(writer, args...)
	}
	result, err := exec.ExecContext(ctx, sql, args...)
	if err != nil {
		return 0, errors.Wrap(err, "models: unable to update all in groupLog slice")
	}

	rowsAff, err := result.RowsAffected()
	if err != nil {
		return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all groupLog")
	}
	return rowsAff, nil
}

// 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 *GroupLog) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error {
	if o == nil {
		return errors.New("models: no group_logs provided for upsert")
	}
	if !boil.TimestampsAreSkipped(ctx) {
		currTime := time.Now().In(boil.GetLocation())

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

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

	nzDefaults := queries.NonZeroDefaultSet(groupLogColumnsWithDefault, 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)

	groupLogUpsertCacheMut.RLock()
	cache, cached := groupLogUpsertCache[key]
	groupLogUpsertCacheMut.RUnlock()

	var err error

	if !cached {
		insert, _ := insertColumns.InsertColumnSet(
			groupLogAllColumns,
			groupLogColumnsWithDefault,
			groupLogColumnsWithoutDefault,
			nzDefaults,
		)

		update := updateColumns.UpdateColumnSet(
			groupLogAllColumns,
			groupLogPrimaryKeyColumns,
		)

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

		ret := strmangle.SetComplement(groupLogAllColumns, strmangle.SetIntersect(insert, update))

		conflict := conflictColumns
		if len(conflict) == 0 && updateOnConflict && len(update) != 0 {
			if len(groupLogPrimaryKeyColumns) == 0 {
				return errors.New("models: unable to upsert group_logs, could not build conflict column list")
			}

			conflict = make([]string, len(groupLogPrimaryKeyColumns))
			copy(conflict, groupLogPrimaryKeyColumns)
		}
		cache.query = buildUpsertQueryPostgres(dialect, "\"group_logs\"", updateOnConflict, ret, update, conflict, insert, opts...)

		cache.valueMapping, err = queries.BindMapping(groupLogType, groupLogMapping, insert)
		if err != nil {
			return err
		}
		if len(ret) != 0 {
			cache.retMapping, err = queries.BindMapping(groupLogType, groupLogMapping, 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.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, cache.query)
		fmt.Fprintln(writer, vals)
	}
	if len(cache.retMapping) != 0 {
		err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...)
		if errors.Is(err, sql.ErrNoRows) {
			err = nil // Postgres 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 group_logs")
	}

	if !cached {
		groupLogUpsertCacheMut.Lock()
		groupLogUpsertCache[key] = cache
		groupLogUpsertCacheMut.Unlock()
	}

	return o.doAfterUpsertHooks(ctx, exec)
}

// Delete deletes a single GroupLog record with an executor.
// Delete will match against the primary key column to find the record to delete.
func (o *GroupLog) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
	if o == nil {
		return 0, errors.New("models: no GroupLog provided for delete")
	}

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

	args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), groupLogPrimaryKeyMapping)
	sql := "DELETE FROM \"group_logs\" WHERE \"log_id\"=$1"

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, sql)
		fmt.Fprintln(writer, args...)
	}
	result, err := exec.ExecContext(ctx, sql, args...)
	if err != nil {
		return 0, errors.Wrap(err, "models: unable to delete from group_logs")
	}

	rowsAff, err := result.RowsAffected()
	if err != nil {
		return 0, errors.Wrap(err, "models: failed to get rows affected by delete for group_logs")
	}

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

	return rowsAff, nil
}

// DeleteAll deletes all matching rows.
func (q groupLogQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
	if q.Query == nil {
		return 0, errors.New("models: no groupLogQuery provided for delete all")
	}

	queries.SetDelete(q.Query)

	result, err := q.Query.ExecContext(ctx, exec)
	if err != nil {
		return 0, errors.Wrap(err, "models: unable to delete all from group_logs")
	}

	rowsAff, err := result.RowsAffected()
	if err != nil {
		return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for group_logs")
	}

	return rowsAff, nil
}

// DeleteAll deletes all rows in the slice, using an executor.
func (o GroupLogSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
	if len(o) == 0 {
		return 0, nil
	}

	if len(groupLogBeforeDeleteHooks) != 0 {
		for _, obj := range o {
			if err := obj.doBeforeDeleteHooks(ctx, exec); err != nil {
				return 0, err
			}
		}
	}

	var args []interface{}
	for _, obj := range o {
		pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), groupLogPrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}

	sql := "DELETE FROM \"group_logs\" WHERE " +
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, groupLogPrimaryKeyColumns, len(o))

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, sql)
		fmt.Fprintln(writer, args)
	}
	result, err := exec.ExecContext(ctx, sql, args...)
	if err != nil {
		return 0, errors.Wrap(err, "models: unable to delete all from groupLog slice")
	}

	rowsAff, err := result.RowsAffected()
	if err != nil {
		return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for group_logs")
	}

	if len(groupLogAfterDeleteHooks) != 0 {
		for _, obj := range o {
			if err := obj.doAfterDeleteHooks(ctx, exec); err != nil {
				return 0, err
			}
		}
	}

	return rowsAff, nil
}

// Reload refetches the object from the database
// using the primary keys with an executor.
func (o *GroupLog) Reload(ctx context.Context, exec boil.ContextExecutor) error {
	ret, err := FindGroupLog(ctx, exec, o.LogID)
	if err != nil {
		return err
	}

	*o = *ret
	return nil
}

// ReloadAll refetches every row with matching primary key column values
// and overwrites the original object slice with the newly updated slice.
func (o *GroupLogSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
	if o == nil || len(*o) == 0 {
		return nil
	}

	slice := GroupLogSlice{}
	var args []interface{}
	for _, obj := range *o {
		pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), groupLogPrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}

	sql := "SELECT \"group_logs\".* FROM \"group_logs\" WHERE " +
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, groupLogPrimaryKeyColumns, len(*o))

	q := queries.Raw(sql, args...)

	err := q.Bind(ctx, exec, &slice)
	if err != nil {
		return errors.Wrap(err, "models: unable to reload all in GroupLogSlice")
	}

	*o = slice

	return nil
}

// GroupLogExists checks if the GroupLog row exists.
func GroupLogExists(ctx context.Context, exec boil.ContextExecutor, logID int32) (bool, error) {
	var exists bool
	sql := "select exists(select 1 from \"group_logs\" where \"log_id\"=$1 limit 1)"

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, sql)
		fmt.Fprintln(writer, logID)
	}
	row := exec.QueryRowContext(ctx, sql, logID)

	err := row.Scan(&exists)
	if err != nil {
		return false, errors.Wrap(err, "models: unable to check if group_logs exists")
	}

	return exists, nil
}

// Exists checks if the GroupLog row exists.
func (o *GroupLog) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
	return GroupLogExists(ctx, exec, o.LogID)
}
