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

// GroupsPage is an object representing the database table.
type GroupsPage struct {
	PageID            int32     `boil:"page_id" json:"page_id" toml:"page_id" yaml:"page_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"`
	Groups            string    `boil:"groups" json:"groups" toml:"groups" yaml:"groups"`
	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 *groupsPageR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L groupsPageL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}

var GroupsPageColumns = struct {
	PageID            string
	UserName          string
	PreferredUserName string
	Groups            string
	CreatedAt         string
	UpdatedAt         string
	DeletedAt         string
}{
	PageID:            "page_id",
	UserName:          "user_name",
	PreferredUserName: "preferred_user_name",
	Groups:            "groups",
	CreatedAt:         "created_at",
	UpdatedAt:         "updated_at",
	DeletedAt:         "deleted_at",
}

var GroupsPageTableColumns = struct {
	PageID            string
	UserName          string
	PreferredUserName string
	Groups            string
	CreatedAt         string
	UpdatedAt         string
	DeletedAt         string
}{
	PageID:            "groups_page.page_id",
	UserName:          "groups_page.user_name",
	PreferredUserName: "groups_page.preferred_user_name",
	Groups:            "groups_page.groups",
	CreatedAt:         "groups_page.created_at",
	UpdatedAt:         "groups_page.updated_at",
	DeletedAt:         "groups_page.deleted_at",
}

// Generated where

var GroupsPageWhere = struct {
	PageID            whereHelperint32
	UserName          whereHelperstring
	PreferredUserName whereHelperstring
	Groups            whereHelperstring
	CreatedAt         whereHelpertime_Time
	UpdatedAt         whereHelpertime_Time
	DeletedAt         whereHelpernull_Time
}{
	PageID:            whereHelperint32{field: "\"groups_page\".\"page_id\""},
	UserName:          whereHelperstring{field: "\"groups_page\".\"user_name\""},
	PreferredUserName: whereHelperstring{field: "\"groups_page\".\"preferred_user_name\""},
	Groups:            whereHelperstring{field: "\"groups_page\".\"groups\""},
	CreatedAt:         whereHelpertime_Time{field: "\"groups_page\".\"created_at\""},
	UpdatedAt:         whereHelpertime_Time{field: "\"groups_page\".\"updated_at\""},
	DeletedAt:         whereHelpernull_Time{field: "\"groups_page\".\"deleted_at\""},
}

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

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

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

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

var (
	groupsPageAllColumns            = []string{"page_id", "user_name", "preferred_user_name", "groups", "created_at", "updated_at", "deleted_at"}
	groupsPageColumnsWithoutDefault = []string{}
	groupsPageColumnsWithDefault    = []string{"page_id", "user_name", "preferred_user_name", "groups", "created_at", "updated_at", "deleted_at"}
	groupsPagePrimaryKeyColumns     = []string{"page_id"}
	groupsPageGeneratedColumns      = []string{}
)

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

	groupsPageQuery struct {
		*queries.Query
	}
)

// Cache for insert, update and upsert
var (
	groupsPageType                 = reflect.TypeOf(&GroupsPage{})
	groupsPageMapping              = queries.MakeStructMapping(groupsPageType)
	groupsPagePrimaryKeyMapping, _ = queries.BindMapping(groupsPageType, groupsPageMapping, groupsPagePrimaryKeyColumns)
	groupsPageInsertCacheMut       sync.RWMutex
	groupsPageInsertCache          = make(map[string]insertCache)
	groupsPageUpdateCacheMut       sync.RWMutex
	groupsPageUpdateCache          = make(map[string]updateCache)
	groupsPageUpsertCacheMut       sync.RWMutex
	groupsPageUpsertCache          = 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 groupsPageAfterSelectMu sync.Mutex
var groupsPageAfterSelectHooks []GroupsPageHook

var groupsPageBeforeInsertMu sync.Mutex
var groupsPageBeforeInsertHooks []GroupsPageHook
var groupsPageAfterInsertMu sync.Mutex
var groupsPageAfterInsertHooks []GroupsPageHook

var groupsPageBeforeUpdateMu sync.Mutex
var groupsPageBeforeUpdateHooks []GroupsPageHook
var groupsPageAfterUpdateMu sync.Mutex
var groupsPageAfterUpdateHooks []GroupsPageHook

var groupsPageBeforeDeleteMu sync.Mutex
var groupsPageBeforeDeleteHooks []GroupsPageHook
var groupsPageAfterDeleteMu sync.Mutex
var groupsPageAfterDeleteHooks []GroupsPageHook

var groupsPageBeforeUpsertMu sync.Mutex
var groupsPageBeforeUpsertHooks []GroupsPageHook
var groupsPageAfterUpsertMu sync.Mutex
var groupsPageAfterUpsertHooks []GroupsPageHook

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

// AddGroupsPageHook registers your hook function for all future operations.
func AddGroupsPageHook(hookPoint boil.HookPoint, groupsPageHook GroupsPageHook) {
	switch hookPoint {
	case boil.AfterSelectHook:
		groupsPageAfterSelectMu.Lock()
		groupsPageAfterSelectHooks = append(groupsPageAfterSelectHooks, groupsPageHook)
		groupsPageAfterSelectMu.Unlock()
	case boil.BeforeInsertHook:
		groupsPageBeforeInsertMu.Lock()
		groupsPageBeforeInsertHooks = append(groupsPageBeforeInsertHooks, groupsPageHook)
		groupsPageBeforeInsertMu.Unlock()
	case boil.AfterInsertHook:
		groupsPageAfterInsertMu.Lock()
		groupsPageAfterInsertHooks = append(groupsPageAfterInsertHooks, groupsPageHook)
		groupsPageAfterInsertMu.Unlock()
	case boil.BeforeUpdateHook:
		groupsPageBeforeUpdateMu.Lock()
		groupsPageBeforeUpdateHooks = append(groupsPageBeforeUpdateHooks, groupsPageHook)
		groupsPageBeforeUpdateMu.Unlock()
	case boil.AfterUpdateHook:
		groupsPageAfterUpdateMu.Lock()
		groupsPageAfterUpdateHooks = append(groupsPageAfterUpdateHooks, groupsPageHook)
		groupsPageAfterUpdateMu.Unlock()
	case boil.BeforeDeleteHook:
		groupsPageBeforeDeleteMu.Lock()
		groupsPageBeforeDeleteHooks = append(groupsPageBeforeDeleteHooks, groupsPageHook)
		groupsPageBeforeDeleteMu.Unlock()
	case boil.AfterDeleteHook:
		groupsPageAfterDeleteMu.Lock()
		groupsPageAfterDeleteHooks = append(groupsPageAfterDeleteHooks, groupsPageHook)
		groupsPageAfterDeleteMu.Unlock()
	case boil.BeforeUpsertHook:
		groupsPageBeforeUpsertMu.Lock()
		groupsPageBeforeUpsertHooks = append(groupsPageBeforeUpsertHooks, groupsPageHook)
		groupsPageBeforeUpsertMu.Unlock()
	case boil.AfterUpsertHook:
		groupsPageAfterUpsertMu.Lock()
		groupsPageAfterUpsertHooks = append(groupsPageAfterUpsertHooks, groupsPageHook)
		groupsPageAfterUpsertMu.Unlock()
	}
}

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

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

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

	return o, nil
}

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

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

	if len(groupsPageAfterSelectHooks) != 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 GroupsPage records in the query.
func (q groupsPageQuery) 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 groups_page rows")
	}

	return count, nil
}

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

	return count > 0, nil
}

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

	return groupsPageQuery{q}
}

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

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

	q := queries.Raw(query, pageID)

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

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

	return groupsPageObj, nil
}

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

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

	if !cached {
		wl, returnColumns := columns.InsertColumnSet(
			groupsPageAllColumns,
			groupsPageColumnsWithDefault,
			groupsPageColumnsWithoutDefault,
			nzDefaults,
		)

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

	if !cached {
		groupsPageInsertCacheMut.Lock()
		groupsPageInsertCache[key] = cache
		groupsPageInsertCacheMut.Unlock()
	}

	return o.doAfterInsertHooks(ctx, exec)
}

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

	if !cached {
		wl := columns.UpdateColumnSet(
			groupsPageAllColumns,
			groupsPagePrimaryKeyColumns,
		)

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

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

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

	if !cached {
		groupsPageUpdateCacheMut.Lock()
		groupsPageUpdateCache[key] = cache
		groupsPageUpdateCacheMut.Unlock()
	}

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

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

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

	return rowsAff, nil
}

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

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

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

	groupsPageUpsertCacheMut.RLock()
	cache, cached := groupsPageUpsertCache[key]
	groupsPageUpsertCacheMut.RUnlock()

	var err error

	if !cached {
		insert, _ := insertColumns.InsertColumnSet(
			groupsPageAllColumns,
			groupsPageColumnsWithDefault,
			groupsPageColumnsWithoutDefault,
			nzDefaults,
		)

		update := updateColumns.UpdateColumnSet(
			groupsPageAllColumns,
			groupsPagePrimaryKeyColumns,
		)

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

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

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

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

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

	if !cached {
		groupsPageUpsertCacheMut.Lock()
		groupsPageUpsertCache[key] = cache
		groupsPageUpsertCacheMut.Unlock()
	}

	return o.doAfterUpsertHooks(ctx, exec)
}

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

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

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

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

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

	return rowsAff, nil
}

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

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

	return rowsAff, nil
}

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

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

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

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

	if len(groupsPageAfterDeleteHooks) != 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 *GroupsPage) Reload(ctx context.Context, exec boil.ContextExecutor) error {
	ret, err := FindGroupsPage(ctx, exec, o.PageID)
	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 *GroupsPageSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
	if o == nil || len(*o) == 0 {
		return nil
	}

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

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

	*o = slice

	return nil
}

// GroupsPageExists checks if the GroupsPage row exists.
func GroupsPageExists(ctx context.Context, exec boil.ContextExecutor, pageID int32) (bool, error) {
	var exists bool
	sql := "select exists(select 1 from \"groups_page\" where \"page_id\"=$1 limit 1)"

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

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

	return exists, nil
}

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