package models

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

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

type SapMaintenanceTaskListOperationMaterialDatum struct {
	TaskListType                   string      `boil:"TaskListType" json:"TaskListType" toml:"TaskListType" yaml:"TaskListType"`
	TaskListGroup                  string      `boil:"TaskListGroup" json:"TaskListGroup" toml:"TaskListGroup" yaml:"TaskListGroup"`
	TaskListGroupCounter           string      `boil:"TaskListGroupCounter" json:"TaskListGroupCounter" toml:"TaskListGroupCounter" yaml:"TaskListGroupCounter"`
	TaskListSequence               string      `boil:"TaskListSequence" json:"TaskListSequence" toml:"TaskListSequence" yaml:"TaskListSequence"`
	TaskListOperationInternalID    string      `boil:"TaskListOperationInternalID" json:"TaskListOperationInternalID" toml:"TaskListOperationInternalID" yaml:"TaskListOperationInternalID"`
	TaskListOpBOMItmIntVersCounter string      `boil:"TaskListOpBOMItmIntVersCounter" json:"TaskListOpBOMItmIntVersCounter" toml:"TaskListOpBOMItmIntVersCounter" yaml:"TaskListOpBOMItmIntVersCounter"`
	TaskListOpBOMItmInternalID     string      `boil:"TaskListOpBOMItmInternalID" json:"TaskListOpBOMItmInternalID" toml:"TaskListOpBOMItmInternalID" yaml:"TaskListOpBOMItmInternalID"`
	Material                       null.String `boil:"Material" json:"Material,omitempty" toml:"Material" yaml:"Material,omitempty"`
	MaterialName                   null.String `boil:"MaterialName" json:"MaterialName,omitempty" toml:"MaterialName" yaml:"MaterialName,omitempty"`
	BillOfMaterialItemQuantity     null.String `boil:"BillOfMaterialItemQuantity" json:"BillOfMaterialItemQuantity,omitempty" toml:"BillOfMaterialItemQuantity" yaml:"BillOfMaterialItemQuantity,omitempty"`
	BillOfMaterialItemCategory     null.String `boil:"BillOfMaterialItemCategory" json:"BillOfMaterialItemCategory,omitempty" toml:"BillOfMaterialItemCategory" yaml:"BillOfMaterialItemCategory,omitempty"`
	BillOfMaterialItemUnit         null.String `boil:"BillOfMaterialItemUnit" json:"BillOfMaterialItemUnit,omitempty" toml:"BillOfMaterialItemUnit" yaml:"BillOfMaterialItemUnit,omitempty"`
	ResvnIsMRPRlvtOrPurReqnIsCrted null.String `boil:"ResvnIsMRPRlvtOrPurReqnIsCrted" json:"ResvnIsMRPRlvtOrPurReqnIsCrted,omitempty" toml:"ResvnIsMRPRlvtOrPurReqnIsCrted" yaml:"ResvnIsMRPRlvtOrPurReqnIsCrted,omitempty"`
	MatlCompIsMarkedForBackflush   null.Bool   `boil:"MatlCompIsMarkedForBackflush" json:"MatlCompIsMarkedForBackflush,omitempty" toml:"MatlCompIsMarkedForBackflush" yaml:"MatlCompIsMarkedForBackflush,omitempty"`
	SafetyRelevantObject           null.String `boil:"SafetyRelevantObject" json:"SafetyRelevantObject,omitempty" toml:"SafetyRelevantObject" yaml:"SafetyRelevantObject,omitempty"`
	BillOfMaterialItemCategoryDesc null.String `boil:"BillOfMaterialItemCategoryDesc" json:"BillOfMaterialItemCategoryDesc,omitempty" toml:"BillOfMaterialItemCategoryDesc" yaml:"BillOfMaterialItemCategoryDesc,omitempty"`
	MatlsPlngRelevancyCodeName     null.String `boil:"MatlsPlngRelevancyCodeName" json:"MatlsPlngRelevancyCodeName,omitempty" toml:"MatlsPlngRelevancyCodeName" yaml:"MatlsPlngRelevancyCodeName,omitempty"`
	SafetyRelevanceActionDesc      null.String `boil:"SafetyRelevanceActionDesc" json:"SafetyRelevanceActionDesc,omitempty" toml:"SafetyRelevanceActionDesc" yaml:"SafetyRelevanceActionDesc,omitempty"`

	R *sapMaintenanceTaskListOperationMaterialDatumR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L sapMaintenanceTaskListOperationMaterialDatumL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}

var SapMaintenanceTaskListOperationMaterialDatumColumns = struct {
	TaskListType                   string
	TaskListGroup                  string
	TaskListGroupCounter           string
	TaskListSequence               string
	TaskListOperationInternalID    string
	TaskListOpBOMItmIntVersCounter string
	TaskListOpBOMItmInternalID     string
	Material                       string
	MaterialName                   string
	BillOfMaterialItemQuantity     string
	BillOfMaterialItemCategory     string
	BillOfMaterialItemUnit         string
	ResvnIsMRPRlvtOrPurReqnIsCrted string
	MatlCompIsMarkedForBackflush   string
	SafetyRelevantObject           string
	BillOfMaterialItemCategoryDesc string
	MatlsPlngRelevancyCodeName     string
	SafetyRelevanceActionDesc      string
}{
	TaskListType:                   "TaskListType",
	TaskListGroup:                  "TaskListGroup",
	TaskListGroupCounter:           "TaskListGroupCounter",
	TaskListSequence:               "TaskListSequence",
	TaskListOperationInternalID:    "TaskListOperationInternalID",
	TaskListOpBOMItmIntVersCounter: "TaskListOpBOMItmIntVersCounter",
	TaskListOpBOMItmInternalID:     "TaskListOpBOMItmInternalID",
	Material:                       "Material",
	MaterialName:                   "MaterialName",
	BillOfMaterialItemQuantity:     "BillOfMaterialItemQuantity",
	BillOfMaterialItemCategory:     "BillOfMaterialItemCategory",
	BillOfMaterialItemUnit:         "BillOfMaterialItemUnit",
	ResvnIsMRPRlvtOrPurReqnIsCrted: "ResvnIsMRPRlvtOrPurReqnIsCrted",
	MatlCompIsMarkedForBackflush:   "MatlCompIsMarkedForBackflush",
	SafetyRelevantObject:           "SafetyRelevantObject",
	BillOfMaterialItemCategoryDesc: "BillOfMaterialItemCategoryDesc",
	MatlsPlngRelevancyCodeName:     "MatlsPlngRelevancyCodeName",
	SafetyRelevanceActionDesc:      "SafetyRelevanceActionDesc",
}

var SapMaintenanceTaskListOperationMaterialDatumTableColumns = struct {
	TaskListType                   string
	TaskListGroup                  string
	TaskListGroupCounter           string
	TaskListSequence               string
	TaskListOperationInternalID    string
	TaskListOpBOMItmIntVersCounter string
	TaskListOpBOMItmInternalID     string
	Material                       string
	MaterialName                   string
	BillOfMaterialItemQuantity     string
	BillOfMaterialItemCategory     string
	BillOfMaterialItemUnit         string
	ResvnIsMRPRlvtOrPurReqnIsCrted string
	MatlCompIsMarkedForBackflush   string
	SafetyRelevantObject           string
	BillOfMaterialItemCategoryDesc string
	MatlsPlngRelevancyCodeName     string
	SafetyRelevanceActionDesc      string
}{
	TaskListType:                   "sap_maintenance_task_list_operation_material_data.TaskListType",
	TaskListGroup:                  "sap_maintenance_task_list_operation_material_data.TaskListGroup",
	TaskListGroupCounter:           "sap_maintenance_task_list_operation_material_data.TaskListGroupCounter",
	TaskListSequence:               "sap_maintenance_task_list_operation_material_data.TaskListSequence",
	TaskListOperationInternalID:    "sap_maintenance_task_list_operation_material_data.TaskListOperationInternalID",
	TaskListOpBOMItmIntVersCounter: "sap_maintenance_task_list_operation_material_data.TaskListOpBOMItmIntVersCounter",
	TaskListOpBOMItmInternalID:     "sap_maintenance_task_list_operation_material_data.TaskListOpBOMItmInternalID",
	Material:                       "sap_maintenance_task_list_operation_material_data.Material",
	MaterialName:                   "sap_maintenance_task_list_operation_material_data.MaterialName",
	BillOfMaterialItemQuantity:     "sap_maintenance_task_list_operation_material_data.BillOfMaterialItemQuantity",
	BillOfMaterialItemCategory:     "sap_maintenance_task_list_operation_material_data.BillOfMaterialItemCategory",
	BillOfMaterialItemUnit:         "sap_maintenance_task_list_operation_material_data.BillOfMaterialItemUnit",
	ResvnIsMRPRlvtOrPurReqnIsCrted: "sap_maintenance_task_list_operation_material_data.ResvnIsMRPRlvtOrPurReqnIsCrted",
	MatlCompIsMarkedForBackflush:   "sap_maintenance_task_list_operation_material_data.MatlCompIsMarkedForBackflush",
	SafetyRelevantObject:           "sap_maintenance_task_list_operation_material_data.SafetyRelevantObject",
	BillOfMaterialItemCategoryDesc: "sap_maintenance_task_list_operation_material_data.BillOfMaterialItemCategoryDesc",
	MatlsPlngRelevancyCodeName:     "sap_maintenance_task_list_operation_material_data.MatlsPlngRelevancyCodeName",
	SafetyRelevanceActionDesc:      "sap_maintenance_task_list_operation_material_data.SafetyRelevanceActionDesc",
}

var SapMaintenanceTaskListOperationMaterialDatumWhere = struct {
	TaskListType                   whereHelperstring
	TaskListGroup                  whereHelperstring
	TaskListGroupCounter           whereHelperstring
	TaskListSequence               whereHelperstring
	TaskListOperationInternalID    whereHelperstring
	TaskListOpBOMItmIntVersCounter whereHelperstring
	TaskListOpBOMItmInternalID     whereHelperstring
	Material                       whereHelpernull_String
	MaterialName                   whereHelpernull_String
	BillOfMaterialItemQuantity     whereHelpernull_String
	BillOfMaterialItemCategory     whereHelpernull_String
	BillOfMaterialItemUnit         whereHelpernull_String
	ResvnIsMRPRlvtOrPurReqnIsCrted whereHelpernull_String
	MatlCompIsMarkedForBackflush   whereHelpernull_Bool
	SafetyRelevantObject           whereHelpernull_String
	BillOfMaterialItemCategoryDesc whereHelpernull_String
	MatlsPlngRelevancyCodeName     whereHelpernull_String
	SafetyRelevanceActionDesc      whereHelpernull_String
}{
	TaskListType:                   whereHelperstring{field: "`sap_maintenance_task_list_operation_material_data`.`TaskListType`"},
	TaskListGroup:                  whereHelperstring{field: "`sap_maintenance_task_list_operation_material_data`.`TaskListGroup`"},
	TaskListGroupCounter:           whereHelperstring{field: "`sap_maintenance_task_list_operation_material_data`.`TaskListGroupCounter`"},
	TaskListSequence:               whereHelperstring{field: "`sap_maintenance_task_list_operation_material_data`.`TaskListSequence`"},
	TaskListOperationInternalID:    whereHelperstring{field: "`sap_maintenance_task_list_operation_material_data`.`TaskListOperationInternalID`"},
	TaskListOpBOMItmIntVersCounter: whereHelperstring{field: "`sap_maintenance_task_list_operation_material_data`.`TaskListOpBOMItmIntVersCounter`"},
	TaskListOpBOMItmInternalID:     whereHelperstring{field: "`sap_maintenance_task_list_operation_material_data`.`TaskListOpBOMItmInternalID`"},
	Material:                       whereHelpernull_String{field: "`sap_maintenance_task_list_operation_material_data`.`Material`"},
	MaterialName:                   whereHelpernull_String{field: "`sap_maintenance_task_list_operation_material_data`.`MaterialName`"},
	BillOfMaterialItemQuantity:     whereHelpernull_String{field: "`sap_maintenance_task_list_operation_material_data`.`BillOfMaterialItemQuantity`"},
	BillOfMaterialItemCategory:     whereHelpernull_String{field: "`sap_maintenance_task_list_operation_material_data`.`BillOfMaterialItemCategory`"},
	BillOfMaterialItemUnit:         whereHelpernull_String{field: "`sap_maintenance_task_list_operation_material_data`.`BillOfMaterialItemUnit`"},
	ResvnIsMRPRlvtOrPurReqnIsCrted: whereHelpernull_String{field: "`sap_maintenance_task_list_operation_material_data`.`ResvnIsMRPRlvtOrPurReqnIsCrted`"},
	MatlCompIsMarkedForBackflush:   whereHelpernull_Bool{field: "`sap_maintenance_task_list_operation_material_data`.`MatlCompIsMarkedForBackflush`"},
	SafetyRelevantObject:           whereHelpernull_String{field: "`sap_maintenance_task_list_operation_material_data`.`SafetyRelevantObject`"},
	BillOfMaterialItemCategoryDesc: whereHelpernull_String{field: "`sap_maintenance_task_list_operation_material_data`.`BillOfMaterialItemCategoryDesc`"},
	MatlsPlngRelevancyCodeName:     whereHelpernull_String{field: "`sap_maintenance_task_list_operation_material_data`.`MatlsPlngRelevancyCodeName`"},
	SafetyRelevanceActionDesc:      whereHelpernull_String{field: "`sap_maintenance_task_list_operation_material_data`.`SafetyRelevanceActionDesc`"},
}

var SapMaintenanceTaskListOperationMaterialDatumRels = struct {
}{}

type sapMaintenanceTaskListOperationMaterialDatumR struct {
}

func (*sapMaintenanceTaskListOperationMaterialDatumR) NewStruct() *sapMaintenanceTaskListOperationMaterialDatumR {
	return &sapMaintenanceTaskListOperationMaterialDatumR{}
}

type sapMaintenanceTaskListOperationMaterialDatumL struct{}

var (
	sapMaintenanceTaskListOperationMaterialDatumAllColumns            = []string{"TaskListType", "TaskListGroup", "TaskListGroupCounter", "TaskListSequence", "TaskListOperationInternalID", "TaskListOpBOMItmIntVersCounter", "TaskListOpBOMItmInternalID", "Material", "MaterialName", "BillOfMaterialItemQuantity", "BillOfMaterialItemCategory", "BillOfMaterialItemUnit", "ResvnIsMRPRlvtOrPurReqnIsCrted", "MatlCompIsMarkedForBackflush", "SafetyRelevantObject", "BillOfMaterialItemCategoryDesc", "MatlsPlngRelevancyCodeName", "SafetyRelevanceActionDesc"}
	sapMaintenanceTaskListOperationMaterialDatumColumnsWithoutDefault = []string{"TaskListType", "TaskListGroup", "TaskListGroupCounter", "TaskListSequence", "TaskListOperationInternalID", "TaskListOpBOMItmIntVersCounter", "TaskListOpBOMItmInternalID", "Material", "MaterialName", "BillOfMaterialItemQuantity", "BillOfMaterialItemCategory", "BillOfMaterialItemUnit", "ResvnIsMRPRlvtOrPurReqnIsCrted", "MatlCompIsMarkedForBackflush", "SafetyRelevantObject", "BillOfMaterialItemCategoryDesc", "MatlsPlngRelevancyCodeName", "SafetyRelevanceActionDesc"}
	sapMaintenanceTaskListOperationMaterialDatumColumnsWithDefault    = []string{}
	sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyColumns     = []string{"TaskListType", "TaskListGroup", "TaskListGroupCounter", "TaskListSequence", "TaskListOperationInternalID", "TaskListOpBOMItmIntVersCounter", "TaskListOpBOMItmInternalID"}
	sapMaintenanceTaskListOperationMaterialDatumGeneratedColumns      = []string{}
)

type (

	SapMaintenanceTaskListOperationMaterialDatumSlice []*SapMaintenanceTaskListOperationMaterialDatum

	SapMaintenanceTaskListOperationMaterialDatumHook func(context.Context, boil.ContextExecutor, *SapMaintenanceTaskListOperationMaterialDatum) error

	sapMaintenanceTaskListOperationMaterialDatumQuery struct {
		*queries.Query
	}
)

var (
	sapMaintenanceTaskListOperationMaterialDatumType                 = reflect.TypeOf(&SapMaintenanceTaskListOperationMaterialDatum{})
	sapMaintenanceTaskListOperationMaterialDatumMapping              = queries.MakeStructMapping(sapMaintenanceTaskListOperationMaterialDatumType)
	sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyMapping, _ = queries.BindMapping(sapMaintenanceTaskListOperationMaterialDatumType, sapMaintenanceTaskListOperationMaterialDatumMapping, sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyColumns)
	sapMaintenanceTaskListOperationMaterialDatumInsertCacheMut       sync.RWMutex
	sapMaintenanceTaskListOperationMaterialDatumInsertCache          = make(map[string]insertCache)
	sapMaintenanceTaskListOperationMaterialDatumUpdateCacheMut       sync.RWMutex
	sapMaintenanceTaskListOperationMaterialDatumUpdateCache          = make(map[string]updateCache)
	sapMaintenanceTaskListOperationMaterialDatumUpsertCacheMut       sync.RWMutex
	sapMaintenanceTaskListOperationMaterialDatumUpsertCache          = make(map[string]insertCache)
)

var (

	_ = time.Second

	_ = qmhelper.Where
)

var sapMaintenanceTaskListOperationMaterialDatumAfterSelectHooks []SapMaintenanceTaskListOperationMaterialDatumHook

var sapMaintenanceTaskListOperationMaterialDatumBeforeInsertHooks []SapMaintenanceTaskListOperationMaterialDatumHook
var sapMaintenanceTaskListOperationMaterialDatumAfterInsertHooks []SapMaintenanceTaskListOperationMaterialDatumHook

var sapMaintenanceTaskListOperationMaterialDatumBeforeUpdateHooks []SapMaintenanceTaskListOperationMaterialDatumHook
var sapMaintenanceTaskListOperationMaterialDatumAfterUpdateHooks []SapMaintenanceTaskListOperationMaterialDatumHook

var sapMaintenanceTaskListOperationMaterialDatumBeforeDeleteHooks []SapMaintenanceTaskListOperationMaterialDatumHook
var sapMaintenanceTaskListOperationMaterialDatumAfterDeleteHooks []SapMaintenanceTaskListOperationMaterialDatumHook

var sapMaintenanceTaskListOperationMaterialDatumBeforeUpsertHooks []SapMaintenanceTaskListOperationMaterialDatumHook
var sapMaintenanceTaskListOperationMaterialDatumAfterUpsertHooks []SapMaintenanceTaskListOperationMaterialDatumHook

func (o *SapMaintenanceTaskListOperationMaterialDatum) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

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

	return nil
}

func (o *SapMaintenanceTaskListOperationMaterialDatum) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

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

	return nil
}

func (o *SapMaintenanceTaskListOperationMaterialDatum) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

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

	return nil
}

func (o *SapMaintenanceTaskListOperationMaterialDatum) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

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

	return nil
}

func (o *SapMaintenanceTaskListOperationMaterialDatum) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

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

	return nil
}

func (o *SapMaintenanceTaskListOperationMaterialDatum) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

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

	return nil
}

func (o *SapMaintenanceTaskListOperationMaterialDatum) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

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

	return nil
}

func (o *SapMaintenanceTaskListOperationMaterialDatum) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

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

	return nil
}

func (o *SapMaintenanceTaskListOperationMaterialDatum) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

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

	return nil
}

func AddSapMaintenanceTaskListOperationMaterialDatumHook(hookPoint boil.HookPoint, sapMaintenanceTaskListOperationMaterialDatumHook SapMaintenanceTaskListOperationMaterialDatumHook) {
	switch hookPoint {
	case boil.AfterSelectHook:
		sapMaintenanceTaskListOperationMaterialDatumAfterSelectHooks = append(sapMaintenanceTaskListOperationMaterialDatumAfterSelectHooks, sapMaintenanceTaskListOperationMaterialDatumHook)
	case boil.BeforeInsertHook:
		sapMaintenanceTaskListOperationMaterialDatumBeforeInsertHooks = append(sapMaintenanceTaskListOperationMaterialDatumBeforeInsertHooks, sapMaintenanceTaskListOperationMaterialDatumHook)
	case boil.AfterInsertHook:
		sapMaintenanceTaskListOperationMaterialDatumAfterInsertHooks = append(sapMaintenanceTaskListOperationMaterialDatumAfterInsertHooks, sapMaintenanceTaskListOperationMaterialDatumHook)
	case boil.BeforeUpdateHook:
		sapMaintenanceTaskListOperationMaterialDatumBeforeUpdateHooks = append(sapMaintenanceTaskListOperationMaterialDatumBeforeUpdateHooks, sapMaintenanceTaskListOperationMaterialDatumHook)
	case boil.AfterUpdateHook:
		sapMaintenanceTaskListOperationMaterialDatumAfterUpdateHooks = append(sapMaintenanceTaskListOperationMaterialDatumAfterUpdateHooks, sapMaintenanceTaskListOperationMaterialDatumHook)
	case boil.BeforeDeleteHook:
		sapMaintenanceTaskListOperationMaterialDatumBeforeDeleteHooks = append(sapMaintenanceTaskListOperationMaterialDatumBeforeDeleteHooks, sapMaintenanceTaskListOperationMaterialDatumHook)
	case boil.AfterDeleteHook:
		sapMaintenanceTaskListOperationMaterialDatumAfterDeleteHooks = append(sapMaintenanceTaskListOperationMaterialDatumAfterDeleteHooks, sapMaintenanceTaskListOperationMaterialDatumHook)
	case boil.BeforeUpsertHook:
		sapMaintenanceTaskListOperationMaterialDatumBeforeUpsertHooks = append(sapMaintenanceTaskListOperationMaterialDatumBeforeUpsertHooks, sapMaintenanceTaskListOperationMaterialDatumHook)
	case boil.AfterUpsertHook:
		sapMaintenanceTaskListOperationMaterialDatumAfterUpsertHooks = append(sapMaintenanceTaskListOperationMaterialDatumAfterUpsertHooks, sapMaintenanceTaskListOperationMaterialDatumHook)
	}
}

func (q sapMaintenanceTaskListOperationMaterialDatumQuery) One(ctx context.Context, exec boil.ContextExecutor) (*SapMaintenanceTaskListOperationMaterialDatum, error) {
	o := &SapMaintenanceTaskListOperationMaterialDatum{}

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

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

	return o, nil
}

func (q sapMaintenanceTaskListOperationMaterialDatumQuery) All(ctx context.Context, exec boil.ContextExecutor) (SapMaintenanceTaskListOperationMaterialDatumSlice, error) {
	var o []*SapMaintenanceTaskListOperationMaterialDatum

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

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

	return o, nil
}

func (q sapMaintenanceTaskListOperationMaterialDatumQuery) 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 sap_maintenance_task_list_operation_material_data rows")
	}

	return count, nil
}

func (q sapMaintenanceTaskListOperationMaterialDatumQuery) 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 sap_maintenance_task_list_operation_material_data exists")
	}

	return count > 0, nil
}

func SapMaintenanceTaskListOperationMaterialData(mods ...qm.QueryMod) sapMaintenanceTaskListOperationMaterialDatumQuery {
	mods = append(mods, qm.From("`sap_maintenance_task_list_operation_material_data`"))
	q := NewQuery(mods...)
	if len(queries.GetSelect(q)) == 0 {
		queries.SetSelect(q, []string{"`sap_maintenance_task_list_operation_material_data`.*"})
	}

	return sapMaintenanceTaskListOperationMaterialDatumQuery{q}
}

func FindSapMaintenanceTaskListOperationMaterialDatum(ctx context.Context, exec boil.ContextExecutor, taskListType string, taskListGroup string, taskListGroupCounter string, taskListSequence string, taskListOperationInternalID string, taskListOpBOMItmIntVersCounter string, taskListOpBOMItmInternalID string, selectCols ...string) (*SapMaintenanceTaskListOperationMaterialDatum, error) {
	sapMaintenanceTaskListOperationMaterialDatumObj := &SapMaintenanceTaskListOperationMaterialDatum{}

	sel := "*"
	if len(selectCols) > 0 {
		sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
	}
	query := fmt.Sprintf(
		"select %s from `sap_maintenance_task_list_operation_material_data` where `TaskListType`=? AND `TaskListGroup`=? AND `TaskListGroupCounter`=? AND `TaskListSequence`=? AND `TaskListOperationInternalID`=? AND `TaskListOpBOMItmIntVersCounter`=? AND `TaskListOpBOMItmInternalID`=?", sel,
	)

	q := queries.Raw(query, taskListType, taskListGroup, taskListGroupCounter, taskListSequence, taskListOperationInternalID, taskListOpBOMItmIntVersCounter, taskListOpBOMItmInternalID)

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

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

	return sapMaintenanceTaskListOperationMaterialDatumObj, nil
}

func (o *SapMaintenanceTaskListOperationMaterialDatum) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
	if o == nil {
		return errors.New("models: no sap_maintenance_task_list_operation_material_data provided for insertion")
	}

	var err error

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

	nzDefaults := queries.NonZeroDefaultSet(sapMaintenanceTaskListOperationMaterialDatumColumnsWithDefault, o)

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

	if !cached {
		wl, returnColumns := columns.InsertColumnSet(
			sapMaintenanceTaskListOperationMaterialDatumAllColumns,
			sapMaintenanceTaskListOperationMaterialDatumColumnsWithDefault,
			sapMaintenanceTaskListOperationMaterialDatumColumnsWithoutDefault,
			nzDefaults,
		)

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

		var queryOutput, queryReturning string

		if len(cache.retMapping) != 0 {
			cache.retQuery = fmt.Sprintf("SELECT `%s` FROM `sap_maintenance_task_list_operation_material_data` WHERE %s", strings.Join(returnColumns, "`,`"), strmangle.WhereClause("`", "`", 0, sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyColumns))
		}

		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)
	}
	_, err = exec.ExecContext(ctx, cache.query, vals...)

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

	var identifierCols []interface{}

	if len(cache.retMapping) == 0 {
		goto CacheNoHooks
	}

	identifierCols = []interface{}{
		o.TaskListType,
		o.TaskListGroup,
		o.TaskListGroupCounter,
		o.TaskListSequence,
		o.TaskListOperationInternalID,
		o.TaskListOpBOMItmIntVersCounter,
		o.TaskListOpBOMItmInternalID,
	}

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, cache.retQuery)
		fmt.Fprintln(writer, identifierCols...)
	}
	err = exec.QueryRowContext(ctx, cache.retQuery, identifierCols...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
	if err != nil {
		return errors.Wrap(err, "models: unable to populate default values for sap_maintenance_task_list_operation_material_data")
	}

CacheNoHooks:
	if !cached {
		sapMaintenanceTaskListOperationMaterialDatumInsertCacheMut.Lock()
		sapMaintenanceTaskListOperationMaterialDatumInsertCache[key] = cache
		sapMaintenanceTaskListOperationMaterialDatumInsertCacheMut.Unlock()
	}

	return o.doAfterInsertHooks(ctx, exec)
}

func (o *SapMaintenanceTaskListOperationMaterialDatum) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
	var err error
	if err = o.doBeforeUpdateHooks(ctx, exec); err != nil {
		return 0, err
	}
	key := makeCacheKey(columns, nil)
	sapMaintenanceTaskListOperationMaterialDatumUpdateCacheMut.RLock()
	cache, cached := sapMaintenanceTaskListOperationMaterialDatumUpdateCache[key]
	sapMaintenanceTaskListOperationMaterialDatumUpdateCacheMut.RUnlock()

	if !cached {
		wl := columns.UpdateColumnSet(
			sapMaintenanceTaskListOperationMaterialDatumAllColumns,
			sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyColumns,
		)

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

		cache.query = fmt.Sprintf("UPDATE `sap_maintenance_task_list_operation_material_data` SET %s WHERE %s",
			strmangle.SetParamNames("`", "`", 0, wl),
			strmangle.WhereClause("`", "`", 0, sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyColumns),
		)
		cache.valueMapping, err = queries.BindMapping(sapMaintenanceTaskListOperationMaterialDatumType, sapMaintenanceTaskListOperationMaterialDatumMapping, append(wl, sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyColumns...))
		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 sap_maintenance_task_list_operation_material_data row")
	}

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

	if !cached {
		sapMaintenanceTaskListOperationMaterialDatumUpdateCacheMut.Lock()
		sapMaintenanceTaskListOperationMaterialDatumUpdateCache[key] = cache
		sapMaintenanceTaskListOperationMaterialDatumUpdateCacheMut.Unlock()
	}

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

func (q sapMaintenanceTaskListOperationMaterialDatumQuery) 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 sap_maintenance_task_list_operation_material_data")
	}

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

	return rowsAff, nil
}

func (o SapMaintenanceTaskListOperationMaterialDatumSlice) 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++
	}

	for _, obj := range o {
		pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}

	sql := fmt.Sprintf("UPDATE `sap_maintenance_task_list_operation_material_data` SET %s WHERE %s",
		strmangle.SetParamNames("`", "`", 0, colNames),
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyColumns, 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 sapMaintenanceTaskListOperationMaterialDatum slice")
	}

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

var mySQLSapMaintenanceTaskListOperationMaterialDatumUniqueColumns = []string{}

func (o *SapMaintenanceTaskListOperationMaterialDatum) Upsert(ctx context.Context, exec boil.ContextExecutor, updateColumns, insertColumns boil.Columns) error {
	if o == nil {
		return errors.New("models: no sap_maintenance_task_list_operation_material_data provided for upsert")
	}

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

	nzDefaults := queries.NonZeroDefaultSet(sapMaintenanceTaskListOperationMaterialDatumColumnsWithDefault, o)
	nzUniques := queries.NonZeroDefaultSet(mySQLSapMaintenanceTaskListOperationMaterialDatumUniqueColumns, o)

	if len(nzUniques) == 0 {
		return errors.New("cannot upsert with a table that cannot conflict on a unique column")
	}

	buf := strmangle.GetBuffer()
	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)
	}
	buf.WriteByte('.')
	for _, c := range nzUniques {
		buf.WriteString(c)
	}
	key := buf.String()
	strmangle.PutBuffer(buf)

	sapMaintenanceTaskListOperationMaterialDatumUpsertCacheMut.RLock()
	cache, cached := sapMaintenanceTaskListOperationMaterialDatumUpsertCache[key]
	sapMaintenanceTaskListOperationMaterialDatumUpsertCacheMut.RUnlock()

	var err error

	if !cached {
		insert, ret := insertColumns.InsertColumnSet(
			sapMaintenanceTaskListOperationMaterialDatumAllColumns,
			sapMaintenanceTaskListOperationMaterialDatumColumnsWithDefault,
			sapMaintenanceTaskListOperationMaterialDatumColumnsWithoutDefault,
			nzDefaults,
		)

		update := updateColumns.UpdateColumnSet(
			sapMaintenanceTaskListOperationMaterialDatumAllColumns,
			sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyColumns,
		)

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

		ret = strmangle.SetComplement(ret, nzUniques)
		cache.query = buildUpsertQueryMySQL(dialect, "`sap_maintenance_task_list_operation_material_data`", update, insert)
		cache.retQuery = fmt.Sprintf(
			"SELECT %s FROM `sap_maintenance_task_list_operation_material_data` WHERE %s",
			strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, ret), ","),
			strmangle.WhereClause("`", "`", 0, nzUniques),
		)

		cache.valueMapping, err = queries.BindMapping(sapMaintenanceTaskListOperationMaterialDatumType, sapMaintenanceTaskListOperationMaterialDatumMapping, insert)
		if err != nil {
			return err
		}
		if len(ret) != 0 {
			cache.retMapping, err = queries.BindMapping(sapMaintenanceTaskListOperationMaterialDatumType, sapMaintenanceTaskListOperationMaterialDatumMapping, 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)
	}
	_, err = exec.ExecContext(ctx, cache.query, vals...)

	if err != nil {
		return errors.Wrap(err, "models: unable to upsert for sap_maintenance_task_list_operation_material_data")
	}

	var uniqueMap []uint64
	var nzUniqueCols []interface{}

	if len(cache.retMapping) == 0 {
		goto CacheNoHooks
	}

	uniqueMap, err = queries.BindMapping(sapMaintenanceTaskListOperationMaterialDatumType, sapMaintenanceTaskListOperationMaterialDatumMapping, nzUniques)
	if err != nil {
		return errors.Wrap(err, "models: unable to retrieve unique values for sap_maintenance_task_list_operation_material_data")
	}
	nzUniqueCols = queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), uniqueMap)

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, cache.retQuery)
		fmt.Fprintln(writer, nzUniqueCols...)
	}
	err = exec.QueryRowContext(ctx, cache.retQuery, nzUniqueCols...).Scan(returns...)
	if err != nil {
		return errors.Wrap(err, "models: unable to populate default values for sap_maintenance_task_list_operation_material_data")
	}

CacheNoHooks:
	if !cached {
		sapMaintenanceTaskListOperationMaterialDatumUpsertCacheMut.Lock()
		sapMaintenanceTaskListOperationMaterialDatumUpsertCache[key] = cache
		sapMaintenanceTaskListOperationMaterialDatumUpsertCacheMut.Unlock()
	}

	return o.doAfterUpsertHooks(ctx, exec)
}

func (o *SapMaintenanceTaskListOperationMaterialDatum) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
	if o == nil {
		return 0, errors.New("models: no SapMaintenanceTaskListOperationMaterialDatum provided for delete")
	}

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

	args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyMapping)
	sql := "DELETE FROM `sap_maintenance_task_list_operation_material_data` WHERE `TaskListType`=? AND `TaskListGroup`=? AND `TaskListGroupCounter`=? AND `TaskListSequence`=? AND `TaskListOperationInternalID`=? AND `TaskListOpBOMItmIntVersCounter`=? AND `TaskListOpBOMItmInternalID`=?"

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

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

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

	return rowsAff, nil
}

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

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

	return rowsAff, nil
}

func (o SapMaintenanceTaskListOperationMaterialDatumSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
	if len(o) == 0 {
		return 0, nil
	}

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

	sql := "DELETE FROM `sap_maintenance_task_list_operation_material_data` WHERE " +
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyColumns, 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 sapMaintenanceTaskListOperationMaterialDatum slice")
	}

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

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

	return rowsAff, nil
}

func (o *SapMaintenanceTaskListOperationMaterialDatum) Reload(ctx context.Context, exec boil.ContextExecutor) error {
	ret, err := FindSapMaintenanceTaskListOperationMaterialDatum(ctx, exec, o.TaskListType, o.TaskListGroup, o.TaskListGroupCounter, o.TaskListSequence, o.TaskListOperationInternalID, o.TaskListOpBOMItmIntVersCounter, o.TaskListOpBOMItmInternalID)
	if err != nil {
		return err
	}

	*o = *ret
	return nil
}

func (o *SapMaintenanceTaskListOperationMaterialDatumSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
	if o == nil || len(*o) == 0 {
		return nil
	}

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

	sql := "SELECT `sap_maintenance_task_list_operation_material_data`.* FROM `sap_maintenance_task_list_operation_material_data` WHERE " +
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyColumns, 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 SapMaintenanceTaskListOperationMaterialDatumSlice")
	}

	*o = slice

	return nil
}

func SapMaintenanceTaskListOperationMaterialDatumExists(ctx context.Context, exec boil.ContextExecutor, taskListType string, taskListGroup string, taskListGroupCounter string, taskListSequence string, taskListOperationInternalID string, taskListOpBOMItmIntVersCounter string, taskListOpBOMItmInternalID string) (bool, error) {
	var exists bool
	sql := "select exists(select 1 from `sap_maintenance_task_list_operation_material_data` where `TaskListType`=? AND `TaskListGroup`=? AND `TaskListGroupCounter`=? AND `TaskListSequence`=? AND `TaskListOperationInternalID`=? AND `TaskListOpBOMItmIntVersCounter`=? AND `TaskListOpBOMItmInternalID`=? limit 1)"

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, sql)
		fmt.Fprintln(writer, taskListType, taskListGroup, taskListGroupCounter, taskListSequence, taskListOperationInternalID, taskListOpBOMItmIntVersCounter, taskListOpBOMItmInternalID)
	}
	row := exec.QueryRowContext(ctx, sql, taskListType, taskListGroup, taskListGroupCounter, taskListSequence, taskListOperationInternalID, taskListOpBOMItmIntVersCounter, taskListOpBOMItmInternalID)

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

	return exists, nil
}
// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/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/friendsofgo/errors"
	"github.com/volatiletech/null/v8"
	"github.com/volatiletech/sqlboiler/v4/boil"
	"github.com/volatiletech/sqlboiler/v4/queries"
	"github.com/volatiletech/sqlboiler/v4/queries/qm"
	"github.com/volatiletech/sqlboiler/v4/queries/qmhelper"
	"github.com/volatiletech/strmangle"
)

// SapMaintenanceTaskListOperationMaterialDatum is an object representing the database table.
type SapMaintenanceTaskListOperationMaterialDatum struct {
	TaskListType                   string      `boil:"TaskListType" json:"TaskListType" toml:"TaskListType" yaml:"TaskListType"`
	TaskListGroup                  string      `boil:"TaskListGroup" json:"TaskListGroup" toml:"TaskListGroup" yaml:"TaskListGroup"`
	TaskListGroupCounter           string      `boil:"TaskListGroupCounter" json:"TaskListGroupCounter" toml:"TaskListGroupCounter" yaml:"TaskListGroupCounter"`
	TaskListSequence               string      `boil:"TaskListSequence" json:"TaskListSequence" toml:"TaskListSequence" yaml:"TaskListSequence"`
	TaskListOperationInternalID    string      `boil:"TaskListOperationInternalID" json:"TaskListOperationInternalID" toml:"TaskListOperationInternalID" yaml:"TaskListOperationInternalID"`
	TaskListOpBOMItmIntVersCounter string      `boil:"TaskListOpBOMItmIntVersCounter" json:"TaskListOpBOMItmIntVersCounter" toml:"TaskListOpBOMItmIntVersCounter" yaml:"TaskListOpBOMItmIntVersCounter"`
	TaskListOpBOMItmInternalID     string      `boil:"TaskListOpBOMItmInternalID" json:"TaskListOpBOMItmInternalID" toml:"TaskListOpBOMItmInternalID" yaml:"TaskListOpBOMItmInternalID"`
	Material                       null.String `boil:"Material" json:"Material,omitempty" toml:"Material" yaml:"Material,omitempty"`
	MaterialName                   null.String `boil:"MaterialName" json:"MaterialName,omitempty" toml:"MaterialName" yaml:"MaterialName,omitempty"`
	BillOfMaterialItemQuantity     null.String `boil:"BillOfMaterialItemQuantity" json:"BillOfMaterialItemQuantity,omitempty" toml:"BillOfMaterialItemQuantity" yaml:"BillOfMaterialItemQuantity,omitempty"`
	BillOfMaterialItemCategory     null.String `boil:"BillOfMaterialItemCategory" json:"BillOfMaterialItemCategory,omitempty" toml:"BillOfMaterialItemCategory" yaml:"BillOfMaterialItemCategory,omitempty"`
	BillOfMaterialItemUnit         null.String `boil:"BillOfMaterialItemUnit" json:"BillOfMaterialItemUnit,omitempty" toml:"BillOfMaterialItemUnit" yaml:"BillOfMaterialItemUnit,omitempty"`
	ResvnIsMRPRlvtOrPurReqnIsCrted null.String `boil:"ResvnIsMRPRlvtOrPurReqnIsCrted" json:"ResvnIsMRPRlvtOrPurReqnIsCrted,omitempty" toml:"ResvnIsMRPRlvtOrPurReqnIsCrted" yaml:"ResvnIsMRPRlvtOrPurReqnIsCrted,omitempty"`
	MatlCompIsMarkedForBackflush   null.Bool   `boil:"MatlCompIsMarkedForBackflush" json:"MatlCompIsMarkedForBackflush,omitempty" toml:"MatlCompIsMarkedForBackflush" yaml:"MatlCompIsMarkedForBackflush,omitempty"`
	SafetyRelevantObject           null.String `boil:"SafetyRelevantObject" json:"SafetyRelevantObject,omitempty" toml:"SafetyRelevantObject" yaml:"SafetyRelevantObject,omitempty"`
	BillOfMaterialItemCategoryDesc null.String `boil:"BillOfMaterialItemCategoryDesc" json:"BillOfMaterialItemCategoryDesc,omitempty" toml:"BillOfMaterialItemCategoryDesc" yaml:"BillOfMaterialItemCategoryDesc,omitempty"`
	MatlsPlngRelevancyCodeName     null.String `boil:"MatlsPlngRelevancyCodeName" json:"MatlsPlngRelevancyCodeName,omitempty" toml:"MatlsPlngRelevancyCodeName" yaml:"MatlsPlngRelevancyCodeName,omitempty"`
	SafetyRelevanceActionDesc      null.String `boil:"SafetyRelevanceActionDesc" json:"SafetyRelevanceActionDesc,omitempty" toml:"SafetyRelevanceActionDesc" yaml:"SafetyRelevanceActionDesc,omitempty"`

	R *sapMaintenanceTaskListOperationMaterialDatumR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L sapMaintenanceTaskListOperationMaterialDatumL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}

var SapMaintenanceTaskListOperationMaterialDatumColumns = struct {
	TaskListType                   string
	TaskListGroup                  string
	TaskListGroupCounter           string
	TaskListSequence               string
	TaskListOperationInternalID    string
	TaskListOpBOMItmIntVersCounter string
	TaskListOpBOMItmInternalID     string
	Material                       string
	MaterialName                   string
	BillOfMaterialItemQuantity     string
	BillOfMaterialItemCategory     string
	BillOfMaterialItemUnit         string
	ResvnIsMRPRlvtOrPurReqnIsCrted string
	MatlCompIsMarkedForBackflush   string
	SafetyRelevantObject           string
	BillOfMaterialItemCategoryDesc string
	MatlsPlngRelevancyCodeName     string
	SafetyRelevanceActionDesc      string
}{
	TaskListType:                   "TaskListType",
	TaskListGroup:                  "TaskListGroup",
	TaskListGroupCounter:           "TaskListGroupCounter",
	TaskListSequence:               "TaskListSequence",
	TaskListOperationInternalID:    "TaskListOperationInternalID",
	TaskListOpBOMItmIntVersCounter: "TaskListOpBOMItmIntVersCounter",
	TaskListOpBOMItmInternalID:     "TaskListOpBOMItmInternalID",
	Material:                       "Material",
	MaterialName:                   "MaterialName",
	BillOfMaterialItemQuantity:     "BillOfMaterialItemQuantity",
	BillOfMaterialItemCategory:     "BillOfMaterialItemCategory",
	BillOfMaterialItemUnit:         "BillOfMaterialItemUnit",
	ResvnIsMRPRlvtOrPurReqnIsCrted: "ResvnIsMRPRlvtOrPurReqnIsCrted",
	MatlCompIsMarkedForBackflush:   "MatlCompIsMarkedForBackflush",
	SafetyRelevantObject:           "SafetyRelevantObject",
	BillOfMaterialItemCategoryDesc: "BillOfMaterialItemCategoryDesc",
	MatlsPlngRelevancyCodeName:     "MatlsPlngRelevancyCodeName",
	SafetyRelevanceActionDesc:      "SafetyRelevanceActionDesc",
}

var SapMaintenanceTaskListOperationMaterialDatumTableColumns = struct {
	TaskListType                   string
	TaskListGroup                  string
	TaskListGroupCounter           string
	TaskListSequence               string
	TaskListOperationInternalID    string
	TaskListOpBOMItmIntVersCounter string
	TaskListOpBOMItmInternalID     string
	Material                       string
	MaterialName                   string
	BillOfMaterialItemQuantity     string
	BillOfMaterialItemCategory     string
	BillOfMaterialItemUnit         string
	ResvnIsMRPRlvtOrPurReqnIsCrted string
	MatlCompIsMarkedForBackflush   string
	SafetyRelevantObject           string
	BillOfMaterialItemCategoryDesc string
	MatlsPlngRelevancyCodeName     string
	SafetyRelevanceActionDesc      string
}{
	TaskListType:                   "sap_maintenance_task_list_operation_material_data.TaskListType",
	TaskListGroup:                  "sap_maintenance_task_list_operation_material_data.TaskListGroup",
	TaskListGroupCounter:           "sap_maintenance_task_list_operation_material_data.TaskListGroupCounter",
	TaskListSequence:               "sap_maintenance_task_list_operation_material_data.TaskListSequence",
	TaskListOperationInternalID:    "sap_maintenance_task_list_operation_material_data.TaskListOperationInternalID",
	TaskListOpBOMItmIntVersCounter: "sap_maintenance_task_list_operation_material_data.TaskListOpBOMItmIntVersCounter",
	TaskListOpBOMItmInternalID:     "sap_maintenance_task_list_operation_material_data.TaskListOpBOMItmInternalID",
	Material:                       "sap_maintenance_task_list_operation_material_data.Material",
	MaterialName:                   "sap_maintenance_task_list_operation_material_data.MaterialName",
	BillOfMaterialItemQuantity:     "sap_maintenance_task_list_operation_material_data.BillOfMaterialItemQuantity",
	BillOfMaterialItemCategory:     "sap_maintenance_task_list_operation_material_data.BillOfMaterialItemCategory",
	BillOfMaterialItemUnit:         "sap_maintenance_task_list_operation_material_data.BillOfMaterialItemUnit",
	ResvnIsMRPRlvtOrPurReqnIsCrted: "sap_maintenance_task_list_operation_material_data.ResvnIsMRPRlvtOrPurReqnIsCrted",
	MatlCompIsMarkedForBackflush:   "sap_maintenance_task_list_operation_material_data.MatlCompIsMarkedForBackflush",
	SafetyRelevantObject:           "sap_maintenance_task_list_operation_material_data.SafetyRelevantObject",
	BillOfMaterialItemCategoryDesc: "sap_maintenance_task_list_operation_material_data.BillOfMaterialItemCategoryDesc",
	MatlsPlngRelevancyCodeName:     "sap_maintenance_task_list_operation_material_data.MatlsPlngRelevancyCodeName",
	SafetyRelevanceActionDesc:      "sap_maintenance_task_list_operation_material_data.SafetyRelevanceActionDesc",
}

// Generated where

var SapMaintenanceTaskListOperationMaterialDatumWhere = struct {
	TaskListType                   whereHelperstring
	TaskListGroup                  whereHelperstring
	TaskListGroupCounter           whereHelperstring
	TaskListSequence               whereHelperstring
	TaskListOperationInternalID    whereHelperstring
	TaskListOpBOMItmIntVersCounter whereHelperstring
	TaskListOpBOMItmInternalID     whereHelperstring
	Material                       whereHelpernull_String
	MaterialName                   whereHelpernull_String
	BillOfMaterialItemQuantity     whereHelpernull_String
	BillOfMaterialItemCategory     whereHelpernull_String
	BillOfMaterialItemUnit         whereHelpernull_String
	ResvnIsMRPRlvtOrPurReqnIsCrted whereHelpernull_String
	MatlCompIsMarkedForBackflush   whereHelpernull_Bool
	SafetyRelevantObject           whereHelpernull_String
	BillOfMaterialItemCategoryDesc whereHelpernull_String
	MatlsPlngRelevancyCodeName     whereHelpernull_String
	SafetyRelevanceActionDesc      whereHelpernull_String
}{
	TaskListType:                   whereHelperstring{field: "`sap_maintenance_task_list_operation_material_data`.`TaskListType`"},
	TaskListGroup:                  whereHelperstring{field: "`sap_maintenance_task_list_operation_material_data`.`TaskListGroup`"},
	TaskListGroupCounter:           whereHelperstring{field: "`sap_maintenance_task_list_operation_material_data`.`TaskListGroupCounter`"},
	TaskListSequence:               whereHelperstring{field: "`sap_maintenance_task_list_operation_material_data`.`TaskListSequence`"},
	TaskListOperationInternalID:    whereHelperstring{field: "`sap_maintenance_task_list_operation_material_data`.`TaskListOperationInternalID`"},
	TaskListOpBOMItmIntVersCounter: whereHelperstring{field: "`sap_maintenance_task_list_operation_material_data`.`TaskListOpBOMItmIntVersCounter`"},
	TaskListOpBOMItmInternalID:     whereHelperstring{field: "`sap_maintenance_task_list_operation_material_data`.`TaskListOpBOMItmInternalID`"},
	Material:                       whereHelpernull_String{field: "`sap_maintenance_task_list_operation_material_data`.`Material`"},
	MaterialName:                   whereHelpernull_String{field: "`sap_maintenance_task_list_operation_material_data`.`MaterialName`"},
	BillOfMaterialItemQuantity:     whereHelpernull_String{field: "`sap_maintenance_task_list_operation_material_data`.`BillOfMaterialItemQuantity`"},
	BillOfMaterialItemCategory:     whereHelpernull_String{field: "`sap_maintenance_task_list_operation_material_data`.`BillOfMaterialItemCategory`"},
	BillOfMaterialItemUnit:         whereHelpernull_String{field: "`sap_maintenance_task_list_operation_material_data`.`BillOfMaterialItemUnit`"},
	ResvnIsMRPRlvtOrPurReqnIsCrted: whereHelpernull_String{field: "`sap_maintenance_task_list_operation_material_data`.`ResvnIsMRPRlvtOrPurReqnIsCrted`"},
	MatlCompIsMarkedForBackflush:   whereHelpernull_Bool{field: "`sap_maintenance_task_list_operation_material_data`.`MatlCompIsMarkedForBackflush`"},
	SafetyRelevantObject:           whereHelpernull_String{field: "`sap_maintenance_task_list_operation_material_data`.`SafetyRelevantObject`"},
	BillOfMaterialItemCategoryDesc: whereHelpernull_String{field: "`sap_maintenance_task_list_operation_material_data`.`BillOfMaterialItemCategoryDesc`"},
	MatlsPlngRelevancyCodeName:     whereHelpernull_String{field: "`sap_maintenance_task_list_operation_material_data`.`MatlsPlngRelevancyCodeName`"},
	SafetyRelevanceActionDesc:      whereHelpernull_String{field: "`sap_maintenance_task_list_operation_material_data`.`SafetyRelevanceActionDesc`"},
}

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

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

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

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

var (
	sapMaintenanceTaskListOperationMaterialDatumAllColumns            = []string{"TaskListType", "TaskListGroup", "TaskListGroupCounter", "TaskListSequence", "TaskListOperationInternalID", "TaskListOpBOMItmIntVersCounter", "TaskListOpBOMItmInternalID", "Material", "MaterialName", "BillOfMaterialItemQuantity", "BillOfMaterialItemCategory", "BillOfMaterialItemUnit", "ResvnIsMRPRlvtOrPurReqnIsCrted", "MatlCompIsMarkedForBackflush", "SafetyRelevantObject", "BillOfMaterialItemCategoryDesc", "MatlsPlngRelevancyCodeName", "SafetyRelevanceActionDesc"}
	sapMaintenanceTaskListOperationMaterialDatumColumnsWithoutDefault = []string{"TaskListType", "TaskListGroup", "TaskListGroupCounter", "TaskListSequence", "TaskListOperationInternalID", "TaskListOpBOMItmIntVersCounter", "TaskListOpBOMItmInternalID", "Material", "MaterialName", "BillOfMaterialItemQuantity", "BillOfMaterialItemCategory", "BillOfMaterialItemUnit", "ResvnIsMRPRlvtOrPurReqnIsCrted", "MatlCompIsMarkedForBackflush", "SafetyRelevantObject", "BillOfMaterialItemCategoryDesc", "MatlsPlngRelevancyCodeName", "SafetyRelevanceActionDesc"}
	sapMaintenanceTaskListOperationMaterialDatumColumnsWithDefault    = []string{}
	sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyColumns     = []string{"TaskListType", "TaskListGroup", "TaskListGroupCounter", "TaskListSequence", "TaskListOperationInternalID", "TaskListOpBOMItmIntVersCounter", "TaskListOpBOMItmInternalID"}
	sapMaintenanceTaskListOperationMaterialDatumGeneratedColumns      = []string{}
)

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

	sapMaintenanceTaskListOperationMaterialDatumQuery struct {
		*queries.Query
	}
)

// Cache for insert, update and upsert
var (
	sapMaintenanceTaskListOperationMaterialDatumType                 = reflect.TypeOf(&SapMaintenanceTaskListOperationMaterialDatum{})
	sapMaintenanceTaskListOperationMaterialDatumMapping              = queries.MakeStructMapping(sapMaintenanceTaskListOperationMaterialDatumType)
	sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyMapping, _ = queries.BindMapping(sapMaintenanceTaskListOperationMaterialDatumType, sapMaintenanceTaskListOperationMaterialDatumMapping, sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyColumns)
	sapMaintenanceTaskListOperationMaterialDatumInsertCacheMut       sync.RWMutex
	sapMaintenanceTaskListOperationMaterialDatumInsertCache          = make(map[string]insertCache)
	sapMaintenanceTaskListOperationMaterialDatumUpdateCacheMut       sync.RWMutex
	sapMaintenanceTaskListOperationMaterialDatumUpdateCache          = make(map[string]updateCache)
	sapMaintenanceTaskListOperationMaterialDatumUpsertCacheMut       sync.RWMutex
	sapMaintenanceTaskListOperationMaterialDatumUpsertCache          = 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 sapMaintenanceTaskListOperationMaterialDatumAfterSelectHooks []SapMaintenanceTaskListOperationMaterialDatumHook

var sapMaintenanceTaskListOperationMaterialDatumBeforeInsertHooks []SapMaintenanceTaskListOperationMaterialDatumHook
var sapMaintenanceTaskListOperationMaterialDatumAfterInsertHooks []SapMaintenanceTaskListOperationMaterialDatumHook

var sapMaintenanceTaskListOperationMaterialDatumBeforeUpdateHooks []SapMaintenanceTaskListOperationMaterialDatumHook
var sapMaintenanceTaskListOperationMaterialDatumAfterUpdateHooks []SapMaintenanceTaskListOperationMaterialDatumHook

var sapMaintenanceTaskListOperationMaterialDatumBeforeDeleteHooks []SapMaintenanceTaskListOperationMaterialDatumHook
var sapMaintenanceTaskListOperationMaterialDatumAfterDeleteHooks []SapMaintenanceTaskListOperationMaterialDatumHook

var sapMaintenanceTaskListOperationMaterialDatumBeforeUpsertHooks []SapMaintenanceTaskListOperationMaterialDatumHook
var sapMaintenanceTaskListOperationMaterialDatumAfterUpsertHooks []SapMaintenanceTaskListOperationMaterialDatumHook

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

// AddSapMaintenanceTaskListOperationMaterialDatumHook registers your hook function for all future operations.
func AddSapMaintenanceTaskListOperationMaterialDatumHook(hookPoint boil.HookPoint, sapMaintenanceTaskListOperationMaterialDatumHook SapMaintenanceTaskListOperationMaterialDatumHook) {
	switch hookPoint {
	case boil.AfterSelectHook:
		sapMaintenanceTaskListOperationMaterialDatumAfterSelectHooks = append(sapMaintenanceTaskListOperationMaterialDatumAfterSelectHooks, sapMaintenanceTaskListOperationMaterialDatumHook)
	case boil.BeforeInsertHook:
		sapMaintenanceTaskListOperationMaterialDatumBeforeInsertHooks = append(sapMaintenanceTaskListOperationMaterialDatumBeforeInsertHooks, sapMaintenanceTaskListOperationMaterialDatumHook)
	case boil.AfterInsertHook:
		sapMaintenanceTaskListOperationMaterialDatumAfterInsertHooks = append(sapMaintenanceTaskListOperationMaterialDatumAfterInsertHooks, sapMaintenanceTaskListOperationMaterialDatumHook)
	case boil.BeforeUpdateHook:
		sapMaintenanceTaskListOperationMaterialDatumBeforeUpdateHooks = append(sapMaintenanceTaskListOperationMaterialDatumBeforeUpdateHooks, sapMaintenanceTaskListOperationMaterialDatumHook)
	case boil.AfterUpdateHook:
		sapMaintenanceTaskListOperationMaterialDatumAfterUpdateHooks = append(sapMaintenanceTaskListOperationMaterialDatumAfterUpdateHooks, sapMaintenanceTaskListOperationMaterialDatumHook)
	case boil.BeforeDeleteHook:
		sapMaintenanceTaskListOperationMaterialDatumBeforeDeleteHooks = append(sapMaintenanceTaskListOperationMaterialDatumBeforeDeleteHooks, sapMaintenanceTaskListOperationMaterialDatumHook)
	case boil.AfterDeleteHook:
		sapMaintenanceTaskListOperationMaterialDatumAfterDeleteHooks = append(sapMaintenanceTaskListOperationMaterialDatumAfterDeleteHooks, sapMaintenanceTaskListOperationMaterialDatumHook)
	case boil.BeforeUpsertHook:
		sapMaintenanceTaskListOperationMaterialDatumBeforeUpsertHooks = append(sapMaintenanceTaskListOperationMaterialDatumBeforeUpsertHooks, sapMaintenanceTaskListOperationMaterialDatumHook)
	case boil.AfterUpsertHook:
		sapMaintenanceTaskListOperationMaterialDatumAfterUpsertHooks = append(sapMaintenanceTaskListOperationMaterialDatumAfterUpsertHooks, sapMaintenanceTaskListOperationMaterialDatumHook)
	}
}

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

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

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

	return o, nil
}

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

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

	if len(sapMaintenanceTaskListOperationMaterialDatumAfterSelectHooks) != 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 SapMaintenanceTaskListOperationMaterialDatum records in the query.
func (q sapMaintenanceTaskListOperationMaterialDatumQuery) 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 sap_maintenance_task_list_operation_material_data rows")
	}

	return count, nil
}

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

	return count > 0, nil
}

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

	return sapMaintenanceTaskListOperationMaterialDatumQuery{q}
}

// FindSapMaintenanceTaskListOperationMaterialDatum retrieves a single record by ID with an executor.
// If selectCols is empty Find will return all columns.
func FindSapMaintenanceTaskListOperationMaterialDatum(ctx context.Context, exec boil.ContextExecutor, taskListType string, taskListGroup string, taskListGroupCounter string, taskListSequence string, taskListOperationInternalID string, taskListOpBOMItmIntVersCounter string, taskListOpBOMItmInternalID string, selectCols ...string) (*SapMaintenanceTaskListOperationMaterialDatum, error) {
	sapMaintenanceTaskListOperationMaterialDatumObj := &SapMaintenanceTaskListOperationMaterialDatum{}

	sel := "*"
	if len(selectCols) > 0 {
		sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
	}
	query := fmt.Sprintf(
		"select %s from `sap_maintenance_task_list_operation_material_data` where `TaskListType`=? AND `TaskListGroup`=? AND `TaskListGroupCounter`=? AND `TaskListSequence`=? AND `TaskListOperationInternalID`=? AND `TaskListOpBOMItmIntVersCounter`=? AND `TaskListOpBOMItmInternalID`=?", sel,
	)

	q := queries.Raw(query, taskListType, taskListGroup, taskListGroupCounter, taskListSequence, taskListOperationInternalID, taskListOpBOMItmIntVersCounter, taskListOpBOMItmInternalID)

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

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

	return sapMaintenanceTaskListOperationMaterialDatumObj, nil
}

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

	var err error

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

	nzDefaults := queries.NonZeroDefaultSet(sapMaintenanceTaskListOperationMaterialDatumColumnsWithDefault, o)

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

	if !cached {
		wl, returnColumns := columns.InsertColumnSet(
			sapMaintenanceTaskListOperationMaterialDatumAllColumns,
			sapMaintenanceTaskListOperationMaterialDatumColumnsWithDefault,
			sapMaintenanceTaskListOperationMaterialDatumColumnsWithoutDefault,
			nzDefaults,
		)

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

		var queryOutput, queryReturning string

		if len(cache.retMapping) != 0 {
			cache.retQuery = fmt.Sprintf("SELECT `%s` FROM `sap_maintenance_task_list_operation_material_data` WHERE %s", strings.Join(returnColumns, "`,`"), strmangle.WhereClause("`", "`", 0, sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyColumns))
		}

		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)
	}
	_, err = exec.ExecContext(ctx, cache.query, vals...)

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

	var identifierCols []interface{}

	if len(cache.retMapping) == 0 {
		goto CacheNoHooks
	}

	identifierCols = []interface{}{
		o.TaskListType,
		o.TaskListGroup,
		o.TaskListGroupCounter,
		o.TaskListSequence,
		o.TaskListOperationInternalID,
		o.TaskListOpBOMItmIntVersCounter,
		o.TaskListOpBOMItmInternalID,
	}

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, cache.retQuery)
		fmt.Fprintln(writer, identifierCols...)
	}
	err = exec.QueryRowContext(ctx, cache.retQuery, identifierCols...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
	if err != nil {
		return errors.Wrap(err, "models: unable to populate default values for sap_maintenance_task_list_operation_material_data")
	}

CacheNoHooks:
	if !cached {
		sapMaintenanceTaskListOperationMaterialDatumInsertCacheMut.Lock()
		sapMaintenanceTaskListOperationMaterialDatumInsertCache[key] = cache
		sapMaintenanceTaskListOperationMaterialDatumInsertCacheMut.Unlock()
	}

	return o.doAfterInsertHooks(ctx, exec)
}

// Update uses an executor to update the SapMaintenanceTaskListOperationMaterialDatum.
// 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 *SapMaintenanceTaskListOperationMaterialDatum) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
	var err error
	if err = o.doBeforeUpdateHooks(ctx, exec); err != nil {
		return 0, err
	}
	key := makeCacheKey(columns, nil)
	sapMaintenanceTaskListOperationMaterialDatumUpdateCacheMut.RLock()
	cache, cached := sapMaintenanceTaskListOperationMaterialDatumUpdateCache[key]
	sapMaintenanceTaskListOperationMaterialDatumUpdateCacheMut.RUnlock()

	if !cached {
		wl := columns.UpdateColumnSet(
			sapMaintenanceTaskListOperationMaterialDatumAllColumns,
			sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyColumns,
		)

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

		cache.query = fmt.Sprintf("UPDATE `sap_maintenance_task_list_operation_material_data` SET %s WHERE %s",
			strmangle.SetParamNames("`", "`", 0, wl),
			strmangle.WhereClause("`", "`", 0, sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyColumns),
		)
		cache.valueMapping, err = queries.BindMapping(sapMaintenanceTaskListOperationMaterialDatumType, sapMaintenanceTaskListOperationMaterialDatumMapping, append(wl, sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyColumns...))
		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 sap_maintenance_task_list_operation_material_data row")
	}

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

	if !cached {
		sapMaintenanceTaskListOperationMaterialDatumUpdateCacheMut.Lock()
		sapMaintenanceTaskListOperationMaterialDatumUpdateCache[key] = cache
		sapMaintenanceTaskListOperationMaterialDatumUpdateCacheMut.Unlock()
	}

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

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

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

	return rowsAff, nil
}

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

	sql := fmt.Sprintf("UPDATE `sap_maintenance_task_list_operation_material_data` SET %s WHERE %s",
		strmangle.SetParamNames("`", "`", 0, colNames),
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyColumns, 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 sapMaintenanceTaskListOperationMaterialDatum slice")
	}

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

var mySQLSapMaintenanceTaskListOperationMaterialDatumUniqueColumns = []string{}

// 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 *SapMaintenanceTaskListOperationMaterialDatum) Upsert(ctx context.Context, exec boil.ContextExecutor, updateColumns, insertColumns boil.Columns) error {
	if o == nil {
		return errors.New("models: no sap_maintenance_task_list_operation_material_data provided for upsert")
	}

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

	nzDefaults := queries.NonZeroDefaultSet(sapMaintenanceTaskListOperationMaterialDatumColumnsWithDefault, o)
	nzUniques := queries.NonZeroDefaultSet(mySQLSapMaintenanceTaskListOperationMaterialDatumUniqueColumns, o)

	if len(nzUniques) == 0 {
		return errors.New("cannot upsert with a table that cannot conflict on a unique column")
	}

	// Build cache key in-line uglily - mysql vs psql problems
	buf := strmangle.GetBuffer()
	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)
	}
	buf.WriteByte('.')
	for _, c := range nzUniques {
		buf.WriteString(c)
	}
	key := buf.String()
	strmangle.PutBuffer(buf)

	sapMaintenanceTaskListOperationMaterialDatumUpsertCacheMut.RLock()
	cache, cached := sapMaintenanceTaskListOperationMaterialDatumUpsertCache[key]
	sapMaintenanceTaskListOperationMaterialDatumUpsertCacheMut.RUnlock()

	var err error

	if !cached {
		insert, ret := insertColumns.InsertColumnSet(
			sapMaintenanceTaskListOperationMaterialDatumAllColumns,
			sapMaintenanceTaskListOperationMaterialDatumColumnsWithDefault,
			sapMaintenanceTaskListOperationMaterialDatumColumnsWithoutDefault,
			nzDefaults,
		)

		update := updateColumns.UpdateColumnSet(
			sapMaintenanceTaskListOperationMaterialDatumAllColumns,
			sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyColumns,
		)

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

		ret = strmangle.SetComplement(ret, nzUniques)
		cache.query = buildUpsertQueryMySQL(dialect, "`sap_maintenance_task_list_operation_material_data`", update, insert)
		cache.retQuery = fmt.Sprintf(
			"SELECT %s FROM `sap_maintenance_task_list_operation_material_data` WHERE %s",
			strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, ret), ","),
			strmangle.WhereClause("`", "`", 0, nzUniques),
		)

		cache.valueMapping, err = queries.BindMapping(sapMaintenanceTaskListOperationMaterialDatumType, sapMaintenanceTaskListOperationMaterialDatumMapping, insert)
		if err != nil {
			return err
		}
		if len(ret) != 0 {
			cache.retMapping, err = queries.BindMapping(sapMaintenanceTaskListOperationMaterialDatumType, sapMaintenanceTaskListOperationMaterialDatumMapping, 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)
	}
	_, err = exec.ExecContext(ctx, cache.query, vals...)

	if err != nil {
		return errors.Wrap(err, "models: unable to upsert for sap_maintenance_task_list_operation_material_data")
	}

	var uniqueMap []uint64
	var nzUniqueCols []interface{}

	if len(cache.retMapping) == 0 {
		goto CacheNoHooks
	}

	uniqueMap, err = queries.BindMapping(sapMaintenanceTaskListOperationMaterialDatumType, sapMaintenanceTaskListOperationMaterialDatumMapping, nzUniques)
	if err != nil {
		return errors.Wrap(err, "models: unable to retrieve unique values for sap_maintenance_task_list_operation_material_data")
	}
	nzUniqueCols = queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), uniqueMap)

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, cache.retQuery)
		fmt.Fprintln(writer, nzUniqueCols...)
	}
	err = exec.QueryRowContext(ctx, cache.retQuery, nzUniqueCols...).Scan(returns...)
	if err != nil {
		return errors.Wrap(err, "models: unable to populate default values for sap_maintenance_task_list_operation_material_data")
	}

CacheNoHooks:
	if !cached {
		sapMaintenanceTaskListOperationMaterialDatumUpsertCacheMut.Lock()
		sapMaintenanceTaskListOperationMaterialDatumUpsertCache[key] = cache
		sapMaintenanceTaskListOperationMaterialDatumUpsertCacheMut.Unlock()
	}

	return o.doAfterUpsertHooks(ctx, exec)
}

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

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

	args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyMapping)
	sql := "DELETE FROM `sap_maintenance_task_list_operation_material_data` WHERE `TaskListType`=? AND `TaskListGroup`=? AND `TaskListGroupCounter`=? AND `TaskListSequence`=? AND `TaskListOperationInternalID`=? AND `TaskListOpBOMItmIntVersCounter`=? AND `TaskListOpBOMItmInternalID`=?"

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

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

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

	return rowsAff, nil
}

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

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

	return rowsAff, nil
}

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

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

	sql := "DELETE FROM `sap_maintenance_task_list_operation_material_data` WHERE " +
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyColumns, 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 sapMaintenanceTaskListOperationMaterialDatum slice")
	}

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

	if len(sapMaintenanceTaskListOperationMaterialDatumAfterDeleteHooks) != 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 *SapMaintenanceTaskListOperationMaterialDatum) Reload(ctx context.Context, exec boil.ContextExecutor) error {
	ret, err := FindSapMaintenanceTaskListOperationMaterialDatum(ctx, exec, o.TaskListType, o.TaskListGroup, o.TaskListGroupCounter, o.TaskListSequence, o.TaskListOperationInternalID, o.TaskListOpBOMItmIntVersCounter, o.TaskListOpBOMItmInternalID)
	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 *SapMaintenanceTaskListOperationMaterialDatumSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
	if o == nil || len(*o) == 0 {
		return nil
	}

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

	sql := "SELECT `sap_maintenance_task_list_operation_material_data`.* FROM `sap_maintenance_task_list_operation_material_data` WHERE " +
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, sapMaintenanceTaskListOperationMaterialDatumPrimaryKeyColumns, 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 SapMaintenanceTaskListOperationMaterialDatumSlice")
	}

	*o = slice

	return nil
}

// SapMaintenanceTaskListOperationMaterialDatumExists checks if the SapMaintenanceTaskListOperationMaterialDatum row exists.
func SapMaintenanceTaskListOperationMaterialDatumExists(ctx context.Context, exec boil.ContextExecutor, taskListType string, taskListGroup string, taskListGroupCounter string, taskListSequence string, taskListOperationInternalID string, taskListOpBOMItmIntVersCounter string, taskListOpBOMItmInternalID string) (bool, error) {
	var exists bool
	sql := "select exists(select 1 from `sap_maintenance_task_list_operation_material_data` where `TaskListType`=? AND `TaskListGroup`=? AND `TaskListGroupCounter`=? AND `TaskListSequence`=? AND `TaskListOperationInternalID`=? AND `TaskListOpBOMItmIntVersCounter`=? AND `TaskListOpBOMItmInternalID`=? limit 1)"

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, sql)
		fmt.Fprintln(writer, taskListType, taskListGroup, taskListGroupCounter, taskListSequence, taskListOperationInternalID, taskListOpBOMItmIntVersCounter, taskListOpBOMItmInternalID)
	}
	row := exec.QueryRowContext(ctx, sql, taskListType, taskListGroup, taskListGroupCounter, taskListSequence, taskListOperationInternalID, taskListOpBOMItmIntVersCounter, taskListOpBOMItmInternalID)

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

	return exists, nil
}
