// 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"
)

// RunReport is an object representing the database table.
type RunReport struct {
	ID                int32     `boil:"id" json:"id" toml:"id" yaml:"id"`
	RunID             int32     `boil:"run_id" json:"run_id" toml:"run_id" yaml:"run_id"`
	Link              string    `boil:"link" json:"link" toml:"link" yaml:"link"`
	Status            string    `boil:"status" json:"status" toml:"status" yaml:"status"`
	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"`
	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 *runReportR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L runReportL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}

var RunReportColumns = struct {
	ID                string
	RunID             string
	Link              string
	Status            string
	UserName          string
	PreferredUserName string
	CreatedAt         string
	UpdatedAt         string
	DeletedAt         string
}{
	ID:                "id",
	RunID:             "run_id",
	Link:              "link",
	Status:            "status",
	UserName:          "user_name",
	PreferredUserName: "preferred_user_name",
	CreatedAt:         "created_at",
	UpdatedAt:         "updated_at",
	DeletedAt:         "deleted_at",
}

var RunReportTableColumns = struct {
	ID                string
	RunID             string
	Link              string
	Status            string
	UserName          string
	PreferredUserName string
	CreatedAt         string
	UpdatedAt         string
	DeletedAt         string
}{
	ID:                "run_report.id",
	RunID:             "run_report.run_id",
	Link:              "run_report.link",
	Status:            "run_report.status",
	UserName:          "run_report.user_name",
	PreferredUserName: "run_report.preferred_user_name",
	CreatedAt:         "run_report.created_at",
	UpdatedAt:         "run_report.updated_at",
	DeletedAt:         "run_report.deleted_at",
}

// Generated where

var RunReportWhere = struct {
	ID                whereHelperint32
	RunID             whereHelperint32
	Link              whereHelperstring
	Status            whereHelperstring
	UserName          whereHelperstring
	PreferredUserName whereHelperstring
	CreatedAt         whereHelpertime_Time
	UpdatedAt         whereHelpertime_Time
	DeletedAt         whereHelpernull_Time
}{
	ID:                whereHelperint32{field: "\"run_report\".\"id\""},
	RunID:             whereHelperint32{field: "\"run_report\".\"run_id\""},
	Link:              whereHelperstring{field: "\"run_report\".\"link\""},
	Status:            whereHelperstring{field: "\"run_report\".\"status\""},
	UserName:          whereHelperstring{field: "\"run_report\".\"user_name\""},
	PreferredUserName: whereHelperstring{field: "\"run_report\".\"preferred_user_name\""},
	CreatedAt:         whereHelpertime_Time{field: "\"run_report\".\"created_at\""},
	UpdatedAt:         whereHelpertime_Time{field: "\"run_report\".\"updated_at\""},
	DeletedAt:         whereHelpernull_Time{field: "\"run_report\".\"deleted_at\""},
}

// RunReportRels is where relationship names are stored.
var RunReportRels = struct {
	Run string
}{
	Run: "Run",
}

// runReportR is where relationships are stored.
type runReportR struct {
	Run *Run `boil:"Run" json:"Run" toml:"Run" yaml:"Run"`
}

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

func (o *RunReport) GetRun() *Run {
	if o == nil {
		return nil
	}

	return o.R.GetRun()
}

func (r *runReportR) GetRun() *Run {
	if r == nil {
		return nil
	}

	return r.Run
}

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

var (
	runReportAllColumns            = []string{"id", "run_id", "link", "status", "user_name", "preferred_user_name", "created_at", "updated_at", "deleted_at"}
	runReportColumnsWithoutDefault = []string{"run_id"}
	runReportColumnsWithDefault    = []string{"id", "link", "status", "user_name", "preferred_user_name", "created_at", "updated_at", "deleted_at"}
	runReportPrimaryKeyColumns     = []string{"id"}
	runReportGeneratedColumns      = []string{}
)

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

	runReportQuery struct {
		*queries.Query
	}
)

// Cache for insert, update and upsert
var (
	runReportType                 = reflect.TypeOf(&RunReport{})
	runReportMapping              = queries.MakeStructMapping(runReportType)
	runReportPrimaryKeyMapping, _ = queries.BindMapping(runReportType, runReportMapping, runReportPrimaryKeyColumns)
	runReportInsertCacheMut       sync.RWMutex
	runReportInsertCache          = make(map[string]insertCache)
	runReportUpdateCacheMut       sync.RWMutex
	runReportUpdateCache          = make(map[string]updateCache)
	runReportUpsertCacheMut       sync.RWMutex
	runReportUpsertCache          = 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 runReportAfterSelectMu sync.Mutex
var runReportAfterSelectHooks []RunReportHook

var runReportBeforeInsertMu sync.Mutex
var runReportBeforeInsertHooks []RunReportHook
var runReportAfterInsertMu sync.Mutex
var runReportAfterInsertHooks []RunReportHook

var runReportBeforeUpdateMu sync.Mutex
var runReportBeforeUpdateHooks []RunReportHook
var runReportAfterUpdateMu sync.Mutex
var runReportAfterUpdateHooks []RunReportHook

var runReportBeforeDeleteMu sync.Mutex
var runReportBeforeDeleteHooks []RunReportHook
var runReportAfterDeleteMu sync.Mutex
var runReportAfterDeleteHooks []RunReportHook

var runReportBeforeUpsertMu sync.Mutex
var runReportBeforeUpsertHooks []RunReportHook
var runReportAfterUpsertMu sync.Mutex
var runReportAfterUpsertHooks []RunReportHook

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

// AddRunReportHook registers your hook function for all future operations.
func AddRunReportHook(hookPoint boil.HookPoint, runReportHook RunReportHook) {
	switch hookPoint {
	case boil.AfterSelectHook:
		runReportAfterSelectMu.Lock()
		runReportAfterSelectHooks = append(runReportAfterSelectHooks, runReportHook)
		runReportAfterSelectMu.Unlock()
	case boil.BeforeInsertHook:
		runReportBeforeInsertMu.Lock()
		runReportBeforeInsertHooks = append(runReportBeforeInsertHooks, runReportHook)
		runReportBeforeInsertMu.Unlock()
	case boil.AfterInsertHook:
		runReportAfterInsertMu.Lock()
		runReportAfterInsertHooks = append(runReportAfterInsertHooks, runReportHook)
		runReportAfterInsertMu.Unlock()
	case boil.BeforeUpdateHook:
		runReportBeforeUpdateMu.Lock()
		runReportBeforeUpdateHooks = append(runReportBeforeUpdateHooks, runReportHook)
		runReportBeforeUpdateMu.Unlock()
	case boil.AfterUpdateHook:
		runReportAfterUpdateMu.Lock()
		runReportAfterUpdateHooks = append(runReportAfterUpdateHooks, runReportHook)
		runReportAfterUpdateMu.Unlock()
	case boil.BeforeDeleteHook:
		runReportBeforeDeleteMu.Lock()
		runReportBeforeDeleteHooks = append(runReportBeforeDeleteHooks, runReportHook)
		runReportBeforeDeleteMu.Unlock()
	case boil.AfterDeleteHook:
		runReportAfterDeleteMu.Lock()
		runReportAfterDeleteHooks = append(runReportAfterDeleteHooks, runReportHook)
		runReportAfterDeleteMu.Unlock()
	case boil.BeforeUpsertHook:
		runReportBeforeUpsertMu.Lock()
		runReportBeforeUpsertHooks = append(runReportBeforeUpsertHooks, runReportHook)
		runReportBeforeUpsertMu.Unlock()
	case boil.AfterUpsertHook:
		runReportAfterUpsertMu.Lock()
		runReportAfterUpsertHooks = append(runReportAfterUpsertHooks, runReportHook)
		runReportAfterUpsertMu.Unlock()
	}
}

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

	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 run_report")
	}

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

	return o, nil
}

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

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

	if len(runReportAfterSelectHooks) != 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 RunReport records in the query.
func (q runReportQuery) 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 run_report rows")
	}

	return count, nil
}

// Exists checks if the row exists in the table.
func (q runReportQuery) 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 run_report exists")
	}

	return count > 0, nil
}

// Run pointed to by the foreign key.
func (o *RunReport) Run(mods ...qm.QueryMod) runQuery {
	queryMods := []qm.QueryMod{
		qm.Where("\"run_id\" = ?", o.RunID),
	}

	queryMods = append(queryMods, mods...)

	return Runs(queryMods...)
}

// LoadRun allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (runReportL) LoadRun(ctx context.Context, e boil.ContextExecutor, singular bool, maybeRunReport interface{}, mods queries.Applicator) error {
	var slice []*RunReport
	var object *RunReport

	if singular {
		var ok bool
		object, ok = maybeRunReport.(*RunReport)
		if !ok {
			object = new(RunReport)
			ok = queries.SetFromEmbeddedStruct(&object, &maybeRunReport)
			if !ok {
				return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeRunReport))
			}
		}
	} else {
		s, ok := maybeRunReport.(*[]*RunReport)
		if ok {
			slice = *s
		} else {
			ok = queries.SetFromEmbeddedStruct(&slice, maybeRunReport)
			if !ok {
				return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeRunReport))
			}
		}
	}

	args := make(map[interface{}]struct{})
	if singular {
		if object.R == nil {
			object.R = &runReportR{}
		}
		args[object.RunID] = struct{}{}

	} else {
		for _, obj := range slice {
			if obj.R == nil {
				obj.R = &runReportR{}
			}

			args[obj.RunID] = struct{}{}

		}
	}

	if len(args) == 0 {
		return nil
	}

	argsSlice := make([]interface{}, len(args))
	i := 0
	for arg := range args {
		argsSlice[i] = arg
		i++
	}

	query := NewQuery(
		qm.From(`runs`),
		qm.WhereIn(`runs.run_id in ?`, argsSlice...),
	)
	if mods != nil {
		mods.Apply(query)
	}

	results, err := query.QueryContext(ctx, e)
	if err != nil {
		return errors.Wrap(err, "failed to eager load Run")
	}

	var resultSlice []*Run
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice Run")
	}

	if err = results.Close(); err != nil {
		return errors.Wrap(err, "failed to close results of eager load for runs")
	}
	if err = results.Err(); err != nil {
		return errors.Wrap(err, "error occurred during iteration of eager loaded relations for runs")
	}

	if len(runAfterSelectHooks) != 0 {
		for _, obj := range resultSlice {
			if err := obj.doAfterSelectHooks(ctx, e); err != nil {
				return err
			}
		}
	}

	if len(resultSlice) == 0 {
		return nil
	}

	if singular {
		foreign := resultSlice[0]
		object.R.Run = foreign
		if foreign.R == nil {
			foreign.R = &runR{}
		}
		foreign.R.RunReports = append(foreign.R.RunReports, object)
		return nil
	}

	for _, local := range slice {
		for _, foreign := range resultSlice {
			if local.RunID == foreign.RunID {
				local.R.Run = foreign
				if foreign.R == nil {
					foreign.R = &runR{}
				}
				foreign.R.RunReports = append(foreign.R.RunReports, local)
				break
			}
		}
	}

	return nil
}

// SetRun of the runReport to the related item.
// Sets o.R.Run to related.
// Adds o to related.R.RunReports.
func (o *RunReport) SetRun(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Run) error {
	var err error
	if insert {
		if err = related.Insert(ctx, exec, boil.Infer()); err != nil {
			return errors.Wrap(err, "failed to insert into foreign table")
		}
	}

	updateQuery := fmt.Sprintf(
		"UPDATE \"run_report\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 1, []string{"run_id"}),
		strmangle.WhereClause("\"", "\"", 2, runReportPrimaryKeyColumns),
	)
	values := []interface{}{related.RunID, o.ID}

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, updateQuery)
		fmt.Fprintln(writer, values)
	}
	if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
		return errors.Wrap(err, "failed to update local table")
	}

	o.RunID = related.RunID
	if o.R == nil {
		o.R = &runReportR{
			Run: related,
		}
	} else {
		o.R.Run = related
	}

	if related.R == nil {
		related.R = &runR{
			RunReports: RunReportSlice{o},
		}
	} else {
		related.R.RunReports = append(related.R.RunReports, o)
	}

	return nil
}

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

	return runReportQuery{q}
}

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

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

	q := queries.Raw(query, iD)

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

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

	return runReportObj, nil
}

// Insert a single record using an executor.
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
func (o *RunReport) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
	if o == nil {
		return errors.New("models: no run_report 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(runReportColumnsWithDefault, o)

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

	if !cached {
		wl, returnColumns := columns.InsertColumnSet(
			runReportAllColumns,
			runReportColumnsWithDefault,
			runReportColumnsWithoutDefault,
			nzDefaults,
		)

		cache.valueMapping, err = queries.BindMapping(runReportType, runReportMapping, wl)
		if err != nil {
			return err
		}
		cache.retMapping, err = queries.BindMapping(runReportType, runReportMapping, returnColumns)
		if err != nil {
			return err
		}
		if len(wl) != 0 {
			cache.query = fmt.Sprintf("INSERT INTO \"run_report\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
		} else {
			cache.query = "INSERT INTO \"run_report\" %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 run_report")
	}

	if !cached {
		runReportInsertCacheMut.Lock()
		runReportInsertCache[key] = cache
		runReportInsertCacheMut.Unlock()
	}

	return o.doAfterInsertHooks(ctx, exec)
}

// Update uses an executor to update the RunReport.
// 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 *RunReport) 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)
	runReportUpdateCacheMut.RLock()
	cache, cached := runReportUpdateCache[key]
	runReportUpdateCacheMut.RUnlock()

	if !cached {
		wl := columns.UpdateColumnSet(
			runReportAllColumns,
			runReportPrimaryKeyColumns,
		)

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

		cache.query = fmt.Sprintf("UPDATE \"run_report\" SET %s WHERE %s",
			strmangle.SetParamNames("\"", "\"", 1, wl),
			strmangle.WhereClause("\"", "\"", len(wl)+1, runReportPrimaryKeyColumns),
		)
		cache.valueMapping, err = queries.BindMapping(runReportType, runReportMapping, append(wl, runReportPrimaryKeyColumns...))
		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 run_report row")
	}

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

	if !cached {
		runReportUpdateCacheMut.Lock()
		runReportUpdateCache[key] = cache
		runReportUpdateCacheMut.Unlock()
	}

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

// UpdateAll updates all rows with the specified column values.
func (q runReportQuery) 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 run_report")
	}

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

	return rowsAff, nil
}

// UpdateAll updates all rows with the specified column values, using an executor.
func (o RunReportSlice) 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)), runReportPrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}

	sql := fmt.Sprintf("UPDATE \"run_report\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 1, colNames),
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, runReportPrimaryKeyColumns, 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 runReport slice")
	}

	rowsAff, err := result.RowsAffected()
	if err != nil {
		return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all runReport")
	}
	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 *RunReport) 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 run_report 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(runReportColumnsWithDefault, 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)

	runReportUpsertCacheMut.RLock()
	cache, cached := runReportUpsertCache[key]
	runReportUpsertCacheMut.RUnlock()

	var err error

	if !cached {
		insert, _ := insertColumns.InsertColumnSet(
			runReportAllColumns,
			runReportColumnsWithDefault,
			runReportColumnsWithoutDefault,
			nzDefaults,
		)

		update := updateColumns.UpdateColumnSet(
			runReportAllColumns,
			runReportPrimaryKeyColumns,
		)

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

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

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

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

		cache.valueMapping, err = queries.BindMapping(runReportType, runReportMapping, insert)
		if err != nil {
			return err
		}
		if len(ret) != 0 {
			cache.retMapping, err = queries.BindMapping(runReportType, runReportMapping, 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 run_report")
	}

	if !cached {
		runReportUpsertCacheMut.Lock()
		runReportUpsertCache[key] = cache
		runReportUpsertCacheMut.Unlock()
	}

	return o.doAfterUpsertHooks(ctx, exec)
}

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

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

	args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), runReportPrimaryKeyMapping)
	sql := "DELETE FROM \"run_report\" WHERE \"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 run_report")
	}

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

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

	return rowsAff, nil
}

// DeleteAll deletes all matching rows.
func (q runReportQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
	if q.Query == nil {
		return 0, errors.New("models: no runReportQuery 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 run_report")
	}

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

	return rowsAff, nil
}

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

	if len(runReportBeforeDeleteHooks) != 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)), runReportPrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}

	sql := "DELETE FROM \"run_report\" WHERE " +
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, runReportPrimaryKeyColumns, 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 runReport slice")
	}

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

	if len(runReportAfterDeleteHooks) != 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 *RunReport) Reload(ctx context.Context, exec boil.ContextExecutor) error {
	ret, err := FindRunReport(ctx, exec, o.ID)
	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 *RunReportSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
	if o == nil || len(*o) == 0 {
		return nil
	}

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

	sql := "SELECT \"run_report\".* FROM \"run_report\" WHERE " +
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, runReportPrimaryKeyColumns, 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 RunReportSlice")
	}

	*o = slice

	return nil
}

// RunReportExists checks if the RunReport row exists.
func RunReportExists(ctx context.Context, exec boil.ContextExecutor, iD int32) (bool, error) {
	var exists bool
	sql := "select exists(select 1 from \"run_report\" where \"id\"=$1 limit 1)"

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

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

	return exists, nil
}

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