From 60f4b241f4db7d9725f6cc886d3047d5b6682ee9 Mon Sep 17 00:00:00 2001 From: Alva Zhang Date: Wed, 16 Aug 2023 17:22:47 -0700 Subject: [PATCH] =?UTF-8?q?=E2=80=9Crebase=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrations/00021_bom.sql | 36 + internal/models/aoc_mac_address_bom.go | 1117 ++++++++++++++++ internal/models/aoc_mac_address_bom_test.go | 841 ++++++++++++ internal/models/attributes.go | 47 - internal/models/bmc_mac_address_bom.go | 1070 ++++++++++++++++ internal/models/bmc_mac_address_bom_test.go | 841 ++++++++++++ internal/models/boil_suites_test.go | 62 + internal/models/boil_table_names.go | 6 + internal/models/bom_info.go | 1276 +++++++++++++++++++ internal/models/bom_info_test.go | 1039 +++++++++++++++ internal/models/crdb_suites_test.go | 3 + 11 files changed, 6291 insertions(+), 47 deletions(-) create mode 100644 db/migrations/00021_bom.sql create mode 100644 internal/models/aoc_mac_address_bom.go create mode 100644 internal/models/aoc_mac_address_bom_test.go create mode 100644 internal/models/bmc_mac_address_bom.go create mode 100644 internal/models/bmc_mac_address_bom_test.go create mode 100644 internal/models/bom_info.go create mode 100644 internal/models/bom_info_test.go diff --git a/db/migrations/00021_bom.sql b/db/migrations/00021_bom.sql new file mode 100644 index 00000000..a59a0421 --- /dev/null +++ b/db/migrations/00021_bom.sql @@ -0,0 +1,36 @@ +-- +goose Up +-- +goose StatementBegin + +CREATE TABLE bom_info ( + id UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(), + serial_num STRING NULL, + aoc_mac_address STRING NULL, + bmc_mac_address STRING NULL, + num_defi_pmi STRING NULL, + num_def_pwd STRING NULL, + metro String NULL +); + +CREATE TABLE aoc_mac_address_bom ( + id UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(), + aoc_mac_address STRING NULL, + bom_info_id UUID NOT NULL REFERENCES bom_info(id) ON DELETE CASCADE +); + +CREATE TABLE bmc_mac_address_bom ( + id UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(), + bmc_mac_address STRING NULL, + bom_info_id UUID NOT NULL REFERENCES bom_info(id) ON DELETE CASCADE +); + + +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin + +DROP TABLE bom_info; +DROP TABLE aoc_mac_address_bom; +DROP TABLE bmc_mac_address_bom; + +-- +goose StatementEnd \ No newline at end of file diff --git a/internal/models/aoc_mac_address_bom.go b/internal/models/aoc_mac_address_bom.go new file mode 100644 index 00000000..872ad882 --- /dev/null +++ b/internal/models/aoc_mac_address_bom.go @@ -0,0 +1,1117 @@ +// 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" +) + +// AocMacAddressBom is an object representing the database table. +type AocMacAddressBom struct { + ID string `boil:"id" json:"id" toml:"id" yaml:"id"` + AocMacAddress null.String `boil:"aoc_mac_address" json:"aoc_mac_address,omitempty" toml:"aoc_mac_address" yaml:"aoc_mac_address,omitempty"` + BomInfoID string `boil:"bom_info_id" json:"bom_info_id" toml:"bom_info_id" yaml:"bom_info_id"` + + R *aocMacAddressBomR `boil:"-" json:"-" toml:"-" yaml:"-"` + L aocMacAddressBomL `boil:"-" json:"-" toml:"-" yaml:"-"` +} + +var AocMacAddressBomColumns = struct { + ID string + AocMacAddress string + BomInfoID string +}{ + ID: "id", + AocMacAddress: "aoc_mac_address", + BomInfoID: "bom_info_id", +} + +var AocMacAddressBomTableColumns = struct { + ID string + AocMacAddress string + BomInfoID string +}{ + ID: "aoc_mac_address_bom.id", + AocMacAddress: "aoc_mac_address_bom.aoc_mac_address", + BomInfoID: "aoc_mac_address_bom.bom_info_id", +} + +// Generated where + +type whereHelperstring struct{ field string } + +func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } +func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } +func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } +func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } +func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } +func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) IN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelperstring) NIN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} + +type whereHelpernull_String struct{ field string } + +func (w whereHelpernull_String) EQ(x null.String) qm.QueryMod { + return qmhelper.WhereNullEQ(w.field, false, x) +} +func (w whereHelpernull_String) NEQ(x null.String) qm.QueryMod { + return qmhelper.WhereNullEQ(w.field, true, x) +} +func (w whereHelpernull_String) LT(x null.String) qm.QueryMod { + return qmhelper.Where(w.field, qmhelper.LT, x) +} +func (w whereHelpernull_String) LTE(x null.String) qm.QueryMod { + return qmhelper.Where(w.field, qmhelper.LTE, x) +} +func (w whereHelpernull_String) GT(x null.String) qm.QueryMod { + return qmhelper.Where(w.field, qmhelper.GT, x) +} +func (w whereHelpernull_String) GTE(x null.String) qm.QueryMod { + return qmhelper.Where(w.field, qmhelper.GTE, x) +} + +func (w whereHelpernull_String) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } +func (w whereHelpernull_String) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } + +var AocMacAddressBomWhere = struct { + ID whereHelperstring + AocMacAddress whereHelpernull_String + BomInfoID whereHelperstring +}{ + ID: whereHelperstring{field: "\"aoc_mac_address_bom\".\"id\""}, + AocMacAddress: whereHelpernull_String{field: "\"aoc_mac_address_bom\".\"aoc_mac_address\""}, + BomInfoID: whereHelperstring{field: "\"aoc_mac_address_bom\".\"bom_info_id\""}, +} + +// AocMacAddressBomRels is where relationship names are stored. +var AocMacAddressBomRels = struct { + BomInfo string +}{ + BomInfo: "BomInfo", +} + +// aocMacAddressBomR is where relationships are stored. +type aocMacAddressBomR struct { + BomInfo *BomInfo `boil:"BomInfo" json:"BomInfo" toml:"BomInfo" yaml:"BomInfo"` +} + +// NewStruct creates a new relationship struct +func (*aocMacAddressBomR) NewStruct() *aocMacAddressBomR { + return &aocMacAddressBomR{} +} + +func (r *aocMacAddressBomR) GetBomInfo() *BomInfo { + if r == nil { + return nil + } + return r.BomInfo +} + +// aocMacAddressBomL is where Load methods for each relationship are stored. +type aocMacAddressBomL struct{} + +var ( + aocMacAddressBomAllColumns = []string{"id", "aoc_mac_address", "bom_info_id"} + aocMacAddressBomColumnsWithoutDefault = []string{"bom_info_id"} + aocMacAddressBomColumnsWithDefault = []string{"id", "aoc_mac_address"} + aocMacAddressBomPrimaryKeyColumns = []string{"id"} + aocMacAddressBomGeneratedColumns = []string{} +) + +type ( + // AocMacAddressBomSlice is an alias for a slice of pointers to AocMacAddressBom. + // This should almost always be used instead of []AocMacAddressBom. + AocMacAddressBomSlice []*AocMacAddressBom + // AocMacAddressBomHook is the signature for custom AocMacAddressBom hook methods + AocMacAddressBomHook func(context.Context, boil.ContextExecutor, *AocMacAddressBom) error + + aocMacAddressBomQuery struct { + *queries.Query + } +) + +// Cache for insert, update and upsert +var ( + aocMacAddressBomType = reflect.TypeOf(&AocMacAddressBom{}) + aocMacAddressBomMapping = queries.MakeStructMapping(aocMacAddressBomType) + aocMacAddressBomPrimaryKeyMapping, _ = queries.BindMapping(aocMacAddressBomType, aocMacAddressBomMapping, aocMacAddressBomPrimaryKeyColumns) + aocMacAddressBomInsertCacheMut sync.RWMutex + aocMacAddressBomInsertCache = make(map[string]insertCache) + aocMacAddressBomUpdateCacheMut sync.RWMutex + aocMacAddressBomUpdateCache = make(map[string]updateCache) + aocMacAddressBomUpsertCacheMut sync.RWMutex + aocMacAddressBomUpsertCache = 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 aocMacAddressBomAfterSelectHooks []AocMacAddressBomHook + +var aocMacAddressBomBeforeInsertHooks []AocMacAddressBomHook +var aocMacAddressBomAfterInsertHooks []AocMacAddressBomHook + +var aocMacAddressBomBeforeUpdateHooks []AocMacAddressBomHook +var aocMacAddressBomAfterUpdateHooks []AocMacAddressBomHook + +var aocMacAddressBomBeforeDeleteHooks []AocMacAddressBomHook +var aocMacAddressBomAfterDeleteHooks []AocMacAddressBomHook + +var aocMacAddressBomBeforeUpsertHooks []AocMacAddressBomHook +var aocMacAddressBomAfterUpsertHooks []AocMacAddressBomHook + +// doAfterSelectHooks executes all "after Select" hooks. +func (o *AocMacAddressBom) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range aocMacAddressBomAfterSelectHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeInsertHooks executes all "before insert" hooks. +func (o *AocMacAddressBom) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range aocMacAddressBomBeforeInsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterInsertHooks executes all "after Insert" hooks. +func (o *AocMacAddressBom) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range aocMacAddressBomAfterInsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeUpdateHooks executes all "before Update" hooks. +func (o *AocMacAddressBom) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range aocMacAddressBomBeforeUpdateHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterUpdateHooks executes all "after Update" hooks. +func (o *AocMacAddressBom) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range aocMacAddressBomAfterUpdateHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeDeleteHooks executes all "before Delete" hooks. +func (o *AocMacAddressBom) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range aocMacAddressBomBeforeDeleteHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterDeleteHooks executes all "after Delete" hooks. +func (o *AocMacAddressBom) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range aocMacAddressBomAfterDeleteHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeUpsertHooks executes all "before Upsert" hooks. +func (o *AocMacAddressBom) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range aocMacAddressBomBeforeUpsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterUpsertHooks executes all "after Upsert" hooks. +func (o *AocMacAddressBom) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range aocMacAddressBomAfterUpsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// AddAocMacAddressBomHook registers your hook function for all future operations. +func AddAocMacAddressBomHook(hookPoint boil.HookPoint, aocMacAddressBomHook AocMacAddressBomHook) { + switch hookPoint { + case boil.AfterSelectHook: + aocMacAddressBomAfterSelectHooks = append(aocMacAddressBomAfterSelectHooks, aocMacAddressBomHook) + case boil.BeforeInsertHook: + aocMacAddressBomBeforeInsertHooks = append(aocMacAddressBomBeforeInsertHooks, aocMacAddressBomHook) + case boil.AfterInsertHook: + aocMacAddressBomAfterInsertHooks = append(aocMacAddressBomAfterInsertHooks, aocMacAddressBomHook) + case boil.BeforeUpdateHook: + aocMacAddressBomBeforeUpdateHooks = append(aocMacAddressBomBeforeUpdateHooks, aocMacAddressBomHook) + case boil.AfterUpdateHook: + aocMacAddressBomAfterUpdateHooks = append(aocMacAddressBomAfterUpdateHooks, aocMacAddressBomHook) + case boil.BeforeDeleteHook: + aocMacAddressBomBeforeDeleteHooks = append(aocMacAddressBomBeforeDeleteHooks, aocMacAddressBomHook) + case boil.AfterDeleteHook: + aocMacAddressBomAfterDeleteHooks = append(aocMacAddressBomAfterDeleteHooks, aocMacAddressBomHook) + case boil.BeforeUpsertHook: + aocMacAddressBomBeforeUpsertHooks = append(aocMacAddressBomBeforeUpsertHooks, aocMacAddressBomHook) + case boil.AfterUpsertHook: + aocMacAddressBomAfterUpsertHooks = append(aocMacAddressBomAfterUpsertHooks, aocMacAddressBomHook) + } +} + +// One returns a single aocMacAddressBom record from the query. +func (q aocMacAddressBomQuery) One(ctx context.Context, exec boil.ContextExecutor) (*AocMacAddressBom, error) { + o := &AocMacAddressBom{} + + 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 aoc_mac_address_bom") + } + + if err := o.doAfterSelectHooks(ctx, exec); err != nil { + return o, err + } + + return o, nil +} + +// All returns all AocMacAddressBom records from the query. +func (q aocMacAddressBomQuery) All(ctx context.Context, exec boil.ContextExecutor) (AocMacAddressBomSlice, error) { + var o []*AocMacAddressBom + + err := q.Bind(ctx, exec, &o) + if err != nil { + return nil, errors.Wrap(err, "models: failed to assign all query results to AocMacAddressBom slice") + } + + if len(aocMacAddressBomAfterSelectHooks) != 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 AocMacAddressBom records in the query. +func (q aocMacAddressBomQuery) 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 aoc_mac_address_bom rows") + } + + return count, nil +} + +// Exists checks if the row exists in the table. +func (q aocMacAddressBomQuery) 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 aoc_mac_address_bom exists") + } + + return count > 0, nil +} + +// BomInfo pointed to by the foreign key. +func (o *AocMacAddressBom) BomInfo(mods ...qm.QueryMod) bomInfoQuery { + queryMods := []qm.QueryMod{ + qm.Where("\"id\" = ?", o.BomInfoID), + } + + queryMods = append(queryMods, mods...) + + return BomInfos(queryMods...) +} + +// LoadBomInfo allows an eager lookup of values, cached into the +// loaded structs of the objects. This is for an N-1 relationship. +func (aocMacAddressBomL) LoadBomInfo(ctx context.Context, e boil.ContextExecutor, singular bool, maybeAocMacAddressBom interface{}, mods queries.Applicator) error { + var slice []*AocMacAddressBom + var object *AocMacAddressBom + + if singular { + object = maybeAocMacAddressBom.(*AocMacAddressBom) + } else { + slice = *maybeAocMacAddressBom.(*[]*AocMacAddressBom) + } + + args := make([]interface{}, 0, 1) + if singular { + if object.R == nil { + object.R = &aocMacAddressBomR{} + } + args = append(args, object.BomInfoID) + + } else { + Outer: + for _, obj := range slice { + if obj.R == nil { + obj.R = &aocMacAddressBomR{} + } + + for _, a := range args { + if a == obj.BomInfoID { + continue Outer + } + } + + args = append(args, obj.BomInfoID) + + } + } + + if len(args) == 0 { + return nil + } + + query := NewQuery( + qm.From(`bom_info`), + qm.WhereIn(`bom_info.id in ?`, args...), + ) + if mods != nil { + mods.Apply(query) + } + + results, err := query.QueryContext(ctx, e) + if err != nil { + return errors.Wrap(err, "failed to eager load BomInfo") + } + + var resultSlice []*BomInfo + if err = queries.Bind(results, &resultSlice); err != nil { + return errors.Wrap(err, "failed to bind eager loaded slice BomInfo") + } + + if err = results.Close(); err != nil { + return errors.Wrap(err, "failed to close results of eager load for bom_info") + } + if err = results.Err(); err != nil { + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for bom_info") + } + + if len(aocMacAddressBomAfterSelectHooks) != 0 { + for _, obj := range resultSlice { + if err := obj.doAfterSelectHooks(ctx, e); err != nil { + return err + } + } + } + + if len(resultSlice) == 0 { + return nil + } + + if singular { + foreign := resultSlice[0] + object.R.BomInfo = foreign + if foreign.R == nil { + foreign.R = &bomInfoR{} + } + foreign.R.AocMacAddressBoms = append(foreign.R.AocMacAddressBoms, object) + return nil + } + + for _, local := range slice { + for _, foreign := range resultSlice { + if local.BomInfoID == foreign.ID { + local.R.BomInfo = foreign + if foreign.R == nil { + foreign.R = &bomInfoR{} + } + foreign.R.AocMacAddressBoms = append(foreign.R.AocMacAddressBoms, local) + break + } + } + } + + return nil +} + +// SetBomInfo of the aocMacAddressBom to the related item. +// Sets o.R.BomInfo to related. +// Adds o to related.R.AocMacAddressBoms. +func (o *AocMacAddressBom) SetBomInfo(ctx context.Context, exec boil.ContextExecutor, insert bool, related *BomInfo) error { + var err error + if insert { + if err = related.Insert(ctx, exec, boil.Infer()); err != nil { + return errors.Wrap(err, "failed to insert into foreign table") + } + } + + updateQuery := fmt.Sprintf( + "UPDATE \"aoc_mac_address_bom\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, []string{"bom_info_id"}), + strmangle.WhereClause("\"", "\"", 2, aocMacAddressBomPrimaryKeyColumns), + ) + values := []interface{}{related.ID, o.ID} + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) + } + if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { + return errors.Wrap(err, "failed to update local table") + } + + o.BomInfoID = related.ID + if o.R == nil { + o.R = &aocMacAddressBomR{ + BomInfo: related, + } + } else { + o.R.BomInfo = related + } + + if related.R == nil { + related.R = &bomInfoR{ + AocMacAddressBoms: AocMacAddressBomSlice{o}, + } + } else { + related.R.AocMacAddressBoms = append(related.R.AocMacAddressBoms, o) + } + + return nil +} + +// AocMacAddressBoms retrieves all the records using an executor. +func AocMacAddressBoms(mods ...qm.QueryMod) aocMacAddressBomQuery { + mods = append(mods, qm.From("\"aoc_mac_address_bom\"")) + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"aoc_mac_address_bom\".*"}) + } + + return aocMacAddressBomQuery{q} +} + +// FindAocMacAddressBom retrieves a single record by ID with an executor. +// If selectCols is empty Find will return all columns. +func FindAocMacAddressBom(ctx context.Context, exec boil.ContextExecutor, iD string, selectCols ...string) (*AocMacAddressBom, error) { + aocMacAddressBomObj := &AocMacAddressBom{} + + sel := "*" + if len(selectCols) > 0 { + sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",") + } + query := fmt.Sprintf( + "select %s from \"aoc_mac_address_bom\" where \"id\"=$1", sel, + ) + + q := queries.Raw(query, iD) + + err := q.Bind(ctx, exec, aocMacAddressBomObj) + if err != nil { + if errors.Is(err, sql.ErrNoRows) { + return nil, sql.ErrNoRows + } + return nil, errors.Wrap(err, "models: unable to select from aoc_mac_address_bom") + } + + if err = aocMacAddressBomObj.doAfterSelectHooks(ctx, exec); err != nil { + return aocMacAddressBomObj, err + } + + return aocMacAddressBomObj, nil +} + +// Insert a single record using an executor. +// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts. +func (o *AocMacAddressBom) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error { + if o == nil { + return errors.New("models: no aoc_mac_address_bom provided for insertion") + } + + var err error + + if err := o.doBeforeInsertHooks(ctx, exec); err != nil { + return err + } + + nzDefaults := queries.NonZeroDefaultSet(aocMacAddressBomColumnsWithDefault, o) + + key := makeCacheKey(columns, nzDefaults) + aocMacAddressBomInsertCacheMut.RLock() + cache, cached := aocMacAddressBomInsertCache[key] + aocMacAddressBomInsertCacheMut.RUnlock() + + if !cached { + wl, returnColumns := columns.InsertColumnSet( + aocMacAddressBomAllColumns, + aocMacAddressBomColumnsWithDefault, + aocMacAddressBomColumnsWithoutDefault, + nzDefaults, + ) + + cache.valueMapping, err = queries.BindMapping(aocMacAddressBomType, aocMacAddressBomMapping, wl) + if err != nil { + return err + } + cache.retMapping, err = queries.BindMapping(aocMacAddressBomType, aocMacAddressBomMapping, returnColumns) + if err != nil { + return err + } + if len(wl) != 0 { + cache.query = fmt.Sprintf("INSERT INTO \"aoc_mac_address_bom\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1)) + } else { + cache.query = "INSERT INTO \"aoc_mac_address_bom\" %sDEFAULT VALUES%s" + } + + var queryOutput, queryReturning string + + if len(cache.retMapping) != 0 { + queryReturning = fmt.Sprintf(" RETURNING \"%s\"", strings.Join(returnColumns, "\",\"")) + } + + cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning) + } + + value := reflect.Indirect(reflect.ValueOf(o)) + vals := queries.ValuesFromMapping(value, cache.valueMapping) + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) + } + + if len(cache.retMapping) != 0 { + err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...) + } else { + _, err = exec.ExecContext(ctx, cache.query, vals...) + } + + if err != nil { + return errors.Wrap(err, "models: unable to insert into aoc_mac_address_bom") + } + + if !cached { + aocMacAddressBomInsertCacheMut.Lock() + aocMacAddressBomInsertCache[key] = cache + aocMacAddressBomInsertCacheMut.Unlock() + } + + return o.doAfterInsertHooks(ctx, exec) +} + +// Update uses an executor to update the AocMacAddressBom. +// 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 *AocMacAddressBom) 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) + aocMacAddressBomUpdateCacheMut.RLock() + cache, cached := aocMacAddressBomUpdateCache[key] + aocMacAddressBomUpdateCacheMut.RUnlock() + + if !cached { + wl := columns.UpdateColumnSet( + aocMacAddressBomAllColumns, + aocMacAddressBomPrimaryKeyColumns, + ) + + if !columns.IsWhitelist() { + wl = strmangle.SetComplement(wl, []string{"created_at"}) + } + if len(wl) == 0 { + return 0, errors.New("models: unable to update aoc_mac_address_bom, could not build whitelist") + } + + cache.query = fmt.Sprintf("UPDATE \"aoc_mac_address_bom\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, wl), + strmangle.WhereClause("\"", "\"", len(wl)+1, aocMacAddressBomPrimaryKeyColumns), + ) + cache.valueMapping, err = queries.BindMapping(aocMacAddressBomType, aocMacAddressBomMapping, append(wl, aocMacAddressBomPrimaryKeyColumns...)) + 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 aoc_mac_address_bom row") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: failed to get rows affected by update for aoc_mac_address_bom") + } + + if !cached { + aocMacAddressBomUpdateCacheMut.Lock() + aocMacAddressBomUpdateCache[key] = cache + aocMacAddressBomUpdateCacheMut.Unlock() + } + + return rowsAff, o.doAfterUpdateHooks(ctx, exec) +} + +// UpdateAll updates all rows with the specified column values. +func (q aocMacAddressBomQuery) 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 aoc_mac_address_bom") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for aoc_mac_address_bom") + } + + return rowsAff, nil +} + +// UpdateAll updates all rows with the specified column values, using an executor. +func (o AocMacAddressBomSlice) 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)), aocMacAddressBomPrimaryKeyMapping) + args = append(args, pkeyArgs...) + } + + sql := fmt.Sprintf("UPDATE \"aoc_mac_address_bom\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, colNames), + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, aocMacAddressBomPrimaryKeyColumns, 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 aocMacAddressBom slice") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all aocMacAddressBom") + } + return rowsAff, nil +} + +// Delete deletes a single AocMacAddressBom record with an executor. +// Delete will match against the primary key column to find the record to delete. +func (o *AocMacAddressBom) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) { + if o == nil { + return 0, errors.New("models: no AocMacAddressBom provided for delete") + } + + if err := o.doBeforeDeleteHooks(ctx, exec); err != nil { + return 0, err + } + + args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), aocMacAddressBomPrimaryKeyMapping) + sql := "DELETE FROM \"aoc_mac_address_bom\" WHERE \"id\"=$1" + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) + } + result, err := exec.ExecContext(ctx, sql, args...) + if err != nil { + return 0, errors.Wrap(err, "models: unable to delete from aoc_mac_address_bom") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for aoc_mac_address_bom") + } + + if err := o.doAfterDeleteHooks(ctx, exec); err != nil { + return 0, err + } + + return rowsAff, nil +} + +// DeleteAll deletes all matching rows. +func (q aocMacAddressBomQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { + if q.Query == nil { + return 0, errors.New("models: no aocMacAddressBomQuery 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 aoc_mac_address_bom") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for aoc_mac_address_bom") + } + + return rowsAff, nil +} + +// DeleteAll deletes all rows in the slice, using an executor. +func (o AocMacAddressBomSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { + if len(o) == 0 { + return 0, nil + } + + if len(aocMacAddressBomBeforeDeleteHooks) != 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)), aocMacAddressBomPrimaryKeyMapping) + args = append(args, pkeyArgs...) + } + + sql := "DELETE FROM \"aoc_mac_address_bom\" WHERE " + + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, aocMacAddressBomPrimaryKeyColumns, 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 aocMacAddressBom slice") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for aoc_mac_address_bom") + } + + if len(aocMacAddressBomAfterDeleteHooks) != 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 *AocMacAddressBom) Reload(ctx context.Context, exec boil.ContextExecutor) error { + ret, err := FindAocMacAddressBom(ctx, exec, o.ID) + if err != nil { + return err + } + + *o = *ret + return nil +} + +// ReloadAll refetches every row with matching primary key column values +// and overwrites the original object slice with the newly updated slice. +func (o *AocMacAddressBomSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error { + if o == nil || len(*o) == 0 { + return nil + } + + slice := AocMacAddressBomSlice{} + var args []interface{} + for _, obj := range *o { + pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), aocMacAddressBomPrimaryKeyMapping) + args = append(args, pkeyArgs...) + } + + sql := "SELECT \"aoc_mac_address_bom\".* FROM \"aoc_mac_address_bom\" WHERE " + + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, aocMacAddressBomPrimaryKeyColumns, 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 AocMacAddressBomSlice") + } + + *o = slice + + return nil +} + +// AocMacAddressBomExists checks if the AocMacAddressBom row exists. +func AocMacAddressBomExists(ctx context.Context, exec boil.ContextExecutor, iD string) (bool, error) { + var exists bool + sql := "select exists(select 1 from \"aoc_mac_address_bom\" where \"id\"=$1 limit 1)" + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) + } + row := exec.QueryRowContext(ctx, sql, iD) + + err := row.Scan(&exists) + if err != nil { + return false, errors.Wrap(err, "models: unable to check if aoc_mac_address_bom exists") + } + + return exists, nil +} + +// Upsert attempts an insert using an executor, and does an update or ignore on conflict. +// See boil.Columns documentation for how to properly use updateColumns and insertColumns. +func (o *AocMacAddressBom) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { + if o == nil { + return errors.New("models: no aoc_mac_address_bom provided for upsert") + } + + if err := o.doBeforeUpsertHooks(ctx, exec); err != nil { + return err + } + + nzDefaults := queries.NonZeroDefaultSet(aocMacAddressBomColumnsWithDefault, o) + + // Build cache key in-line uglily - mysql vs psql problems + buf := strmangle.GetBuffer() + if updateOnConflict { + buf.WriteByte('t') + } else { + buf.WriteByte('f') + } + buf.WriteByte('.') + for _, c := range conflictColumns { + buf.WriteString(c) + } + buf.WriteByte('.') + buf.WriteString(strconv.Itoa(updateColumns.Kind)) + for _, c := range updateColumns.Cols { + buf.WriteString(c) + } + buf.WriteByte('.') + buf.WriteString(strconv.Itoa(insertColumns.Kind)) + for _, c := range insertColumns.Cols { + buf.WriteString(c) + } + buf.WriteByte('.') + for _, c := range nzDefaults { + buf.WriteString(c) + } + key := buf.String() + strmangle.PutBuffer(buf) + + aocMacAddressBomUpsertCacheMut.RLock() + cache, cached := aocMacAddressBomUpsertCache[key] + aocMacAddressBomUpsertCacheMut.RUnlock() + + var err error + + if !cached { + insert, ret := insertColumns.InsertColumnSet( + aocMacAddressBomAllColumns, + aocMacAddressBomColumnsWithDefault, + aocMacAddressBomColumnsWithoutDefault, + nzDefaults, + ) + update := updateColumns.UpdateColumnSet( + aocMacAddressBomAllColumns, + aocMacAddressBomPrimaryKeyColumns, + ) + + if updateOnConflict && len(update) == 0 { + return errors.New("models: unable to upsert aoc_mac_address_bom, could not build update column list") + } + + conflict := conflictColumns + if len(conflict) == 0 { + conflict = make([]string, len(aocMacAddressBomPrimaryKeyColumns)) + copy(conflict, aocMacAddressBomPrimaryKeyColumns) + } + cache.query = buildUpsertQueryCockroachDB(dialect, "\"aoc_mac_address_bom\"", updateOnConflict, ret, update, conflict, insert) + + cache.valueMapping, err = queries.BindMapping(aocMacAddressBomType, aocMacAddressBomMapping, insert) + if err != nil { + return err + } + if len(ret) != 0 { + cache.retMapping, err = queries.BindMapping(aocMacAddressBomType, aocMacAddressBomMapping, ret) + if err != nil { + return err + } + } + } + + value := reflect.Indirect(reflect.ValueOf(o)) + vals := queries.ValuesFromMapping(value, cache.valueMapping) + var returns []interface{} + if len(cache.retMapping) != 0 { + returns = queries.PtrsFromMapping(value, cache.retMapping) + } + + if boil.DebugMode { + _, _ = fmt.Fprintln(boil.DebugWriter, cache.query) + _, _ = fmt.Fprintln(boil.DebugWriter, vals) + } + + if len(cache.retMapping) != 0 { + err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) + if err == sql.ErrNoRows { + err = nil // CockcorachDB doesn't return anything when there's no update + } + } else { + _, err = exec.ExecContext(ctx, cache.query, vals...) + } + if err != nil { + return errors.Wrap(err, "models: unable to upsert aoc_mac_address_bom") + } + + if !cached { + aocMacAddressBomUpsertCacheMut.Lock() + aocMacAddressBomUpsertCache[key] = cache + aocMacAddressBomUpsertCacheMut.Unlock() + } + + return o.doAfterUpsertHooks(ctx, exec) +} diff --git a/internal/models/aoc_mac_address_bom_test.go b/internal/models/aoc_mac_address_bom_test.go new file mode 100644 index 00000000..56a8e0d7 --- /dev/null +++ b/internal/models/aoc_mac_address_bom_test.go @@ -0,0 +1,841 @@ +// 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 ( + "bytes" + "context" + "reflect" + "testing" + + "github.com/volatiletech/randomize" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/strmangle" +) + +func testAocMacAddressBomsUpsert(t *testing.T) { + t.Parallel() + + if len(aocMacAddressBomAllColumns) == len(aocMacAddressBomPrimaryKeyColumns) { + t.Skip("Skipping table with only primary key columns") + } + + seed := randomize.NewSeed() + var err error + // Attempt the INSERT side of an UPSERT + o := AocMacAddressBom{} + if err = randomize.Struct(seed, &o, aocMacAddressBomDBTypes, true); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Upsert(ctx, tx, false, nil, boil.Infer(), boil.Infer()); err != nil { + t.Errorf("Unable to upsert AocMacAddressBom: %s", err) + } + + count, err := AocMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + if count != 1 { + t.Error("want one record, got:", count) + } + + // Attempt the UPDATE side of an UPSERT + if err = randomize.Struct(seed, &o, aocMacAddressBomDBTypes, false, aocMacAddressBomPrimaryKeyColumns...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + + if err = o.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer()); err != nil { + t.Errorf("Unable to upsert AocMacAddressBom: %s", err) + } + + count, err = AocMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + if count != 1 { + t.Error("want one record, got:", count) + } +} + +var ( + // Relationships sometimes use the reflection helper queries.Equal/queries.Assign + // so force a package dependency in case they don't. + _ = queries.Equal +) + +func testAocMacAddressBoms(t *testing.T) { + t.Parallel() + + query := AocMacAddressBoms() + + if query.Query == nil { + t.Error("expected a query, got nothing") + } +} + +func testAocMacAddressBomsDelete(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &AocMacAddressBom{} + if err = randomize.Struct(seed, o, aocMacAddressBomDBTypes, true, aocMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + if rowsAff, err := o.Delete(ctx, tx); err != nil { + t.Error(err) + } else if rowsAff != 1 { + t.Error("should only have deleted one row, but affected:", rowsAff) + } + + count, err := AocMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 0 { + t.Error("want zero records, got:", count) + } +} + +func testAocMacAddressBomsQueryDeleteAll(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &AocMacAddressBom{} + if err = randomize.Struct(seed, o, aocMacAddressBomDBTypes, true, aocMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + if rowsAff, err := AocMacAddressBoms().DeleteAll(ctx, tx); err != nil { + t.Error(err) + } else if rowsAff != 1 { + t.Error("should only have deleted one row, but affected:", rowsAff) + } + + count, err := AocMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 0 { + t.Error("want zero records, got:", count) + } +} + +func testAocMacAddressBomsSliceDeleteAll(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &AocMacAddressBom{} + if err = randomize.Struct(seed, o, aocMacAddressBomDBTypes, true, aocMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + slice := AocMacAddressBomSlice{o} + + if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil { + t.Error(err) + } else if rowsAff != 1 { + t.Error("should only have deleted one row, but affected:", rowsAff) + } + + count, err := AocMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 0 { + t.Error("want zero records, got:", count) + } +} + +func testAocMacAddressBomsExists(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &AocMacAddressBom{} + if err = randomize.Struct(seed, o, aocMacAddressBomDBTypes, true, aocMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + e, err := AocMacAddressBomExists(ctx, tx, o.ID) + if err != nil { + t.Errorf("Unable to check if AocMacAddressBom exists: %s", err) + } + if !e { + t.Errorf("Expected AocMacAddressBomExists to return true, but got false.") + } +} + +func testAocMacAddressBomsFind(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &AocMacAddressBom{} + if err = randomize.Struct(seed, o, aocMacAddressBomDBTypes, true, aocMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + aocMacAddressBomFound, err := FindAocMacAddressBom(ctx, tx, o.ID) + if err != nil { + t.Error(err) + } + + if aocMacAddressBomFound == nil { + t.Error("want a record, got nil") + } +} + +func testAocMacAddressBomsBind(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &AocMacAddressBom{} + if err = randomize.Struct(seed, o, aocMacAddressBomDBTypes, true, aocMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + if err = AocMacAddressBoms().Bind(ctx, tx, o); err != nil { + t.Error(err) + } +} + +func testAocMacAddressBomsOne(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &AocMacAddressBom{} + if err = randomize.Struct(seed, o, aocMacAddressBomDBTypes, true, aocMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + if x, err := AocMacAddressBoms().One(ctx, tx); err != nil { + t.Error(err) + } else if x == nil { + t.Error("expected to get a non nil record") + } +} + +func testAocMacAddressBomsAll(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + aocMacAddressBomOne := &AocMacAddressBom{} + aocMacAddressBomTwo := &AocMacAddressBom{} + if err = randomize.Struct(seed, aocMacAddressBomOne, aocMacAddressBomDBTypes, false, aocMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + if err = randomize.Struct(seed, aocMacAddressBomTwo, aocMacAddressBomDBTypes, false, aocMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = aocMacAddressBomOne.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + if err = aocMacAddressBomTwo.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + slice, err := AocMacAddressBoms().All(ctx, tx) + if err != nil { + t.Error(err) + } + + if len(slice) != 2 { + t.Error("want 2 records, got:", len(slice)) + } +} + +func testAocMacAddressBomsCount(t *testing.T) { + t.Parallel() + + var err error + seed := randomize.NewSeed() + aocMacAddressBomOne := &AocMacAddressBom{} + aocMacAddressBomTwo := &AocMacAddressBom{} + if err = randomize.Struct(seed, aocMacAddressBomOne, aocMacAddressBomDBTypes, false, aocMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + if err = randomize.Struct(seed, aocMacAddressBomTwo, aocMacAddressBomDBTypes, false, aocMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = aocMacAddressBomOne.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + if err = aocMacAddressBomTwo.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + count, err := AocMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 2 { + t.Error("want 2 records, got:", count) + } +} + +func aocMacAddressBomBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *AocMacAddressBom) error { + *o = AocMacAddressBom{} + return nil +} + +func aocMacAddressBomAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *AocMacAddressBom) error { + *o = AocMacAddressBom{} + return nil +} + +func aocMacAddressBomAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *AocMacAddressBom) error { + *o = AocMacAddressBom{} + return nil +} + +func aocMacAddressBomBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *AocMacAddressBom) error { + *o = AocMacAddressBom{} + return nil +} + +func aocMacAddressBomAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *AocMacAddressBom) error { + *o = AocMacAddressBom{} + return nil +} + +func aocMacAddressBomBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *AocMacAddressBom) error { + *o = AocMacAddressBom{} + return nil +} + +func aocMacAddressBomAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *AocMacAddressBom) error { + *o = AocMacAddressBom{} + return nil +} + +func aocMacAddressBomBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *AocMacAddressBom) error { + *o = AocMacAddressBom{} + return nil +} + +func aocMacAddressBomAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *AocMacAddressBom) error { + *o = AocMacAddressBom{} + return nil +} + +func testAocMacAddressBomsHooks(t *testing.T) { + t.Parallel() + + var err error + + ctx := context.Background() + empty := &AocMacAddressBom{} + o := &AocMacAddressBom{} + + seed := randomize.NewSeed() + if err = randomize.Struct(seed, o, aocMacAddressBomDBTypes, false); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom object: %s", err) + } + + AddAocMacAddressBomHook(boil.BeforeInsertHook, aocMacAddressBomBeforeInsertHook) + if err = o.doBeforeInsertHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doBeforeInsertHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected BeforeInsertHook function to empty object, but got: %#v", o) + } + aocMacAddressBomBeforeInsertHooks = []AocMacAddressBomHook{} + + AddAocMacAddressBomHook(boil.AfterInsertHook, aocMacAddressBomAfterInsertHook) + if err = o.doAfterInsertHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doAfterInsertHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected AfterInsertHook function to empty object, but got: %#v", o) + } + aocMacAddressBomAfterInsertHooks = []AocMacAddressBomHook{} + + AddAocMacAddressBomHook(boil.AfterSelectHook, aocMacAddressBomAfterSelectHook) + if err = o.doAfterSelectHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doAfterSelectHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected AfterSelectHook function to empty object, but got: %#v", o) + } + aocMacAddressBomAfterSelectHooks = []AocMacAddressBomHook{} + + AddAocMacAddressBomHook(boil.BeforeUpdateHook, aocMacAddressBomBeforeUpdateHook) + if err = o.doBeforeUpdateHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doBeforeUpdateHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected BeforeUpdateHook function to empty object, but got: %#v", o) + } + aocMacAddressBomBeforeUpdateHooks = []AocMacAddressBomHook{} + + AddAocMacAddressBomHook(boil.AfterUpdateHook, aocMacAddressBomAfterUpdateHook) + if err = o.doAfterUpdateHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doAfterUpdateHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected AfterUpdateHook function to empty object, but got: %#v", o) + } + aocMacAddressBomAfterUpdateHooks = []AocMacAddressBomHook{} + + AddAocMacAddressBomHook(boil.BeforeDeleteHook, aocMacAddressBomBeforeDeleteHook) + if err = o.doBeforeDeleteHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doBeforeDeleteHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected BeforeDeleteHook function to empty object, but got: %#v", o) + } + aocMacAddressBomBeforeDeleteHooks = []AocMacAddressBomHook{} + + AddAocMacAddressBomHook(boil.AfterDeleteHook, aocMacAddressBomAfterDeleteHook) + if err = o.doAfterDeleteHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doAfterDeleteHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected AfterDeleteHook function to empty object, but got: %#v", o) + } + aocMacAddressBomAfterDeleteHooks = []AocMacAddressBomHook{} + + AddAocMacAddressBomHook(boil.BeforeUpsertHook, aocMacAddressBomBeforeUpsertHook) + if err = o.doBeforeUpsertHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doBeforeUpsertHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected BeforeUpsertHook function to empty object, but got: %#v", o) + } + aocMacAddressBomBeforeUpsertHooks = []AocMacAddressBomHook{} + + AddAocMacAddressBomHook(boil.AfterUpsertHook, aocMacAddressBomAfterUpsertHook) + if err = o.doAfterUpsertHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doAfterUpsertHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected AfterUpsertHook function to empty object, but got: %#v", o) + } + aocMacAddressBomAfterUpsertHooks = []AocMacAddressBomHook{} +} + +func testAocMacAddressBomsInsert(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &AocMacAddressBom{} + if err = randomize.Struct(seed, o, aocMacAddressBomDBTypes, true, aocMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + count, err := AocMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 1 { + t.Error("want one record, got:", count) + } +} + +func testAocMacAddressBomsInsertWhitelist(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &AocMacAddressBom{} + if err = randomize.Struct(seed, o, aocMacAddressBomDBTypes, true); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Whitelist(aocMacAddressBomColumnsWithoutDefault...)); err != nil { + t.Error(err) + } + + count, err := AocMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 1 { + t.Error("want one record, got:", count) + } +} + +func testAocMacAddressBomToOneBomInfoUsingBomInfo(t *testing.T) { + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + + var local AocMacAddressBom + var foreign BomInfo + + seed := randomize.NewSeed() + if err := randomize.Struct(seed, &local, aocMacAddressBomDBTypes, false, aocMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + if err := randomize.Struct(seed, &foreign, bomInfoDBTypes, false, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + + local.BomInfoID = foreign.ID + if err := local.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + + check, err := local.BomInfo().One(ctx, tx) + if err != nil { + t.Fatal(err) + } + + if check.ID != foreign.ID { + t.Errorf("want: %v, got %v", foreign.ID, check.ID) + } + + slice := AocMacAddressBomSlice{&local} + if err = local.L.LoadBomInfo(ctx, tx, false, (*[]*AocMacAddressBom)(&slice), nil); err != nil { + t.Fatal(err) + } + if local.R.BomInfo == nil { + t.Error("struct should have been eager loaded") + } + + local.R.BomInfo = nil + if err = local.L.LoadBomInfo(ctx, tx, true, &local, nil); err != nil { + t.Fatal(err) + } + if local.R.BomInfo == nil { + t.Error("struct should have been eager loaded") + } +} + +func testAocMacAddressBomToOneSetOpBomInfoUsingBomInfo(t *testing.T) { + var err error + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + + var a AocMacAddressBom + var b, c BomInfo + + seed := randomize.NewSeed() + if err = randomize.Struct(seed, &a, aocMacAddressBomDBTypes, false, strmangle.SetComplement(aocMacAddressBomPrimaryKeyColumns, aocMacAddressBomColumnsWithoutDefault)...); err != nil { + t.Fatal(err) + } + if err = randomize.Struct(seed, &b, bomInfoDBTypes, false, strmangle.SetComplement(bomInfoPrimaryKeyColumns, bomInfoColumnsWithoutDefault)...); err != nil { + t.Fatal(err) + } + if err = randomize.Struct(seed, &c, bomInfoDBTypes, false, strmangle.SetComplement(bomInfoPrimaryKeyColumns, bomInfoColumnsWithoutDefault)...); err != nil { + t.Fatal(err) + } + + if err := a.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + if err = b.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + + for i, x := range []*BomInfo{&b, &c} { + err = a.SetBomInfo(ctx, tx, i != 0, x) + if err != nil { + t.Fatal(err) + } + + if a.R.BomInfo != x { + t.Error("relationship struct not set to correct value") + } + + if x.R.AocMacAddressBoms[0] != &a { + t.Error("failed to append to foreign relationship struct") + } + if a.BomInfoID != x.ID { + t.Error("foreign key was wrong value", a.BomInfoID) + } + + zero := reflect.Zero(reflect.TypeOf(a.BomInfoID)) + reflect.Indirect(reflect.ValueOf(&a.BomInfoID)).Set(zero) + + if err = a.Reload(ctx, tx); err != nil { + t.Fatal("failed to reload", err) + } + + if a.BomInfoID != x.ID { + t.Error("foreign key was wrong value", a.BomInfoID, x.ID) + } + } +} + +func testAocMacAddressBomsReload(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &AocMacAddressBom{} + if err = randomize.Struct(seed, o, aocMacAddressBomDBTypes, true, aocMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + if err = o.Reload(ctx, tx); err != nil { + t.Error(err) + } +} + +func testAocMacAddressBomsReloadAll(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &AocMacAddressBom{} + if err = randomize.Struct(seed, o, aocMacAddressBomDBTypes, true, aocMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + slice := AocMacAddressBomSlice{o} + + if err = slice.ReloadAll(ctx, tx); err != nil { + t.Error(err) + } +} + +func testAocMacAddressBomsSelect(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &AocMacAddressBom{} + if err = randomize.Struct(seed, o, aocMacAddressBomDBTypes, true, aocMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + slice, err := AocMacAddressBoms().All(ctx, tx) + if err != nil { + t.Error(err) + } + + if len(slice) != 1 { + t.Error("want one record, got:", len(slice)) + } +} + +var ( + aocMacAddressBomDBTypes = map[string]string{`ID`: `uuid`, `AocMacAddress`: `string`, `BomInfoID`: `uuid`} + _ = bytes.MinRead +) + +func testAocMacAddressBomsUpdate(t *testing.T) { + t.Parallel() + + if 0 == len(aocMacAddressBomPrimaryKeyColumns) { + t.Skip("Skipping table with no primary key columns") + } + if len(aocMacAddressBomAllColumns) == len(aocMacAddressBomPrimaryKeyColumns) { + t.Skip("Skipping table with only primary key columns") + } + + seed := randomize.NewSeed() + var err error + o := &AocMacAddressBom{} + if err = randomize.Struct(seed, o, aocMacAddressBomDBTypes, true, aocMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + count, err := AocMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 1 { + t.Error("want one record, got:", count) + } + + if err = randomize.Struct(seed, o, aocMacAddressBomDBTypes, true, aocMacAddressBomPrimaryKeyColumns...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + + if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } else if rowsAff != 1 { + t.Error("should only affect one row but affected", rowsAff) + } +} + +func testAocMacAddressBomsSliceUpdateAll(t *testing.T) { + t.Parallel() + + if len(aocMacAddressBomAllColumns) == len(aocMacAddressBomPrimaryKeyColumns) { + t.Skip("Skipping table with only primary key columns") + } + + seed := randomize.NewSeed() + var err error + o := &AocMacAddressBom{} + if err = randomize.Struct(seed, o, aocMacAddressBomDBTypes, true, aocMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + count, err := AocMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 1 { + t.Error("want one record, got:", count) + } + + if err = randomize.Struct(seed, o, aocMacAddressBomDBTypes, true, aocMacAddressBomPrimaryKeyColumns...); err != nil { + t.Errorf("Unable to randomize AocMacAddressBom struct: %s", err) + } + + // Remove Primary keys and unique columns from what we plan to update + var fields []string + if strmangle.StringSliceMatch(aocMacAddressBomAllColumns, aocMacAddressBomPrimaryKeyColumns) { + fields = aocMacAddressBomAllColumns + } else { + fields = strmangle.SetComplement( + aocMacAddressBomAllColumns, + aocMacAddressBomPrimaryKeyColumns, + ) + } + + value := reflect.Indirect(reflect.ValueOf(o)) + typ := reflect.TypeOf(o).Elem() + n := typ.NumField() + + updateMap := M{} + for _, col := range fields { + for i := 0; i < n; i++ { + f := typ.Field(i) + if f.Tag.Get("boil") == col { + updateMap[col] = value.Field(i).Interface() + } + } + } + + slice := AocMacAddressBomSlice{o} + if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil { + t.Error(err) + } else if rowsAff != 1 { + t.Error("wanted one record updated but got", rowsAff) + } +} diff --git a/internal/models/attributes.go b/internal/models/attributes.go index 91c933a7..765fa389 100644 --- a/internal/models/attributes.go +++ b/internal/models/attributes.go @@ -75,53 +75,6 @@ var AttributeTableColumns = struct { // Generated where -type whereHelperstring struct{ field string } - -func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } -func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } -func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } -func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } -func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } -func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } -func (w whereHelperstring) IN(slice []string) qm.QueryMod { - values := make([]interface{}, 0, len(slice)) - for _, value := range slice { - values = append(values, value) - } - return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) -} -func (w whereHelperstring) NIN(slice []string) qm.QueryMod { - values := make([]interface{}, 0, len(slice)) - for _, value := range slice { - values = append(values, value) - } - return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) -} - -type whereHelpernull_String struct{ field string } - -func (w whereHelpernull_String) EQ(x null.String) qm.QueryMod { - return qmhelper.WhereNullEQ(w.field, false, x) -} -func (w whereHelpernull_String) NEQ(x null.String) qm.QueryMod { - return qmhelper.WhereNullEQ(w.field, true, x) -} -func (w whereHelpernull_String) LT(x null.String) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.LT, x) -} -func (w whereHelpernull_String) LTE(x null.String) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.LTE, x) -} -func (w whereHelpernull_String) GT(x null.String) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.GT, x) -} -func (w whereHelpernull_String) GTE(x null.String) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.GTE, x) -} - -func (w whereHelpernull_String) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_String) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } - type whereHelpertypes_JSON struct{ field string } func (w whereHelpertypes_JSON) EQ(x types.JSON) qm.QueryMod { diff --git a/internal/models/bmc_mac_address_bom.go b/internal/models/bmc_mac_address_bom.go new file mode 100644 index 00000000..97ff225d --- /dev/null +++ b/internal/models/bmc_mac_address_bom.go @@ -0,0 +1,1070 @@ +// 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" +) + +// BMCMacAddressBom is an object representing the database table. +type BMCMacAddressBom struct { + ID string `boil:"id" json:"id" toml:"id" yaml:"id"` + BMCMacAddress null.String `boil:"bmc_mac_address" json:"bmc_mac_address,omitempty" toml:"bmc_mac_address" yaml:"bmc_mac_address,omitempty"` + BomInfoID string `boil:"bom_info_id" json:"bom_info_id" toml:"bom_info_id" yaml:"bom_info_id"` + + R *bmcMacAddressBomR `boil:"-" json:"-" toml:"-" yaml:"-"` + L bmcMacAddressBomL `boil:"-" json:"-" toml:"-" yaml:"-"` +} + +var BMCMacAddressBomColumns = struct { + ID string + BMCMacAddress string + BomInfoID string +}{ + ID: "id", + BMCMacAddress: "bmc_mac_address", + BomInfoID: "bom_info_id", +} + +var BMCMacAddressBomTableColumns = struct { + ID string + BMCMacAddress string + BomInfoID string +}{ + ID: "bmc_mac_address_bom.id", + BMCMacAddress: "bmc_mac_address_bom.bmc_mac_address", + BomInfoID: "bmc_mac_address_bom.bom_info_id", +} + +// Generated where + +var BMCMacAddressBomWhere = struct { + ID whereHelperstring + BMCMacAddress whereHelpernull_String + BomInfoID whereHelperstring +}{ + ID: whereHelperstring{field: "\"bmc_mac_address_bom\".\"id\""}, + BMCMacAddress: whereHelpernull_String{field: "\"bmc_mac_address_bom\".\"bmc_mac_address\""}, + BomInfoID: whereHelperstring{field: "\"bmc_mac_address_bom\".\"bom_info_id\""}, +} + +// BMCMacAddressBomRels is where relationship names are stored. +var BMCMacAddressBomRels = struct { + BomInfo string +}{ + BomInfo: "BomInfo", +} + +// bmcMacAddressBomR is where relationships are stored. +type bmcMacAddressBomR struct { + BomInfo *BomInfo `boil:"BomInfo" json:"BomInfo" toml:"BomInfo" yaml:"BomInfo"` +} + +// NewStruct creates a new relationship struct +func (*bmcMacAddressBomR) NewStruct() *bmcMacAddressBomR { + return &bmcMacAddressBomR{} +} + +func (r *bmcMacAddressBomR) GetBomInfo() *BomInfo { + if r == nil { + return nil + } + return r.BomInfo +} + +// bmcMacAddressBomL is where Load methods for each relationship are stored. +type bmcMacAddressBomL struct{} + +var ( + bmcMacAddressBomAllColumns = []string{"id", "bmc_mac_address", "bom_info_id"} + bmcMacAddressBomColumnsWithoutDefault = []string{"bom_info_id"} + bmcMacAddressBomColumnsWithDefault = []string{"id", "bmc_mac_address"} + bmcMacAddressBomPrimaryKeyColumns = []string{"id"} + bmcMacAddressBomGeneratedColumns = []string{} +) + +type ( + // BMCMacAddressBomSlice is an alias for a slice of pointers to BMCMacAddressBom. + // This should almost always be used instead of []BMCMacAddressBom. + BMCMacAddressBomSlice []*BMCMacAddressBom + // BMCMacAddressBomHook is the signature for custom BMCMacAddressBom hook methods + BMCMacAddressBomHook func(context.Context, boil.ContextExecutor, *BMCMacAddressBom) error + + bmcMacAddressBomQuery struct { + *queries.Query + } +) + +// Cache for insert, update and upsert +var ( + bmcMacAddressBomType = reflect.TypeOf(&BMCMacAddressBom{}) + bmcMacAddressBomMapping = queries.MakeStructMapping(bmcMacAddressBomType) + bmcMacAddressBomPrimaryKeyMapping, _ = queries.BindMapping(bmcMacAddressBomType, bmcMacAddressBomMapping, bmcMacAddressBomPrimaryKeyColumns) + bmcMacAddressBomInsertCacheMut sync.RWMutex + bmcMacAddressBomInsertCache = make(map[string]insertCache) + bmcMacAddressBomUpdateCacheMut sync.RWMutex + bmcMacAddressBomUpdateCache = make(map[string]updateCache) + bmcMacAddressBomUpsertCacheMut sync.RWMutex + bmcMacAddressBomUpsertCache = 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 bmcMacAddressBomAfterSelectHooks []BMCMacAddressBomHook + +var bmcMacAddressBomBeforeInsertHooks []BMCMacAddressBomHook +var bmcMacAddressBomAfterInsertHooks []BMCMacAddressBomHook + +var bmcMacAddressBomBeforeUpdateHooks []BMCMacAddressBomHook +var bmcMacAddressBomAfterUpdateHooks []BMCMacAddressBomHook + +var bmcMacAddressBomBeforeDeleteHooks []BMCMacAddressBomHook +var bmcMacAddressBomAfterDeleteHooks []BMCMacAddressBomHook + +var bmcMacAddressBomBeforeUpsertHooks []BMCMacAddressBomHook +var bmcMacAddressBomAfterUpsertHooks []BMCMacAddressBomHook + +// doAfterSelectHooks executes all "after Select" hooks. +func (o *BMCMacAddressBom) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range bmcMacAddressBomAfterSelectHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeInsertHooks executes all "before insert" hooks. +func (o *BMCMacAddressBom) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range bmcMacAddressBomBeforeInsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterInsertHooks executes all "after Insert" hooks. +func (o *BMCMacAddressBom) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range bmcMacAddressBomAfterInsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeUpdateHooks executes all "before Update" hooks. +func (o *BMCMacAddressBom) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range bmcMacAddressBomBeforeUpdateHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterUpdateHooks executes all "after Update" hooks. +func (o *BMCMacAddressBom) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range bmcMacAddressBomAfterUpdateHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeDeleteHooks executes all "before Delete" hooks. +func (o *BMCMacAddressBom) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range bmcMacAddressBomBeforeDeleteHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterDeleteHooks executes all "after Delete" hooks. +func (o *BMCMacAddressBom) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range bmcMacAddressBomAfterDeleteHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeUpsertHooks executes all "before Upsert" hooks. +func (o *BMCMacAddressBom) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range bmcMacAddressBomBeforeUpsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterUpsertHooks executes all "after Upsert" hooks. +func (o *BMCMacAddressBom) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range bmcMacAddressBomAfterUpsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// AddBMCMacAddressBomHook registers your hook function for all future operations. +func AddBMCMacAddressBomHook(hookPoint boil.HookPoint, bmcMacAddressBomHook BMCMacAddressBomHook) { + switch hookPoint { + case boil.AfterSelectHook: + bmcMacAddressBomAfterSelectHooks = append(bmcMacAddressBomAfterSelectHooks, bmcMacAddressBomHook) + case boil.BeforeInsertHook: + bmcMacAddressBomBeforeInsertHooks = append(bmcMacAddressBomBeforeInsertHooks, bmcMacAddressBomHook) + case boil.AfterInsertHook: + bmcMacAddressBomAfterInsertHooks = append(bmcMacAddressBomAfterInsertHooks, bmcMacAddressBomHook) + case boil.BeforeUpdateHook: + bmcMacAddressBomBeforeUpdateHooks = append(bmcMacAddressBomBeforeUpdateHooks, bmcMacAddressBomHook) + case boil.AfterUpdateHook: + bmcMacAddressBomAfterUpdateHooks = append(bmcMacAddressBomAfterUpdateHooks, bmcMacAddressBomHook) + case boil.BeforeDeleteHook: + bmcMacAddressBomBeforeDeleteHooks = append(bmcMacAddressBomBeforeDeleteHooks, bmcMacAddressBomHook) + case boil.AfterDeleteHook: + bmcMacAddressBomAfterDeleteHooks = append(bmcMacAddressBomAfterDeleteHooks, bmcMacAddressBomHook) + case boil.BeforeUpsertHook: + bmcMacAddressBomBeforeUpsertHooks = append(bmcMacAddressBomBeforeUpsertHooks, bmcMacAddressBomHook) + case boil.AfterUpsertHook: + bmcMacAddressBomAfterUpsertHooks = append(bmcMacAddressBomAfterUpsertHooks, bmcMacAddressBomHook) + } +} + +// One returns a single bmcMacAddressBom record from the query. +func (q bmcMacAddressBomQuery) One(ctx context.Context, exec boil.ContextExecutor) (*BMCMacAddressBom, error) { + o := &BMCMacAddressBom{} + + 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 bmc_mac_address_bom") + } + + if err := o.doAfterSelectHooks(ctx, exec); err != nil { + return o, err + } + + return o, nil +} + +// All returns all BMCMacAddressBom records from the query. +func (q bmcMacAddressBomQuery) All(ctx context.Context, exec boil.ContextExecutor) (BMCMacAddressBomSlice, error) { + var o []*BMCMacAddressBom + + err := q.Bind(ctx, exec, &o) + if err != nil { + return nil, errors.Wrap(err, "models: failed to assign all query results to BMCMacAddressBom slice") + } + + if len(bmcMacAddressBomAfterSelectHooks) != 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 BMCMacAddressBom records in the query. +func (q bmcMacAddressBomQuery) 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 bmc_mac_address_bom rows") + } + + return count, nil +} + +// Exists checks if the row exists in the table. +func (q bmcMacAddressBomQuery) 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 bmc_mac_address_bom exists") + } + + return count > 0, nil +} + +// BomInfo pointed to by the foreign key. +func (o *BMCMacAddressBom) BomInfo(mods ...qm.QueryMod) bomInfoQuery { + queryMods := []qm.QueryMod{ + qm.Where("\"id\" = ?", o.BomInfoID), + } + + queryMods = append(queryMods, mods...) + + return BomInfos(queryMods...) +} + +// LoadBomInfo allows an eager lookup of values, cached into the +// loaded structs of the objects. This is for an N-1 relationship. +func (bmcMacAddressBomL) LoadBomInfo(ctx context.Context, e boil.ContextExecutor, singular bool, maybeBMCMacAddressBom interface{}, mods queries.Applicator) error { + var slice []*BMCMacAddressBom + var object *BMCMacAddressBom + + if singular { + object = maybeBMCMacAddressBom.(*BMCMacAddressBom) + } else { + slice = *maybeBMCMacAddressBom.(*[]*BMCMacAddressBom) + } + + args := make([]interface{}, 0, 1) + if singular { + if object.R == nil { + object.R = &bmcMacAddressBomR{} + } + args = append(args, object.BomInfoID) + + } else { + Outer: + for _, obj := range slice { + if obj.R == nil { + obj.R = &bmcMacAddressBomR{} + } + + for _, a := range args { + if a == obj.BomInfoID { + continue Outer + } + } + + args = append(args, obj.BomInfoID) + + } + } + + if len(args) == 0 { + return nil + } + + query := NewQuery( + qm.From(`bom_info`), + qm.WhereIn(`bom_info.id in ?`, args...), + ) + if mods != nil { + mods.Apply(query) + } + + results, err := query.QueryContext(ctx, e) + if err != nil { + return errors.Wrap(err, "failed to eager load BomInfo") + } + + var resultSlice []*BomInfo + if err = queries.Bind(results, &resultSlice); err != nil { + return errors.Wrap(err, "failed to bind eager loaded slice BomInfo") + } + + if err = results.Close(); err != nil { + return errors.Wrap(err, "failed to close results of eager load for bom_info") + } + if err = results.Err(); err != nil { + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for bom_info") + } + + if len(bmcMacAddressBomAfterSelectHooks) != 0 { + for _, obj := range resultSlice { + if err := obj.doAfterSelectHooks(ctx, e); err != nil { + return err + } + } + } + + if len(resultSlice) == 0 { + return nil + } + + if singular { + foreign := resultSlice[0] + object.R.BomInfo = foreign + if foreign.R == nil { + foreign.R = &bomInfoR{} + } + foreign.R.BMCMacAddressBoms = append(foreign.R.BMCMacAddressBoms, object) + return nil + } + + for _, local := range slice { + for _, foreign := range resultSlice { + if local.BomInfoID == foreign.ID { + local.R.BomInfo = foreign + if foreign.R == nil { + foreign.R = &bomInfoR{} + } + foreign.R.BMCMacAddressBoms = append(foreign.R.BMCMacAddressBoms, local) + break + } + } + } + + return nil +} + +// SetBomInfo of the bmcMacAddressBom to the related item. +// Sets o.R.BomInfo to related. +// Adds o to related.R.BMCMacAddressBoms. +func (o *BMCMacAddressBom) SetBomInfo(ctx context.Context, exec boil.ContextExecutor, insert bool, related *BomInfo) error { + var err error + if insert { + if err = related.Insert(ctx, exec, boil.Infer()); err != nil { + return errors.Wrap(err, "failed to insert into foreign table") + } + } + + updateQuery := fmt.Sprintf( + "UPDATE \"bmc_mac_address_bom\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, []string{"bom_info_id"}), + strmangle.WhereClause("\"", "\"", 2, bmcMacAddressBomPrimaryKeyColumns), + ) + values := []interface{}{related.ID, o.ID} + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) + } + if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { + return errors.Wrap(err, "failed to update local table") + } + + o.BomInfoID = related.ID + if o.R == nil { + o.R = &bmcMacAddressBomR{ + BomInfo: related, + } + } else { + o.R.BomInfo = related + } + + if related.R == nil { + related.R = &bomInfoR{ + BMCMacAddressBoms: BMCMacAddressBomSlice{o}, + } + } else { + related.R.BMCMacAddressBoms = append(related.R.BMCMacAddressBoms, o) + } + + return nil +} + +// BMCMacAddressBoms retrieves all the records using an executor. +func BMCMacAddressBoms(mods ...qm.QueryMod) bmcMacAddressBomQuery { + mods = append(mods, qm.From("\"bmc_mac_address_bom\"")) + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"bmc_mac_address_bom\".*"}) + } + + return bmcMacAddressBomQuery{q} +} + +// FindBMCMacAddressBom retrieves a single record by ID with an executor. +// If selectCols is empty Find will return all columns. +func FindBMCMacAddressBom(ctx context.Context, exec boil.ContextExecutor, iD string, selectCols ...string) (*BMCMacAddressBom, error) { + bmcMacAddressBomObj := &BMCMacAddressBom{} + + sel := "*" + if len(selectCols) > 0 { + sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",") + } + query := fmt.Sprintf( + "select %s from \"bmc_mac_address_bom\" where \"id\"=$1", sel, + ) + + q := queries.Raw(query, iD) + + err := q.Bind(ctx, exec, bmcMacAddressBomObj) + if err != nil { + if errors.Is(err, sql.ErrNoRows) { + return nil, sql.ErrNoRows + } + return nil, errors.Wrap(err, "models: unable to select from bmc_mac_address_bom") + } + + if err = bmcMacAddressBomObj.doAfterSelectHooks(ctx, exec); err != nil { + return bmcMacAddressBomObj, err + } + + return bmcMacAddressBomObj, nil +} + +// Insert a single record using an executor. +// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts. +func (o *BMCMacAddressBom) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error { + if o == nil { + return errors.New("models: no bmc_mac_address_bom provided for insertion") + } + + var err error + + if err := o.doBeforeInsertHooks(ctx, exec); err != nil { + return err + } + + nzDefaults := queries.NonZeroDefaultSet(bmcMacAddressBomColumnsWithDefault, o) + + key := makeCacheKey(columns, nzDefaults) + bmcMacAddressBomInsertCacheMut.RLock() + cache, cached := bmcMacAddressBomInsertCache[key] + bmcMacAddressBomInsertCacheMut.RUnlock() + + if !cached { + wl, returnColumns := columns.InsertColumnSet( + bmcMacAddressBomAllColumns, + bmcMacAddressBomColumnsWithDefault, + bmcMacAddressBomColumnsWithoutDefault, + nzDefaults, + ) + + cache.valueMapping, err = queries.BindMapping(bmcMacAddressBomType, bmcMacAddressBomMapping, wl) + if err != nil { + return err + } + cache.retMapping, err = queries.BindMapping(bmcMacAddressBomType, bmcMacAddressBomMapping, returnColumns) + if err != nil { + return err + } + if len(wl) != 0 { + cache.query = fmt.Sprintf("INSERT INTO \"bmc_mac_address_bom\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1)) + } else { + cache.query = "INSERT INTO \"bmc_mac_address_bom\" %sDEFAULT VALUES%s" + } + + var queryOutput, queryReturning string + + if len(cache.retMapping) != 0 { + queryReturning = fmt.Sprintf(" RETURNING \"%s\"", strings.Join(returnColumns, "\",\"")) + } + + cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning) + } + + value := reflect.Indirect(reflect.ValueOf(o)) + vals := queries.ValuesFromMapping(value, cache.valueMapping) + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) + } + + if len(cache.retMapping) != 0 { + err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...) + } else { + _, err = exec.ExecContext(ctx, cache.query, vals...) + } + + if err != nil { + return errors.Wrap(err, "models: unable to insert into bmc_mac_address_bom") + } + + if !cached { + bmcMacAddressBomInsertCacheMut.Lock() + bmcMacAddressBomInsertCache[key] = cache + bmcMacAddressBomInsertCacheMut.Unlock() + } + + return o.doAfterInsertHooks(ctx, exec) +} + +// Update uses an executor to update the BMCMacAddressBom. +// 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 *BMCMacAddressBom) 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) + bmcMacAddressBomUpdateCacheMut.RLock() + cache, cached := bmcMacAddressBomUpdateCache[key] + bmcMacAddressBomUpdateCacheMut.RUnlock() + + if !cached { + wl := columns.UpdateColumnSet( + bmcMacAddressBomAllColumns, + bmcMacAddressBomPrimaryKeyColumns, + ) + + if !columns.IsWhitelist() { + wl = strmangle.SetComplement(wl, []string{"created_at"}) + } + if len(wl) == 0 { + return 0, errors.New("models: unable to update bmc_mac_address_bom, could not build whitelist") + } + + cache.query = fmt.Sprintf("UPDATE \"bmc_mac_address_bom\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, wl), + strmangle.WhereClause("\"", "\"", len(wl)+1, bmcMacAddressBomPrimaryKeyColumns), + ) + cache.valueMapping, err = queries.BindMapping(bmcMacAddressBomType, bmcMacAddressBomMapping, append(wl, bmcMacAddressBomPrimaryKeyColumns...)) + 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 bmc_mac_address_bom row") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: failed to get rows affected by update for bmc_mac_address_bom") + } + + if !cached { + bmcMacAddressBomUpdateCacheMut.Lock() + bmcMacAddressBomUpdateCache[key] = cache + bmcMacAddressBomUpdateCacheMut.Unlock() + } + + return rowsAff, o.doAfterUpdateHooks(ctx, exec) +} + +// UpdateAll updates all rows with the specified column values. +func (q bmcMacAddressBomQuery) 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 bmc_mac_address_bom") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for bmc_mac_address_bom") + } + + return rowsAff, nil +} + +// UpdateAll updates all rows with the specified column values, using an executor. +func (o BMCMacAddressBomSlice) 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)), bmcMacAddressBomPrimaryKeyMapping) + args = append(args, pkeyArgs...) + } + + sql := fmt.Sprintf("UPDATE \"bmc_mac_address_bom\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, colNames), + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, bmcMacAddressBomPrimaryKeyColumns, 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 bmcMacAddressBom slice") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all bmcMacAddressBom") + } + return rowsAff, nil +} + +// Delete deletes a single BMCMacAddressBom record with an executor. +// Delete will match against the primary key column to find the record to delete. +func (o *BMCMacAddressBom) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) { + if o == nil { + return 0, errors.New("models: no BMCMacAddressBom provided for delete") + } + + if err := o.doBeforeDeleteHooks(ctx, exec); err != nil { + return 0, err + } + + args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), bmcMacAddressBomPrimaryKeyMapping) + sql := "DELETE FROM \"bmc_mac_address_bom\" WHERE \"id\"=$1" + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) + } + result, err := exec.ExecContext(ctx, sql, args...) + if err != nil { + return 0, errors.Wrap(err, "models: unable to delete from bmc_mac_address_bom") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for bmc_mac_address_bom") + } + + if err := o.doAfterDeleteHooks(ctx, exec); err != nil { + return 0, err + } + + return rowsAff, nil +} + +// DeleteAll deletes all matching rows. +func (q bmcMacAddressBomQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { + if q.Query == nil { + return 0, errors.New("models: no bmcMacAddressBomQuery 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 bmc_mac_address_bom") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for bmc_mac_address_bom") + } + + return rowsAff, nil +} + +// DeleteAll deletes all rows in the slice, using an executor. +func (o BMCMacAddressBomSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { + if len(o) == 0 { + return 0, nil + } + + if len(bmcMacAddressBomBeforeDeleteHooks) != 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)), bmcMacAddressBomPrimaryKeyMapping) + args = append(args, pkeyArgs...) + } + + sql := "DELETE FROM \"bmc_mac_address_bom\" WHERE " + + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, bmcMacAddressBomPrimaryKeyColumns, 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 bmcMacAddressBom slice") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for bmc_mac_address_bom") + } + + if len(bmcMacAddressBomAfterDeleteHooks) != 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 *BMCMacAddressBom) Reload(ctx context.Context, exec boil.ContextExecutor) error { + ret, err := FindBMCMacAddressBom(ctx, exec, o.ID) + if err != nil { + return err + } + + *o = *ret + return nil +} + +// ReloadAll refetches every row with matching primary key column values +// and overwrites the original object slice with the newly updated slice. +func (o *BMCMacAddressBomSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error { + if o == nil || len(*o) == 0 { + return nil + } + + slice := BMCMacAddressBomSlice{} + var args []interface{} + for _, obj := range *o { + pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), bmcMacAddressBomPrimaryKeyMapping) + args = append(args, pkeyArgs...) + } + + sql := "SELECT \"bmc_mac_address_bom\".* FROM \"bmc_mac_address_bom\" WHERE " + + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, bmcMacAddressBomPrimaryKeyColumns, 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 BMCMacAddressBomSlice") + } + + *o = slice + + return nil +} + +// BMCMacAddressBomExists checks if the BMCMacAddressBom row exists. +func BMCMacAddressBomExists(ctx context.Context, exec boil.ContextExecutor, iD string) (bool, error) { + var exists bool + sql := "select exists(select 1 from \"bmc_mac_address_bom\" where \"id\"=$1 limit 1)" + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) + } + row := exec.QueryRowContext(ctx, sql, iD) + + err := row.Scan(&exists) + if err != nil { + return false, errors.Wrap(err, "models: unable to check if bmc_mac_address_bom exists") + } + + return exists, nil +} + +// Upsert attempts an insert using an executor, and does an update or ignore on conflict. +// See boil.Columns documentation for how to properly use updateColumns and insertColumns. +func (o *BMCMacAddressBom) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { + if o == nil { + return errors.New("models: no bmc_mac_address_bom provided for upsert") + } + + if err := o.doBeforeUpsertHooks(ctx, exec); err != nil { + return err + } + + nzDefaults := queries.NonZeroDefaultSet(bmcMacAddressBomColumnsWithDefault, o) + + // Build cache key in-line uglily - mysql vs psql problems + buf := strmangle.GetBuffer() + if updateOnConflict { + buf.WriteByte('t') + } else { + buf.WriteByte('f') + } + buf.WriteByte('.') + for _, c := range conflictColumns { + buf.WriteString(c) + } + buf.WriteByte('.') + buf.WriteString(strconv.Itoa(updateColumns.Kind)) + for _, c := range updateColumns.Cols { + buf.WriteString(c) + } + buf.WriteByte('.') + buf.WriteString(strconv.Itoa(insertColumns.Kind)) + for _, c := range insertColumns.Cols { + buf.WriteString(c) + } + buf.WriteByte('.') + for _, c := range nzDefaults { + buf.WriteString(c) + } + key := buf.String() + strmangle.PutBuffer(buf) + + bmcMacAddressBomUpsertCacheMut.RLock() + cache, cached := bmcMacAddressBomUpsertCache[key] + bmcMacAddressBomUpsertCacheMut.RUnlock() + + var err error + + if !cached { + insert, ret := insertColumns.InsertColumnSet( + bmcMacAddressBomAllColumns, + bmcMacAddressBomColumnsWithDefault, + bmcMacAddressBomColumnsWithoutDefault, + nzDefaults, + ) + update := updateColumns.UpdateColumnSet( + bmcMacAddressBomAllColumns, + bmcMacAddressBomPrimaryKeyColumns, + ) + + if updateOnConflict && len(update) == 0 { + return errors.New("models: unable to upsert bmc_mac_address_bom, could not build update column list") + } + + conflict := conflictColumns + if len(conflict) == 0 { + conflict = make([]string, len(bmcMacAddressBomPrimaryKeyColumns)) + copy(conflict, bmcMacAddressBomPrimaryKeyColumns) + } + cache.query = buildUpsertQueryCockroachDB(dialect, "\"bmc_mac_address_bom\"", updateOnConflict, ret, update, conflict, insert) + + cache.valueMapping, err = queries.BindMapping(bmcMacAddressBomType, bmcMacAddressBomMapping, insert) + if err != nil { + return err + } + if len(ret) != 0 { + cache.retMapping, err = queries.BindMapping(bmcMacAddressBomType, bmcMacAddressBomMapping, ret) + if err != nil { + return err + } + } + } + + value := reflect.Indirect(reflect.ValueOf(o)) + vals := queries.ValuesFromMapping(value, cache.valueMapping) + var returns []interface{} + if len(cache.retMapping) != 0 { + returns = queries.PtrsFromMapping(value, cache.retMapping) + } + + if boil.DebugMode { + _, _ = fmt.Fprintln(boil.DebugWriter, cache.query) + _, _ = fmt.Fprintln(boil.DebugWriter, vals) + } + + if len(cache.retMapping) != 0 { + err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) + if err == sql.ErrNoRows { + err = nil // CockcorachDB doesn't return anything when there's no update + } + } else { + _, err = exec.ExecContext(ctx, cache.query, vals...) + } + if err != nil { + return errors.Wrap(err, "models: unable to upsert bmc_mac_address_bom") + } + + if !cached { + bmcMacAddressBomUpsertCacheMut.Lock() + bmcMacAddressBomUpsertCache[key] = cache + bmcMacAddressBomUpsertCacheMut.Unlock() + } + + return o.doAfterUpsertHooks(ctx, exec) +} diff --git a/internal/models/bmc_mac_address_bom_test.go b/internal/models/bmc_mac_address_bom_test.go new file mode 100644 index 00000000..bb2356f6 --- /dev/null +++ b/internal/models/bmc_mac_address_bom_test.go @@ -0,0 +1,841 @@ +// 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 ( + "bytes" + "context" + "reflect" + "testing" + + "github.com/volatiletech/randomize" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/strmangle" +) + +func testBMCMacAddressBomsUpsert(t *testing.T) { + t.Parallel() + + if len(bmcMacAddressBomAllColumns) == len(bmcMacAddressBomPrimaryKeyColumns) { + t.Skip("Skipping table with only primary key columns") + } + + seed := randomize.NewSeed() + var err error + // Attempt the INSERT side of an UPSERT + o := BMCMacAddressBom{} + if err = randomize.Struct(seed, &o, bmcMacAddressBomDBTypes, true); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Upsert(ctx, tx, false, nil, boil.Infer(), boil.Infer()); err != nil { + t.Errorf("Unable to upsert BMCMacAddressBom: %s", err) + } + + count, err := BMCMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + if count != 1 { + t.Error("want one record, got:", count) + } + + // Attempt the UPDATE side of an UPSERT + if err = randomize.Struct(seed, &o, bmcMacAddressBomDBTypes, false, bmcMacAddressBomPrimaryKeyColumns...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + + if err = o.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer()); err != nil { + t.Errorf("Unable to upsert BMCMacAddressBom: %s", err) + } + + count, err = BMCMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + if count != 1 { + t.Error("want one record, got:", count) + } +} + +var ( + // Relationships sometimes use the reflection helper queries.Equal/queries.Assign + // so force a package dependency in case they don't. + _ = queries.Equal +) + +func testBMCMacAddressBoms(t *testing.T) { + t.Parallel() + + query := BMCMacAddressBoms() + + if query.Query == nil { + t.Error("expected a query, got nothing") + } +} + +func testBMCMacAddressBomsDelete(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BMCMacAddressBom{} + if err = randomize.Struct(seed, o, bmcMacAddressBomDBTypes, true, bmcMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + if rowsAff, err := o.Delete(ctx, tx); err != nil { + t.Error(err) + } else if rowsAff != 1 { + t.Error("should only have deleted one row, but affected:", rowsAff) + } + + count, err := BMCMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 0 { + t.Error("want zero records, got:", count) + } +} + +func testBMCMacAddressBomsQueryDeleteAll(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BMCMacAddressBom{} + if err = randomize.Struct(seed, o, bmcMacAddressBomDBTypes, true, bmcMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + if rowsAff, err := BMCMacAddressBoms().DeleteAll(ctx, tx); err != nil { + t.Error(err) + } else if rowsAff != 1 { + t.Error("should only have deleted one row, but affected:", rowsAff) + } + + count, err := BMCMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 0 { + t.Error("want zero records, got:", count) + } +} + +func testBMCMacAddressBomsSliceDeleteAll(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BMCMacAddressBom{} + if err = randomize.Struct(seed, o, bmcMacAddressBomDBTypes, true, bmcMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + slice := BMCMacAddressBomSlice{o} + + if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil { + t.Error(err) + } else if rowsAff != 1 { + t.Error("should only have deleted one row, but affected:", rowsAff) + } + + count, err := BMCMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 0 { + t.Error("want zero records, got:", count) + } +} + +func testBMCMacAddressBomsExists(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BMCMacAddressBom{} + if err = randomize.Struct(seed, o, bmcMacAddressBomDBTypes, true, bmcMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + e, err := BMCMacAddressBomExists(ctx, tx, o.ID) + if err != nil { + t.Errorf("Unable to check if BMCMacAddressBom exists: %s", err) + } + if !e { + t.Errorf("Expected BMCMacAddressBomExists to return true, but got false.") + } +} + +func testBMCMacAddressBomsFind(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BMCMacAddressBom{} + if err = randomize.Struct(seed, o, bmcMacAddressBomDBTypes, true, bmcMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + bmcMacAddressBomFound, err := FindBMCMacAddressBom(ctx, tx, o.ID) + if err != nil { + t.Error(err) + } + + if bmcMacAddressBomFound == nil { + t.Error("want a record, got nil") + } +} + +func testBMCMacAddressBomsBind(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BMCMacAddressBom{} + if err = randomize.Struct(seed, o, bmcMacAddressBomDBTypes, true, bmcMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + if err = BMCMacAddressBoms().Bind(ctx, tx, o); err != nil { + t.Error(err) + } +} + +func testBMCMacAddressBomsOne(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BMCMacAddressBom{} + if err = randomize.Struct(seed, o, bmcMacAddressBomDBTypes, true, bmcMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + if x, err := BMCMacAddressBoms().One(ctx, tx); err != nil { + t.Error(err) + } else if x == nil { + t.Error("expected to get a non nil record") + } +} + +func testBMCMacAddressBomsAll(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + bmcMacAddressBomOne := &BMCMacAddressBom{} + bmcMacAddressBomTwo := &BMCMacAddressBom{} + if err = randomize.Struct(seed, bmcMacAddressBomOne, bmcMacAddressBomDBTypes, false, bmcMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + if err = randomize.Struct(seed, bmcMacAddressBomTwo, bmcMacAddressBomDBTypes, false, bmcMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = bmcMacAddressBomOne.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + if err = bmcMacAddressBomTwo.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + slice, err := BMCMacAddressBoms().All(ctx, tx) + if err != nil { + t.Error(err) + } + + if len(slice) != 2 { + t.Error("want 2 records, got:", len(slice)) + } +} + +func testBMCMacAddressBomsCount(t *testing.T) { + t.Parallel() + + var err error + seed := randomize.NewSeed() + bmcMacAddressBomOne := &BMCMacAddressBom{} + bmcMacAddressBomTwo := &BMCMacAddressBom{} + if err = randomize.Struct(seed, bmcMacAddressBomOne, bmcMacAddressBomDBTypes, false, bmcMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + if err = randomize.Struct(seed, bmcMacAddressBomTwo, bmcMacAddressBomDBTypes, false, bmcMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = bmcMacAddressBomOne.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + if err = bmcMacAddressBomTwo.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + count, err := BMCMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 2 { + t.Error("want 2 records, got:", count) + } +} + +func bmcMacAddressBomBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *BMCMacAddressBom) error { + *o = BMCMacAddressBom{} + return nil +} + +func bmcMacAddressBomAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *BMCMacAddressBom) error { + *o = BMCMacAddressBom{} + return nil +} + +func bmcMacAddressBomAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *BMCMacAddressBom) error { + *o = BMCMacAddressBom{} + return nil +} + +func bmcMacAddressBomBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *BMCMacAddressBom) error { + *o = BMCMacAddressBom{} + return nil +} + +func bmcMacAddressBomAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *BMCMacAddressBom) error { + *o = BMCMacAddressBom{} + return nil +} + +func bmcMacAddressBomBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *BMCMacAddressBom) error { + *o = BMCMacAddressBom{} + return nil +} + +func bmcMacAddressBomAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *BMCMacAddressBom) error { + *o = BMCMacAddressBom{} + return nil +} + +func bmcMacAddressBomBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *BMCMacAddressBom) error { + *o = BMCMacAddressBom{} + return nil +} + +func bmcMacAddressBomAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *BMCMacAddressBom) error { + *o = BMCMacAddressBom{} + return nil +} + +func testBMCMacAddressBomsHooks(t *testing.T) { + t.Parallel() + + var err error + + ctx := context.Background() + empty := &BMCMacAddressBom{} + o := &BMCMacAddressBom{} + + seed := randomize.NewSeed() + if err = randomize.Struct(seed, o, bmcMacAddressBomDBTypes, false); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom object: %s", err) + } + + AddBMCMacAddressBomHook(boil.BeforeInsertHook, bmcMacAddressBomBeforeInsertHook) + if err = o.doBeforeInsertHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doBeforeInsertHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected BeforeInsertHook function to empty object, but got: %#v", o) + } + bmcMacAddressBomBeforeInsertHooks = []BMCMacAddressBomHook{} + + AddBMCMacAddressBomHook(boil.AfterInsertHook, bmcMacAddressBomAfterInsertHook) + if err = o.doAfterInsertHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doAfterInsertHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected AfterInsertHook function to empty object, but got: %#v", o) + } + bmcMacAddressBomAfterInsertHooks = []BMCMacAddressBomHook{} + + AddBMCMacAddressBomHook(boil.AfterSelectHook, bmcMacAddressBomAfterSelectHook) + if err = o.doAfterSelectHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doAfterSelectHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected AfterSelectHook function to empty object, but got: %#v", o) + } + bmcMacAddressBomAfterSelectHooks = []BMCMacAddressBomHook{} + + AddBMCMacAddressBomHook(boil.BeforeUpdateHook, bmcMacAddressBomBeforeUpdateHook) + if err = o.doBeforeUpdateHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doBeforeUpdateHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected BeforeUpdateHook function to empty object, but got: %#v", o) + } + bmcMacAddressBomBeforeUpdateHooks = []BMCMacAddressBomHook{} + + AddBMCMacAddressBomHook(boil.AfterUpdateHook, bmcMacAddressBomAfterUpdateHook) + if err = o.doAfterUpdateHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doAfterUpdateHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected AfterUpdateHook function to empty object, but got: %#v", o) + } + bmcMacAddressBomAfterUpdateHooks = []BMCMacAddressBomHook{} + + AddBMCMacAddressBomHook(boil.BeforeDeleteHook, bmcMacAddressBomBeforeDeleteHook) + if err = o.doBeforeDeleteHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doBeforeDeleteHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected BeforeDeleteHook function to empty object, but got: %#v", o) + } + bmcMacAddressBomBeforeDeleteHooks = []BMCMacAddressBomHook{} + + AddBMCMacAddressBomHook(boil.AfterDeleteHook, bmcMacAddressBomAfterDeleteHook) + if err = o.doAfterDeleteHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doAfterDeleteHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected AfterDeleteHook function to empty object, but got: %#v", o) + } + bmcMacAddressBomAfterDeleteHooks = []BMCMacAddressBomHook{} + + AddBMCMacAddressBomHook(boil.BeforeUpsertHook, bmcMacAddressBomBeforeUpsertHook) + if err = o.doBeforeUpsertHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doBeforeUpsertHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected BeforeUpsertHook function to empty object, but got: %#v", o) + } + bmcMacAddressBomBeforeUpsertHooks = []BMCMacAddressBomHook{} + + AddBMCMacAddressBomHook(boil.AfterUpsertHook, bmcMacAddressBomAfterUpsertHook) + if err = o.doAfterUpsertHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doAfterUpsertHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected AfterUpsertHook function to empty object, but got: %#v", o) + } + bmcMacAddressBomAfterUpsertHooks = []BMCMacAddressBomHook{} +} + +func testBMCMacAddressBomsInsert(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BMCMacAddressBom{} + if err = randomize.Struct(seed, o, bmcMacAddressBomDBTypes, true, bmcMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + count, err := BMCMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 1 { + t.Error("want one record, got:", count) + } +} + +func testBMCMacAddressBomsInsertWhitelist(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BMCMacAddressBom{} + if err = randomize.Struct(seed, o, bmcMacAddressBomDBTypes, true); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Whitelist(bmcMacAddressBomColumnsWithoutDefault...)); err != nil { + t.Error(err) + } + + count, err := BMCMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 1 { + t.Error("want one record, got:", count) + } +} + +func testBMCMacAddressBomToOneBomInfoUsingBomInfo(t *testing.T) { + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + + var local BMCMacAddressBom + var foreign BomInfo + + seed := randomize.NewSeed() + if err := randomize.Struct(seed, &local, bmcMacAddressBomDBTypes, false, bmcMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + if err := randomize.Struct(seed, &foreign, bomInfoDBTypes, false, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + + local.BomInfoID = foreign.ID + if err := local.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + + check, err := local.BomInfo().One(ctx, tx) + if err != nil { + t.Fatal(err) + } + + if check.ID != foreign.ID { + t.Errorf("want: %v, got %v", foreign.ID, check.ID) + } + + slice := BMCMacAddressBomSlice{&local} + if err = local.L.LoadBomInfo(ctx, tx, false, (*[]*BMCMacAddressBom)(&slice), nil); err != nil { + t.Fatal(err) + } + if local.R.BomInfo == nil { + t.Error("struct should have been eager loaded") + } + + local.R.BomInfo = nil + if err = local.L.LoadBomInfo(ctx, tx, true, &local, nil); err != nil { + t.Fatal(err) + } + if local.R.BomInfo == nil { + t.Error("struct should have been eager loaded") + } +} + +func testBMCMacAddressBomToOneSetOpBomInfoUsingBomInfo(t *testing.T) { + var err error + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + + var a BMCMacAddressBom + var b, c BomInfo + + seed := randomize.NewSeed() + if err = randomize.Struct(seed, &a, bmcMacAddressBomDBTypes, false, strmangle.SetComplement(bmcMacAddressBomPrimaryKeyColumns, bmcMacAddressBomColumnsWithoutDefault)...); err != nil { + t.Fatal(err) + } + if err = randomize.Struct(seed, &b, bomInfoDBTypes, false, strmangle.SetComplement(bomInfoPrimaryKeyColumns, bomInfoColumnsWithoutDefault)...); err != nil { + t.Fatal(err) + } + if err = randomize.Struct(seed, &c, bomInfoDBTypes, false, strmangle.SetComplement(bomInfoPrimaryKeyColumns, bomInfoColumnsWithoutDefault)...); err != nil { + t.Fatal(err) + } + + if err := a.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + if err = b.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + + for i, x := range []*BomInfo{&b, &c} { + err = a.SetBomInfo(ctx, tx, i != 0, x) + if err != nil { + t.Fatal(err) + } + + if a.R.BomInfo != x { + t.Error("relationship struct not set to correct value") + } + + if x.R.BMCMacAddressBoms[0] != &a { + t.Error("failed to append to foreign relationship struct") + } + if a.BomInfoID != x.ID { + t.Error("foreign key was wrong value", a.BomInfoID) + } + + zero := reflect.Zero(reflect.TypeOf(a.BomInfoID)) + reflect.Indirect(reflect.ValueOf(&a.BomInfoID)).Set(zero) + + if err = a.Reload(ctx, tx); err != nil { + t.Fatal("failed to reload", err) + } + + if a.BomInfoID != x.ID { + t.Error("foreign key was wrong value", a.BomInfoID, x.ID) + } + } +} + +func testBMCMacAddressBomsReload(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BMCMacAddressBom{} + if err = randomize.Struct(seed, o, bmcMacAddressBomDBTypes, true, bmcMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + if err = o.Reload(ctx, tx); err != nil { + t.Error(err) + } +} + +func testBMCMacAddressBomsReloadAll(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BMCMacAddressBom{} + if err = randomize.Struct(seed, o, bmcMacAddressBomDBTypes, true, bmcMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + slice := BMCMacAddressBomSlice{o} + + if err = slice.ReloadAll(ctx, tx); err != nil { + t.Error(err) + } +} + +func testBMCMacAddressBomsSelect(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BMCMacAddressBom{} + if err = randomize.Struct(seed, o, bmcMacAddressBomDBTypes, true, bmcMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + slice, err := BMCMacAddressBoms().All(ctx, tx) + if err != nil { + t.Error(err) + } + + if len(slice) != 1 { + t.Error("want one record, got:", len(slice)) + } +} + +var ( + bmcMacAddressBomDBTypes = map[string]string{`ID`: `uuid`, `BMCMacAddress`: `string`, `BomInfoID`: `uuid`} + _ = bytes.MinRead +) + +func testBMCMacAddressBomsUpdate(t *testing.T) { + t.Parallel() + + if 0 == len(bmcMacAddressBomPrimaryKeyColumns) { + t.Skip("Skipping table with no primary key columns") + } + if len(bmcMacAddressBomAllColumns) == len(bmcMacAddressBomPrimaryKeyColumns) { + t.Skip("Skipping table with only primary key columns") + } + + seed := randomize.NewSeed() + var err error + o := &BMCMacAddressBom{} + if err = randomize.Struct(seed, o, bmcMacAddressBomDBTypes, true, bmcMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + count, err := BMCMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 1 { + t.Error("want one record, got:", count) + } + + if err = randomize.Struct(seed, o, bmcMacAddressBomDBTypes, true, bmcMacAddressBomPrimaryKeyColumns...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + + if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } else if rowsAff != 1 { + t.Error("should only affect one row but affected", rowsAff) + } +} + +func testBMCMacAddressBomsSliceUpdateAll(t *testing.T) { + t.Parallel() + + if len(bmcMacAddressBomAllColumns) == len(bmcMacAddressBomPrimaryKeyColumns) { + t.Skip("Skipping table with only primary key columns") + } + + seed := randomize.NewSeed() + var err error + o := &BMCMacAddressBom{} + if err = randomize.Struct(seed, o, bmcMacAddressBomDBTypes, true, bmcMacAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + count, err := BMCMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 1 { + t.Error("want one record, got:", count) + } + + if err = randomize.Struct(seed, o, bmcMacAddressBomDBTypes, true, bmcMacAddressBomPrimaryKeyColumns...); err != nil { + t.Errorf("Unable to randomize BMCMacAddressBom struct: %s", err) + } + + // Remove Primary keys and unique columns from what we plan to update + var fields []string + if strmangle.StringSliceMatch(bmcMacAddressBomAllColumns, bmcMacAddressBomPrimaryKeyColumns) { + fields = bmcMacAddressBomAllColumns + } else { + fields = strmangle.SetComplement( + bmcMacAddressBomAllColumns, + bmcMacAddressBomPrimaryKeyColumns, + ) + } + + value := reflect.Indirect(reflect.ValueOf(o)) + typ := reflect.TypeOf(o).Elem() + n := typ.NumField() + + updateMap := M{} + for _, col := range fields { + for i := 0; i < n; i++ { + f := typ.Field(i) + if f.Tag.Get("boil") == col { + updateMap[col] = value.Field(i).Interface() + } + } + } + + slice := BMCMacAddressBomSlice{o} + if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil { + t.Error(err) + } else if rowsAff != 1 { + t.Error("wanted one record updated but got", rowsAff) + } +} diff --git a/internal/models/boil_suites_test.go b/internal/models/boil_suites_test.go index ed809aa7..75cec0a2 100644 --- a/internal/models/boil_suites_test.go +++ b/internal/models/boil_suites_test.go @@ -12,8 +12,11 @@ import "testing" // It does NOT run each operation group in parallel. // Separating the tests thusly grants avoidance of Postgres deadlocks. func TestParent(t *testing.T) { + t.Run("AocMacAddressBoms", testAocMacAddressBoms) t.Run("Attributes", testAttributes) t.Run("AttributesFirmwareSets", testAttributesFirmwareSets) + t.Run("BMCMacAddressBoms", testBMCMacAddressBoms) + t.Run("BomInfos", testBomInfos) t.Run("ComponentFirmwareSets", testComponentFirmwareSets) t.Run("ComponentFirmwareSetMaps", testComponentFirmwareSetMaps) t.Run("ComponentFirmwareVersions", testComponentFirmwareVersions) @@ -38,8 +41,11 @@ func TestSliceSoftDeleteAll(t *testing.T) { } func TestDelete(t *testing.T) { + t.Run("AocMacAddressBoms", testAocMacAddressBomsDelete) t.Run("Attributes", testAttributesDelete) t.Run("AttributesFirmwareSets", testAttributesFirmwareSetsDelete) + t.Run("BMCMacAddressBoms", testBMCMacAddressBomsDelete) + t.Run("BomInfos", testBomInfosDelete) t.Run("ComponentFirmwareSets", testComponentFirmwareSetsDelete) t.Run("ComponentFirmwareSetMaps", testComponentFirmwareSetMapsDelete) t.Run("ComponentFirmwareVersions", testComponentFirmwareVersionsDelete) @@ -52,8 +58,11 @@ func TestDelete(t *testing.T) { } func TestQueryDeleteAll(t *testing.T) { + t.Run("AocMacAddressBoms", testAocMacAddressBomsQueryDeleteAll) t.Run("Attributes", testAttributesQueryDeleteAll) t.Run("AttributesFirmwareSets", testAttributesFirmwareSetsQueryDeleteAll) + t.Run("BMCMacAddressBoms", testBMCMacAddressBomsQueryDeleteAll) + t.Run("BomInfos", testBomInfosQueryDeleteAll) t.Run("ComponentFirmwareSets", testComponentFirmwareSetsQueryDeleteAll) t.Run("ComponentFirmwareSetMaps", testComponentFirmwareSetMapsQueryDeleteAll) t.Run("ComponentFirmwareVersions", testComponentFirmwareVersionsQueryDeleteAll) @@ -66,8 +75,11 @@ func TestQueryDeleteAll(t *testing.T) { } func TestSliceDeleteAll(t *testing.T) { + t.Run("AocMacAddressBoms", testAocMacAddressBomsSliceDeleteAll) t.Run("Attributes", testAttributesSliceDeleteAll) t.Run("AttributesFirmwareSets", testAttributesFirmwareSetsSliceDeleteAll) + t.Run("BMCMacAddressBoms", testBMCMacAddressBomsSliceDeleteAll) + t.Run("BomInfos", testBomInfosSliceDeleteAll) t.Run("ComponentFirmwareSets", testComponentFirmwareSetsSliceDeleteAll) t.Run("ComponentFirmwareSetMaps", testComponentFirmwareSetMapsSliceDeleteAll) t.Run("ComponentFirmwareVersions", testComponentFirmwareVersionsSliceDeleteAll) @@ -80,8 +92,11 @@ func TestSliceDeleteAll(t *testing.T) { } func TestExists(t *testing.T) { + t.Run("AocMacAddressBoms", testAocMacAddressBomsExists) t.Run("Attributes", testAttributesExists) t.Run("AttributesFirmwareSets", testAttributesFirmwareSetsExists) + t.Run("BMCMacAddressBoms", testBMCMacAddressBomsExists) + t.Run("BomInfos", testBomInfosExists) t.Run("ComponentFirmwareSets", testComponentFirmwareSetsExists) t.Run("ComponentFirmwareSetMaps", testComponentFirmwareSetMapsExists) t.Run("ComponentFirmwareVersions", testComponentFirmwareVersionsExists) @@ -94,8 +109,11 @@ func TestExists(t *testing.T) { } func TestFind(t *testing.T) { + t.Run("AocMacAddressBoms", testAocMacAddressBomsFind) t.Run("Attributes", testAttributesFind) t.Run("AttributesFirmwareSets", testAttributesFirmwareSetsFind) + t.Run("BMCMacAddressBoms", testBMCMacAddressBomsFind) + t.Run("BomInfos", testBomInfosFind) t.Run("ComponentFirmwareSets", testComponentFirmwareSetsFind) t.Run("ComponentFirmwareSetMaps", testComponentFirmwareSetMapsFind) t.Run("ComponentFirmwareVersions", testComponentFirmwareVersionsFind) @@ -108,8 +126,11 @@ func TestFind(t *testing.T) { } func TestBind(t *testing.T) { + t.Run("AocMacAddressBoms", testAocMacAddressBomsBind) t.Run("Attributes", testAttributesBind) t.Run("AttributesFirmwareSets", testAttributesFirmwareSetsBind) + t.Run("BMCMacAddressBoms", testBMCMacAddressBomsBind) + t.Run("BomInfos", testBomInfosBind) t.Run("ComponentFirmwareSets", testComponentFirmwareSetsBind) t.Run("ComponentFirmwareSetMaps", testComponentFirmwareSetMapsBind) t.Run("ComponentFirmwareVersions", testComponentFirmwareVersionsBind) @@ -122,8 +143,11 @@ func TestBind(t *testing.T) { } func TestOne(t *testing.T) { + t.Run("AocMacAddressBoms", testAocMacAddressBomsOne) t.Run("Attributes", testAttributesOne) t.Run("AttributesFirmwareSets", testAttributesFirmwareSetsOne) + t.Run("BMCMacAddressBoms", testBMCMacAddressBomsOne) + t.Run("BomInfos", testBomInfosOne) t.Run("ComponentFirmwareSets", testComponentFirmwareSetsOne) t.Run("ComponentFirmwareSetMaps", testComponentFirmwareSetMapsOne) t.Run("ComponentFirmwareVersions", testComponentFirmwareVersionsOne) @@ -136,8 +160,11 @@ func TestOne(t *testing.T) { } func TestAll(t *testing.T) { + t.Run("AocMacAddressBoms", testAocMacAddressBomsAll) t.Run("Attributes", testAttributesAll) t.Run("AttributesFirmwareSets", testAttributesFirmwareSetsAll) + t.Run("BMCMacAddressBoms", testBMCMacAddressBomsAll) + t.Run("BomInfos", testBomInfosAll) t.Run("ComponentFirmwareSets", testComponentFirmwareSetsAll) t.Run("ComponentFirmwareSetMaps", testComponentFirmwareSetMapsAll) t.Run("ComponentFirmwareVersions", testComponentFirmwareVersionsAll) @@ -150,8 +177,11 @@ func TestAll(t *testing.T) { } func TestCount(t *testing.T) { + t.Run("AocMacAddressBoms", testAocMacAddressBomsCount) t.Run("Attributes", testAttributesCount) t.Run("AttributesFirmwareSets", testAttributesFirmwareSetsCount) + t.Run("BMCMacAddressBoms", testBMCMacAddressBomsCount) + t.Run("BomInfos", testBomInfosCount) t.Run("ComponentFirmwareSets", testComponentFirmwareSetsCount) t.Run("ComponentFirmwareSetMaps", testComponentFirmwareSetMapsCount) t.Run("ComponentFirmwareVersions", testComponentFirmwareVersionsCount) @@ -164,8 +194,11 @@ func TestCount(t *testing.T) { } func TestHooks(t *testing.T) { + t.Run("AocMacAddressBoms", testAocMacAddressBomsHooks) t.Run("Attributes", testAttributesHooks) t.Run("AttributesFirmwareSets", testAttributesFirmwareSetsHooks) + t.Run("BMCMacAddressBoms", testBMCMacAddressBomsHooks) + t.Run("BomInfos", testBomInfosHooks) t.Run("ComponentFirmwareSets", testComponentFirmwareSetsHooks) t.Run("ComponentFirmwareSetMaps", testComponentFirmwareSetMapsHooks) t.Run("ComponentFirmwareVersions", testComponentFirmwareVersionsHooks) @@ -178,10 +211,16 @@ func TestHooks(t *testing.T) { } func TestInsert(t *testing.T) { + t.Run("AocMacAddressBoms", testAocMacAddressBomsInsert) + t.Run("AocMacAddressBoms", testAocMacAddressBomsInsertWhitelist) t.Run("Attributes", testAttributesInsert) t.Run("Attributes", testAttributesInsertWhitelist) t.Run("AttributesFirmwareSets", testAttributesFirmwareSetsInsert) t.Run("AttributesFirmwareSets", testAttributesFirmwareSetsInsertWhitelist) + t.Run("BMCMacAddressBoms", testBMCMacAddressBomsInsert) + t.Run("BMCMacAddressBoms", testBMCMacAddressBomsInsertWhitelist) + t.Run("BomInfos", testBomInfosInsert) + t.Run("BomInfos", testBomInfosInsertWhitelist) t.Run("ComponentFirmwareSets", testComponentFirmwareSetsInsert) t.Run("ComponentFirmwareSets", testComponentFirmwareSetsInsertWhitelist) t.Run("ComponentFirmwareSetMaps", testComponentFirmwareSetMapsInsert) @@ -205,9 +244,11 @@ func TestInsert(t *testing.T) { // TestToOne tests cannot be run in parallel // or deadlocks can occur. func TestToOne(t *testing.T) { + t.Run("AocMacAddressBomToBomInfoUsingBomInfo", testAocMacAddressBomToOneBomInfoUsingBomInfo) t.Run("AttributeToServerUsingServer", testAttributeToOneServerUsingServer) t.Run("AttributeToServerComponentUsingServerComponent", testAttributeToOneServerComponentUsingServerComponent) t.Run("AttributesFirmwareSetToComponentFirmwareSetUsingFirmwareSet", testAttributesFirmwareSetToOneComponentFirmwareSetUsingFirmwareSet) + t.Run("BMCMacAddressBomToBomInfoUsingBomInfo", testBMCMacAddressBomToOneBomInfoUsingBomInfo) t.Run("ComponentFirmwareSetMapToComponentFirmwareSetUsingFirmwareSet", testComponentFirmwareSetMapToOneComponentFirmwareSetUsingFirmwareSet) t.Run("ComponentFirmwareSetMapToComponentFirmwareVersionUsingFirmware", testComponentFirmwareSetMapToOneComponentFirmwareVersionUsingFirmware) t.Run("ServerComponentToServerUsingServer", testServerComponentToOneServerUsingServer) @@ -225,6 +266,8 @@ func TestOneToOne(t *testing.T) {} // TestToMany tests cannot be run in parallel // or deadlocks can occur. func TestToMany(t *testing.T) { + t.Run("BomInfoToAocMacAddressBoms", testBomInfoToManyAocMacAddressBoms) + t.Run("BomInfoToBMCMacAddressBoms", testBomInfoToManyBMCMacAddressBoms) t.Run("ComponentFirmwareSetToFirmwareSetAttributesFirmwareSets", testComponentFirmwareSetToManyFirmwareSetAttributesFirmwareSets) t.Run("ComponentFirmwareSetToFirmwareSetComponentFirmwareSetMaps", testComponentFirmwareSetToManyFirmwareSetComponentFirmwareSetMaps) t.Run("ComponentFirmwareVersionToFirmwareComponentFirmwareSetMaps", testComponentFirmwareVersionToManyFirmwareComponentFirmwareSetMaps) @@ -241,9 +284,11 @@ func TestToMany(t *testing.T) { // TestToOneSet tests cannot be run in parallel // or deadlocks can occur. func TestToOneSet(t *testing.T) { + t.Run("AocMacAddressBomToBomInfoUsingAocMacAddressBoms", testAocMacAddressBomToOneSetOpBomInfoUsingBomInfo) t.Run("AttributeToServerUsingAttributes", testAttributeToOneSetOpServerUsingServer) t.Run("AttributeToServerComponentUsingAttributes", testAttributeToOneSetOpServerComponentUsingServerComponent) t.Run("AttributesFirmwareSetToComponentFirmwareSetUsingFirmwareSetAttributesFirmwareSets", testAttributesFirmwareSetToOneSetOpComponentFirmwareSetUsingFirmwareSet) + t.Run("BMCMacAddressBomToBomInfoUsingBMCMacAddressBoms", testBMCMacAddressBomToOneSetOpBomInfoUsingBomInfo) t.Run("ComponentFirmwareSetMapToComponentFirmwareSetUsingFirmwareSetComponentFirmwareSetMaps", testComponentFirmwareSetMapToOneSetOpComponentFirmwareSetUsingFirmwareSet) t.Run("ComponentFirmwareSetMapToComponentFirmwareVersionUsingFirmwareComponentFirmwareSetMaps", testComponentFirmwareSetMapToOneSetOpComponentFirmwareVersionUsingFirmware) t.Run("ServerComponentToServerUsingServerComponents", testServerComponentToOneSetOpServerUsingServer) @@ -275,6 +320,8 @@ func TestOneToOneRemove(t *testing.T) {} // TestToManyAdd tests cannot be run in parallel // or deadlocks can occur. func TestToManyAdd(t *testing.T) { + t.Run("BomInfoToAocMacAddressBoms", testBomInfoToManyAddOpAocMacAddressBoms) + t.Run("BomInfoToBMCMacAddressBoms", testBomInfoToManyAddOpBMCMacAddressBoms) t.Run("ComponentFirmwareSetToFirmwareSetAttributesFirmwareSets", testComponentFirmwareSetToManyAddOpFirmwareSetAttributesFirmwareSets) t.Run("ComponentFirmwareSetToFirmwareSetComponentFirmwareSetMaps", testComponentFirmwareSetToManyAddOpFirmwareSetComponentFirmwareSetMaps) t.Run("ComponentFirmwareVersionToFirmwareComponentFirmwareSetMaps", testComponentFirmwareVersionToManyAddOpFirmwareComponentFirmwareSetMaps) @@ -309,8 +356,11 @@ func TestToManyRemove(t *testing.T) { } func TestReload(t *testing.T) { + t.Run("AocMacAddressBoms", testAocMacAddressBomsReload) t.Run("Attributes", testAttributesReload) t.Run("AttributesFirmwareSets", testAttributesFirmwareSetsReload) + t.Run("BMCMacAddressBoms", testBMCMacAddressBomsReload) + t.Run("BomInfos", testBomInfosReload) t.Run("ComponentFirmwareSets", testComponentFirmwareSetsReload) t.Run("ComponentFirmwareSetMaps", testComponentFirmwareSetMapsReload) t.Run("ComponentFirmwareVersions", testComponentFirmwareVersionsReload) @@ -323,8 +373,11 @@ func TestReload(t *testing.T) { } func TestReloadAll(t *testing.T) { + t.Run("AocMacAddressBoms", testAocMacAddressBomsReloadAll) t.Run("Attributes", testAttributesReloadAll) t.Run("AttributesFirmwareSets", testAttributesFirmwareSetsReloadAll) + t.Run("BMCMacAddressBoms", testBMCMacAddressBomsReloadAll) + t.Run("BomInfos", testBomInfosReloadAll) t.Run("ComponentFirmwareSets", testComponentFirmwareSetsReloadAll) t.Run("ComponentFirmwareSetMaps", testComponentFirmwareSetMapsReloadAll) t.Run("ComponentFirmwareVersions", testComponentFirmwareVersionsReloadAll) @@ -337,8 +390,11 @@ func TestReloadAll(t *testing.T) { } func TestSelect(t *testing.T) { + t.Run("AocMacAddressBoms", testAocMacAddressBomsSelect) t.Run("Attributes", testAttributesSelect) t.Run("AttributesFirmwareSets", testAttributesFirmwareSetsSelect) + t.Run("BMCMacAddressBoms", testBMCMacAddressBomsSelect) + t.Run("BomInfos", testBomInfosSelect) t.Run("ComponentFirmwareSets", testComponentFirmwareSetsSelect) t.Run("ComponentFirmwareSetMaps", testComponentFirmwareSetMapsSelect) t.Run("ComponentFirmwareVersions", testComponentFirmwareVersionsSelect) @@ -351,8 +407,11 @@ func TestSelect(t *testing.T) { } func TestUpdate(t *testing.T) { + t.Run("AocMacAddressBoms", testAocMacAddressBomsUpdate) t.Run("Attributes", testAttributesUpdate) t.Run("AttributesFirmwareSets", testAttributesFirmwareSetsUpdate) + t.Run("BMCMacAddressBoms", testBMCMacAddressBomsUpdate) + t.Run("BomInfos", testBomInfosUpdate) t.Run("ComponentFirmwareSets", testComponentFirmwareSetsUpdate) t.Run("ComponentFirmwareSetMaps", testComponentFirmwareSetMapsUpdate) t.Run("ComponentFirmwareVersions", testComponentFirmwareVersionsUpdate) @@ -365,8 +424,11 @@ func TestUpdate(t *testing.T) { } func TestSliceUpdateAll(t *testing.T) { + t.Run("AocMacAddressBoms", testAocMacAddressBomsSliceUpdateAll) t.Run("Attributes", testAttributesSliceUpdateAll) t.Run("AttributesFirmwareSets", testAttributesFirmwareSetsSliceUpdateAll) + t.Run("BMCMacAddressBoms", testBMCMacAddressBomsSliceUpdateAll) + t.Run("BomInfos", testBomInfosSliceUpdateAll) t.Run("ComponentFirmwareSets", testComponentFirmwareSetsSliceUpdateAll) t.Run("ComponentFirmwareSetMaps", testComponentFirmwareSetMapsSliceUpdateAll) t.Run("ComponentFirmwareVersions", testComponentFirmwareVersionsSliceUpdateAll) diff --git a/internal/models/boil_table_names.go b/internal/models/boil_table_names.go index 4f33a8de..4ea1762c 100644 --- a/internal/models/boil_table_names.go +++ b/internal/models/boil_table_names.go @@ -4,8 +4,11 @@ package models var TableNames = struct { + AocMacAddressBom string Attributes string AttributesFirmwareSet string + BMCMacAddressBom string + BomInfo string ComponentFirmwareSet string ComponentFirmwareSetMap string ComponentFirmwareVersion string @@ -16,8 +19,11 @@ var TableNames = struct { Servers string VersionedAttributes string }{ + AocMacAddressBom: "aoc_mac_address_bom", Attributes: "attributes", AttributesFirmwareSet: "attributes_firmware_set", + BMCMacAddressBom: "bmc_mac_address_bom", + BomInfo: "bom_info", ComponentFirmwareSet: "component_firmware_set", ComponentFirmwareSetMap: "component_firmware_set_map", ComponentFirmwareVersion: "component_firmware_version", diff --git a/internal/models/bom_info.go b/internal/models/bom_info.go new file mode 100644 index 00000000..3d6a43aa --- /dev/null +++ b/internal/models/bom_info.go @@ -0,0 +1,1276 @@ +// 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" +) + +// BomInfo is an object representing the database table. +type BomInfo struct { + ID string `boil:"id" json:"id" toml:"id" yaml:"id"` + SerialNum null.String `boil:"serial_num" json:"serial_num,omitempty" toml:"serial_num" yaml:"serial_num,omitempty"` + AocMacAddress null.String `boil:"aoc_mac_address" json:"aoc_mac_address,omitempty" toml:"aoc_mac_address" yaml:"aoc_mac_address,omitempty"` + BMCMacAddress null.String `boil:"bmc_mac_address" json:"bmc_mac_address,omitempty" toml:"bmc_mac_address" yaml:"bmc_mac_address,omitempty"` + NumDefiPmi null.String `boil:"num_defi_pmi" json:"num_defi_pmi,omitempty" toml:"num_defi_pmi" yaml:"num_defi_pmi,omitempty"` + NumDefPWD null.String `boil:"num_def_pwd" json:"num_def_pwd,omitempty" toml:"num_def_pwd" yaml:"num_def_pwd,omitempty"` + Metro null.String `boil:"metro" json:"metro,omitempty" toml:"metro" yaml:"metro,omitempty"` + + R *bomInfoR `boil:"-" json:"-" toml:"-" yaml:"-"` + L bomInfoL `boil:"-" json:"-" toml:"-" yaml:"-"` +} + +var BomInfoColumns = struct { + ID string + SerialNum string + AocMacAddress string + BMCMacAddress string + NumDefiPmi string + NumDefPWD string + Metro string +}{ + ID: "id", + SerialNum: "serial_num", + AocMacAddress: "aoc_mac_address", + BMCMacAddress: "bmc_mac_address", + NumDefiPmi: "num_defi_pmi", + NumDefPWD: "num_def_pwd", + Metro: "metro", +} + +var BomInfoTableColumns = struct { + ID string + SerialNum string + AocMacAddress string + BMCMacAddress string + NumDefiPmi string + NumDefPWD string + Metro string +}{ + ID: "bom_info.id", + SerialNum: "bom_info.serial_num", + AocMacAddress: "bom_info.aoc_mac_address", + BMCMacAddress: "bom_info.bmc_mac_address", + NumDefiPmi: "bom_info.num_defi_pmi", + NumDefPWD: "bom_info.num_def_pwd", + Metro: "bom_info.metro", +} + +// Generated where + +var BomInfoWhere = struct { + ID whereHelperstring + SerialNum whereHelpernull_String + AocMacAddress whereHelpernull_String + BMCMacAddress whereHelpernull_String + NumDefiPmi whereHelpernull_String + NumDefPWD whereHelpernull_String + Metro whereHelpernull_String +}{ + ID: whereHelperstring{field: "\"bom_info\".\"id\""}, + SerialNum: whereHelpernull_String{field: "\"bom_info\".\"serial_num\""}, + AocMacAddress: whereHelpernull_String{field: "\"bom_info\".\"aoc_mac_address\""}, + BMCMacAddress: whereHelpernull_String{field: "\"bom_info\".\"bmc_mac_address\""}, + NumDefiPmi: whereHelpernull_String{field: "\"bom_info\".\"num_defi_pmi\""}, + NumDefPWD: whereHelpernull_String{field: "\"bom_info\".\"num_def_pwd\""}, + Metro: whereHelpernull_String{field: "\"bom_info\".\"metro\""}, +} + +// BomInfoRels is where relationship names are stored. +var BomInfoRels = struct { + AocMacAddressBoms string + BMCMacAddressBoms string +}{ + AocMacAddressBoms: "AocMacAddressBoms", + BMCMacAddressBoms: "BMCMacAddressBoms", +} + +// bomInfoR is where relationships are stored. +type bomInfoR struct { + AocMacAddressBoms AocMacAddressBomSlice `boil:"AocMacAddressBoms" json:"AocMacAddressBoms" toml:"AocMacAddressBoms" yaml:"AocMacAddressBoms"` + BMCMacAddressBoms BMCMacAddressBomSlice `boil:"BMCMacAddressBoms" json:"BMCMacAddressBoms" toml:"BMCMacAddressBoms" yaml:"BMCMacAddressBoms"` +} + +// NewStruct creates a new relationship struct +func (*bomInfoR) NewStruct() *bomInfoR { + return &bomInfoR{} +} + +func (r *bomInfoR) GetAocMacAddressBoms() AocMacAddressBomSlice { + if r == nil { + return nil + } + return r.AocMacAddressBoms +} + +func (r *bomInfoR) GetBMCMacAddressBoms() BMCMacAddressBomSlice { + if r == nil { + return nil + } + return r.BMCMacAddressBoms +} + +// bomInfoL is where Load methods for each relationship are stored. +type bomInfoL struct{} + +var ( + bomInfoAllColumns = []string{"id", "serial_num", "aoc_mac_address", "bmc_mac_address", "num_defi_pmi", "num_def_pwd", "metro"} + bomInfoColumnsWithoutDefault = []string{} + bomInfoColumnsWithDefault = []string{"id", "serial_num", "aoc_mac_address", "bmc_mac_address", "num_defi_pmi", "num_def_pwd", "metro"} + bomInfoPrimaryKeyColumns = []string{"id"} + bomInfoGeneratedColumns = []string{} +) + +type ( + // BomInfoSlice is an alias for a slice of pointers to BomInfo. + // This should almost always be used instead of []BomInfo. + BomInfoSlice []*BomInfo + // BomInfoHook is the signature for custom BomInfo hook methods + BomInfoHook func(context.Context, boil.ContextExecutor, *BomInfo) error + + bomInfoQuery struct { + *queries.Query + } +) + +// Cache for insert, update and upsert +var ( + bomInfoType = reflect.TypeOf(&BomInfo{}) + bomInfoMapping = queries.MakeStructMapping(bomInfoType) + bomInfoPrimaryKeyMapping, _ = queries.BindMapping(bomInfoType, bomInfoMapping, bomInfoPrimaryKeyColumns) + bomInfoInsertCacheMut sync.RWMutex + bomInfoInsertCache = make(map[string]insertCache) + bomInfoUpdateCacheMut sync.RWMutex + bomInfoUpdateCache = make(map[string]updateCache) + bomInfoUpsertCacheMut sync.RWMutex + bomInfoUpsertCache = 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 bomInfoAfterSelectHooks []BomInfoHook + +var bomInfoBeforeInsertHooks []BomInfoHook +var bomInfoAfterInsertHooks []BomInfoHook + +var bomInfoBeforeUpdateHooks []BomInfoHook +var bomInfoAfterUpdateHooks []BomInfoHook + +var bomInfoBeforeDeleteHooks []BomInfoHook +var bomInfoAfterDeleteHooks []BomInfoHook + +var bomInfoBeforeUpsertHooks []BomInfoHook +var bomInfoAfterUpsertHooks []BomInfoHook + +// doAfterSelectHooks executes all "after Select" hooks. +func (o *BomInfo) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range bomInfoAfterSelectHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeInsertHooks executes all "before insert" hooks. +func (o *BomInfo) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range bomInfoBeforeInsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterInsertHooks executes all "after Insert" hooks. +func (o *BomInfo) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range bomInfoAfterInsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeUpdateHooks executes all "before Update" hooks. +func (o *BomInfo) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range bomInfoBeforeUpdateHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterUpdateHooks executes all "after Update" hooks. +func (o *BomInfo) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range bomInfoAfterUpdateHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeDeleteHooks executes all "before Delete" hooks. +func (o *BomInfo) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range bomInfoBeforeDeleteHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterDeleteHooks executes all "after Delete" hooks. +func (o *BomInfo) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range bomInfoAfterDeleteHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeUpsertHooks executes all "before Upsert" hooks. +func (o *BomInfo) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range bomInfoBeforeUpsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterUpsertHooks executes all "after Upsert" hooks. +func (o *BomInfo) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range bomInfoAfterUpsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// AddBomInfoHook registers your hook function for all future operations. +func AddBomInfoHook(hookPoint boil.HookPoint, bomInfoHook BomInfoHook) { + switch hookPoint { + case boil.AfterSelectHook: + bomInfoAfterSelectHooks = append(bomInfoAfterSelectHooks, bomInfoHook) + case boil.BeforeInsertHook: + bomInfoBeforeInsertHooks = append(bomInfoBeforeInsertHooks, bomInfoHook) + case boil.AfterInsertHook: + bomInfoAfterInsertHooks = append(bomInfoAfterInsertHooks, bomInfoHook) + case boil.BeforeUpdateHook: + bomInfoBeforeUpdateHooks = append(bomInfoBeforeUpdateHooks, bomInfoHook) + case boil.AfterUpdateHook: + bomInfoAfterUpdateHooks = append(bomInfoAfterUpdateHooks, bomInfoHook) + case boil.BeforeDeleteHook: + bomInfoBeforeDeleteHooks = append(bomInfoBeforeDeleteHooks, bomInfoHook) + case boil.AfterDeleteHook: + bomInfoAfterDeleteHooks = append(bomInfoAfterDeleteHooks, bomInfoHook) + case boil.BeforeUpsertHook: + bomInfoBeforeUpsertHooks = append(bomInfoBeforeUpsertHooks, bomInfoHook) + case boil.AfterUpsertHook: + bomInfoAfterUpsertHooks = append(bomInfoAfterUpsertHooks, bomInfoHook) + } +} + +// One returns a single bomInfo record from the query. +func (q bomInfoQuery) One(ctx context.Context, exec boil.ContextExecutor) (*BomInfo, error) { + o := &BomInfo{} + + 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 bom_info") + } + + if err := o.doAfterSelectHooks(ctx, exec); err != nil { + return o, err + } + + return o, nil +} + +// All returns all BomInfo records from the query. +func (q bomInfoQuery) All(ctx context.Context, exec boil.ContextExecutor) (BomInfoSlice, error) { + var o []*BomInfo + + err := q.Bind(ctx, exec, &o) + if err != nil { + return nil, errors.Wrap(err, "models: failed to assign all query results to BomInfo slice") + } + + if len(bomInfoAfterSelectHooks) != 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 BomInfo records in the query. +func (q bomInfoQuery) 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 bom_info rows") + } + + return count, nil +} + +// Exists checks if the row exists in the table. +func (q bomInfoQuery) 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 bom_info exists") + } + + return count > 0, nil +} + +// AocMacAddressBoms retrieves all the aoc_mac_address_bom's AocMacAddressBoms with an executor. +func (o *BomInfo) AocMacAddressBoms(mods ...qm.QueryMod) aocMacAddressBomQuery { + var queryMods []qm.QueryMod + if len(mods) != 0 { + queryMods = append(queryMods, mods...) + } + + queryMods = append(queryMods, + qm.Where("\"aoc_mac_address_bom\".\"bom_info_id\"=?", o.ID), + ) + + return AocMacAddressBoms(queryMods...) +} + +// BMCMacAddressBoms retrieves all the bmc_mac_address_bom's BMCMacAddressBoms with an executor. +func (o *BomInfo) BMCMacAddressBoms(mods ...qm.QueryMod) bmcMacAddressBomQuery { + var queryMods []qm.QueryMod + if len(mods) != 0 { + queryMods = append(queryMods, mods...) + } + + queryMods = append(queryMods, + qm.Where("\"bmc_mac_address_bom\".\"bom_info_id\"=?", o.ID), + ) + + return BMCMacAddressBoms(queryMods...) +} + +// LoadAocMacAddressBoms allows an eager lookup of values, cached into the +// loaded structs of the objects. This is for a 1-M or N-M relationship. +func (bomInfoL) LoadAocMacAddressBoms(ctx context.Context, e boil.ContextExecutor, singular bool, maybeBomInfo interface{}, mods queries.Applicator) error { + var slice []*BomInfo + var object *BomInfo + + if singular { + object = maybeBomInfo.(*BomInfo) + } else { + slice = *maybeBomInfo.(*[]*BomInfo) + } + + args := make([]interface{}, 0, 1) + if singular { + if object.R == nil { + object.R = &bomInfoR{} + } + args = append(args, object.ID) + } else { + Outer: + for _, obj := range slice { + if obj.R == nil { + obj.R = &bomInfoR{} + } + + for _, a := range args { + if a == obj.ID { + continue Outer + } + } + + args = append(args, obj.ID) + } + } + + if len(args) == 0 { + return nil + } + + query := NewQuery( + qm.From(`aoc_mac_address_bom`), + qm.WhereIn(`aoc_mac_address_bom.bom_info_id in ?`, args...), + ) + if mods != nil { + mods.Apply(query) + } + + results, err := query.QueryContext(ctx, e) + if err != nil { + return errors.Wrap(err, "failed to eager load aoc_mac_address_bom") + } + + var resultSlice []*AocMacAddressBom + if err = queries.Bind(results, &resultSlice); err != nil { + return errors.Wrap(err, "failed to bind eager loaded slice aoc_mac_address_bom") + } + + if err = results.Close(); err != nil { + return errors.Wrap(err, "failed to close results in eager load on aoc_mac_address_bom") + } + if err = results.Err(); err != nil { + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for aoc_mac_address_bom") + } + + if len(aocMacAddressBomAfterSelectHooks) != 0 { + for _, obj := range resultSlice { + if err := obj.doAfterSelectHooks(ctx, e); err != nil { + return err + } + } + } + if singular { + object.R.AocMacAddressBoms = resultSlice + for _, foreign := range resultSlice { + if foreign.R == nil { + foreign.R = &aocMacAddressBomR{} + } + foreign.R.BomInfo = object + } + return nil + } + + for _, foreign := range resultSlice { + for _, local := range slice { + if local.ID == foreign.BomInfoID { + local.R.AocMacAddressBoms = append(local.R.AocMacAddressBoms, foreign) + if foreign.R == nil { + foreign.R = &aocMacAddressBomR{} + } + foreign.R.BomInfo = local + break + } + } + } + + return nil +} + +// LoadBMCMacAddressBoms allows an eager lookup of values, cached into the +// loaded structs of the objects. This is for a 1-M or N-M relationship. +func (bomInfoL) LoadBMCMacAddressBoms(ctx context.Context, e boil.ContextExecutor, singular bool, maybeBomInfo interface{}, mods queries.Applicator) error { + var slice []*BomInfo + var object *BomInfo + + if singular { + object = maybeBomInfo.(*BomInfo) + } else { + slice = *maybeBomInfo.(*[]*BomInfo) + } + + args := make([]interface{}, 0, 1) + if singular { + if object.R == nil { + object.R = &bomInfoR{} + } + args = append(args, object.ID) + } else { + Outer: + for _, obj := range slice { + if obj.R == nil { + obj.R = &bomInfoR{} + } + + for _, a := range args { + if a == obj.ID { + continue Outer + } + } + + args = append(args, obj.ID) + } + } + + if len(args) == 0 { + return nil + } + + query := NewQuery( + qm.From(`bmc_mac_address_bom`), + qm.WhereIn(`bmc_mac_address_bom.bom_info_id in ?`, args...), + ) + if mods != nil { + mods.Apply(query) + } + + results, err := query.QueryContext(ctx, e) + if err != nil { + return errors.Wrap(err, "failed to eager load bmc_mac_address_bom") + } + + var resultSlice []*BMCMacAddressBom + if err = queries.Bind(results, &resultSlice); err != nil { + return errors.Wrap(err, "failed to bind eager loaded slice bmc_mac_address_bom") + } + + if err = results.Close(); err != nil { + return errors.Wrap(err, "failed to close results in eager load on bmc_mac_address_bom") + } + if err = results.Err(); err != nil { + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for bmc_mac_address_bom") + } + + if len(bmcMacAddressBomAfterSelectHooks) != 0 { + for _, obj := range resultSlice { + if err := obj.doAfterSelectHooks(ctx, e); err != nil { + return err + } + } + } + if singular { + object.R.BMCMacAddressBoms = resultSlice + for _, foreign := range resultSlice { + if foreign.R == nil { + foreign.R = &bmcMacAddressBomR{} + } + foreign.R.BomInfo = object + } + return nil + } + + for _, foreign := range resultSlice { + for _, local := range slice { + if local.ID == foreign.BomInfoID { + local.R.BMCMacAddressBoms = append(local.R.BMCMacAddressBoms, foreign) + if foreign.R == nil { + foreign.R = &bmcMacAddressBomR{} + } + foreign.R.BomInfo = local + break + } + } + } + + return nil +} + +// AddAocMacAddressBoms adds the given related objects to the existing relationships +// of the bom_info, optionally inserting them as new records. +// Appends related to o.R.AocMacAddressBoms. +// Sets related.R.BomInfo appropriately. +func (o *BomInfo) AddAocMacAddressBoms(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*AocMacAddressBom) error { + var err error + for _, rel := range related { + if insert { + rel.BomInfoID = o.ID + if err = rel.Insert(ctx, exec, boil.Infer()); err != nil { + return errors.Wrap(err, "failed to insert into foreign table") + } + } else { + updateQuery := fmt.Sprintf( + "UPDATE \"aoc_mac_address_bom\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, []string{"bom_info_id"}), + strmangle.WhereClause("\"", "\"", 2, aocMacAddressBomPrimaryKeyColumns), + ) + values := []interface{}{o.ID, rel.ID} + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) + } + if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { + return errors.Wrap(err, "failed to update foreign table") + } + + rel.BomInfoID = o.ID + } + } + + if o.R == nil { + o.R = &bomInfoR{ + AocMacAddressBoms: related, + } + } else { + o.R.AocMacAddressBoms = append(o.R.AocMacAddressBoms, related...) + } + + for _, rel := range related { + if rel.R == nil { + rel.R = &aocMacAddressBomR{ + BomInfo: o, + } + } else { + rel.R.BomInfo = o + } + } + return nil +} + +// AddBMCMacAddressBoms adds the given related objects to the existing relationships +// of the bom_info, optionally inserting them as new records. +// Appends related to o.R.BMCMacAddressBoms. +// Sets related.R.BomInfo appropriately. +func (o *BomInfo) AddBMCMacAddressBoms(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*BMCMacAddressBom) error { + var err error + for _, rel := range related { + if insert { + rel.BomInfoID = o.ID + if err = rel.Insert(ctx, exec, boil.Infer()); err != nil { + return errors.Wrap(err, "failed to insert into foreign table") + } + } else { + updateQuery := fmt.Sprintf( + "UPDATE \"bmc_mac_address_bom\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, []string{"bom_info_id"}), + strmangle.WhereClause("\"", "\"", 2, bmcMacAddressBomPrimaryKeyColumns), + ) + values := []interface{}{o.ID, rel.ID} + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) + } + if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { + return errors.Wrap(err, "failed to update foreign table") + } + + rel.BomInfoID = o.ID + } + } + + if o.R == nil { + o.R = &bomInfoR{ + BMCMacAddressBoms: related, + } + } else { + o.R.BMCMacAddressBoms = append(o.R.BMCMacAddressBoms, related...) + } + + for _, rel := range related { + if rel.R == nil { + rel.R = &bmcMacAddressBomR{ + BomInfo: o, + } + } else { + rel.R.BomInfo = o + } + } + return nil +} + +// BomInfos retrieves all the records using an executor. +func BomInfos(mods ...qm.QueryMod) bomInfoQuery { + mods = append(mods, qm.From("\"bom_info\"")) + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"bom_info\".*"}) + } + + return bomInfoQuery{q} +} + +// FindBomInfo retrieves a single record by ID with an executor. +// If selectCols is empty Find will return all columns. +func FindBomInfo(ctx context.Context, exec boil.ContextExecutor, iD string, selectCols ...string) (*BomInfo, error) { + bomInfoObj := &BomInfo{} + + sel := "*" + if len(selectCols) > 0 { + sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",") + } + query := fmt.Sprintf( + "select %s from \"bom_info\" where \"id\"=$1", sel, + ) + + q := queries.Raw(query, iD) + + err := q.Bind(ctx, exec, bomInfoObj) + if err != nil { + if errors.Is(err, sql.ErrNoRows) { + return nil, sql.ErrNoRows + } + return nil, errors.Wrap(err, "models: unable to select from bom_info") + } + + if err = bomInfoObj.doAfterSelectHooks(ctx, exec); err != nil { + return bomInfoObj, err + } + + return bomInfoObj, nil +} + +// Insert a single record using an executor. +// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts. +func (o *BomInfo) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error { + if o == nil { + return errors.New("models: no bom_info provided for insertion") + } + + var err error + + if err := o.doBeforeInsertHooks(ctx, exec); err != nil { + return err + } + + nzDefaults := queries.NonZeroDefaultSet(bomInfoColumnsWithDefault, o) + + key := makeCacheKey(columns, nzDefaults) + bomInfoInsertCacheMut.RLock() + cache, cached := bomInfoInsertCache[key] + bomInfoInsertCacheMut.RUnlock() + + if !cached { + wl, returnColumns := columns.InsertColumnSet( + bomInfoAllColumns, + bomInfoColumnsWithDefault, + bomInfoColumnsWithoutDefault, + nzDefaults, + ) + + cache.valueMapping, err = queries.BindMapping(bomInfoType, bomInfoMapping, wl) + if err != nil { + return err + } + cache.retMapping, err = queries.BindMapping(bomInfoType, bomInfoMapping, returnColumns) + if err != nil { + return err + } + if len(wl) != 0 { + cache.query = fmt.Sprintf("INSERT INTO \"bom_info\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1)) + } else { + cache.query = "INSERT INTO \"bom_info\" %sDEFAULT VALUES%s" + } + + var queryOutput, queryReturning string + + if len(cache.retMapping) != 0 { + queryReturning = fmt.Sprintf(" RETURNING \"%s\"", strings.Join(returnColumns, "\",\"")) + } + + cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning) + } + + value := reflect.Indirect(reflect.ValueOf(o)) + vals := queries.ValuesFromMapping(value, cache.valueMapping) + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) + } + + if len(cache.retMapping) != 0 { + err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...) + } else { + _, err = exec.ExecContext(ctx, cache.query, vals...) + } + + if err != nil { + return errors.Wrap(err, "models: unable to insert into bom_info") + } + + if !cached { + bomInfoInsertCacheMut.Lock() + bomInfoInsertCache[key] = cache + bomInfoInsertCacheMut.Unlock() + } + + return o.doAfterInsertHooks(ctx, exec) +} + +// Update uses an executor to update the BomInfo. +// 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 *BomInfo) 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) + bomInfoUpdateCacheMut.RLock() + cache, cached := bomInfoUpdateCache[key] + bomInfoUpdateCacheMut.RUnlock() + + if !cached { + wl := columns.UpdateColumnSet( + bomInfoAllColumns, + bomInfoPrimaryKeyColumns, + ) + + if !columns.IsWhitelist() { + wl = strmangle.SetComplement(wl, []string{"created_at"}) + } + if len(wl) == 0 { + return 0, errors.New("models: unable to update bom_info, could not build whitelist") + } + + cache.query = fmt.Sprintf("UPDATE \"bom_info\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, wl), + strmangle.WhereClause("\"", "\"", len(wl)+1, bomInfoPrimaryKeyColumns), + ) + cache.valueMapping, err = queries.BindMapping(bomInfoType, bomInfoMapping, append(wl, bomInfoPrimaryKeyColumns...)) + 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 bom_info row") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: failed to get rows affected by update for bom_info") + } + + if !cached { + bomInfoUpdateCacheMut.Lock() + bomInfoUpdateCache[key] = cache + bomInfoUpdateCacheMut.Unlock() + } + + return rowsAff, o.doAfterUpdateHooks(ctx, exec) +} + +// UpdateAll updates all rows with the specified column values. +func (q bomInfoQuery) 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 bom_info") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for bom_info") + } + + return rowsAff, nil +} + +// UpdateAll updates all rows with the specified column values, using an executor. +func (o BomInfoSlice) 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)), bomInfoPrimaryKeyMapping) + args = append(args, pkeyArgs...) + } + + sql := fmt.Sprintf("UPDATE \"bom_info\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, colNames), + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, bomInfoPrimaryKeyColumns, 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 bomInfo slice") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all bomInfo") + } + return rowsAff, nil +} + +// Delete deletes a single BomInfo record with an executor. +// Delete will match against the primary key column to find the record to delete. +func (o *BomInfo) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) { + if o == nil { + return 0, errors.New("models: no BomInfo provided for delete") + } + + if err := o.doBeforeDeleteHooks(ctx, exec); err != nil { + return 0, err + } + + args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), bomInfoPrimaryKeyMapping) + sql := "DELETE FROM \"bom_info\" WHERE \"id\"=$1" + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) + } + result, err := exec.ExecContext(ctx, sql, args...) + if err != nil { + return 0, errors.Wrap(err, "models: unable to delete from bom_info") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for bom_info") + } + + if err := o.doAfterDeleteHooks(ctx, exec); err != nil { + return 0, err + } + + return rowsAff, nil +} + +// DeleteAll deletes all matching rows. +func (q bomInfoQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { + if q.Query == nil { + return 0, errors.New("models: no bomInfoQuery 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 bom_info") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for bom_info") + } + + return rowsAff, nil +} + +// DeleteAll deletes all rows in the slice, using an executor. +func (o BomInfoSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { + if len(o) == 0 { + return 0, nil + } + + if len(bomInfoBeforeDeleteHooks) != 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)), bomInfoPrimaryKeyMapping) + args = append(args, pkeyArgs...) + } + + sql := "DELETE FROM \"bom_info\" WHERE " + + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, bomInfoPrimaryKeyColumns, 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 bomInfo slice") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for bom_info") + } + + if len(bomInfoAfterDeleteHooks) != 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 *BomInfo) Reload(ctx context.Context, exec boil.ContextExecutor) error { + ret, err := FindBomInfo(ctx, exec, o.ID) + if err != nil { + return err + } + + *o = *ret + return nil +} + +// ReloadAll refetches every row with matching primary key column values +// and overwrites the original object slice with the newly updated slice. +func (o *BomInfoSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error { + if o == nil || len(*o) == 0 { + return nil + } + + slice := BomInfoSlice{} + var args []interface{} + for _, obj := range *o { + pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), bomInfoPrimaryKeyMapping) + args = append(args, pkeyArgs...) + } + + sql := "SELECT \"bom_info\".* FROM \"bom_info\" WHERE " + + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, bomInfoPrimaryKeyColumns, 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 BomInfoSlice") + } + + *o = slice + + return nil +} + +// BomInfoExists checks if the BomInfo row exists. +func BomInfoExists(ctx context.Context, exec boil.ContextExecutor, iD string) (bool, error) { + var exists bool + sql := "select exists(select 1 from \"bom_info\" where \"id\"=$1 limit 1)" + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) + } + row := exec.QueryRowContext(ctx, sql, iD) + + err := row.Scan(&exists) + if err != nil { + return false, errors.Wrap(err, "models: unable to check if bom_info exists") + } + + return exists, nil +} + +// Upsert attempts an insert using an executor, and does an update or ignore on conflict. +// See boil.Columns documentation for how to properly use updateColumns and insertColumns. +func (o *BomInfo) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { + if o == nil { + return errors.New("models: no bom_info provided for upsert") + } + + if err := o.doBeforeUpsertHooks(ctx, exec); err != nil { + return err + } + + nzDefaults := queries.NonZeroDefaultSet(bomInfoColumnsWithDefault, o) + + // Build cache key in-line uglily - mysql vs psql problems + buf := strmangle.GetBuffer() + if updateOnConflict { + buf.WriteByte('t') + } else { + buf.WriteByte('f') + } + buf.WriteByte('.') + for _, c := range conflictColumns { + buf.WriteString(c) + } + buf.WriteByte('.') + buf.WriteString(strconv.Itoa(updateColumns.Kind)) + for _, c := range updateColumns.Cols { + buf.WriteString(c) + } + buf.WriteByte('.') + buf.WriteString(strconv.Itoa(insertColumns.Kind)) + for _, c := range insertColumns.Cols { + buf.WriteString(c) + } + buf.WriteByte('.') + for _, c := range nzDefaults { + buf.WriteString(c) + } + key := buf.String() + strmangle.PutBuffer(buf) + + bomInfoUpsertCacheMut.RLock() + cache, cached := bomInfoUpsertCache[key] + bomInfoUpsertCacheMut.RUnlock() + + var err error + + if !cached { + insert, ret := insertColumns.InsertColumnSet( + bomInfoAllColumns, + bomInfoColumnsWithDefault, + bomInfoColumnsWithoutDefault, + nzDefaults, + ) + update := updateColumns.UpdateColumnSet( + bomInfoAllColumns, + bomInfoPrimaryKeyColumns, + ) + + if updateOnConflict && len(update) == 0 { + return errors.New("models: unable to upsert bom_info, could not build update column list") + } + + conflict := conflictColumns + if len(conflict) == 0 { + conflict = make([]string, len(bomInfoPrimaryKeyColumns)) + copy(conflict, bomInfoPrimaryKeyColumns) + } + cache.query = buildUpsertQueryCockroachDB(dialect, "\"bom_info\"", updateOnConflict, ret, update, conflict, insert) + + cache.valueMapping, err = queries.BindMapping(bomInfoType, bomInfoMapping, insert) + if err != nil { + return err + } + if len(ret) != 0 { + cache.retMapping, err = queries.BindMapping(bomInfoType, bomInfoMapping, ret) + if err != nil { + return err + } + } + } + + value := reflect.Indirect(reflect.ValueOf(o)) + vals := queries.ValuesFromMapping(value, cache.valueMapping) + var returns []interface{} + if len(cache.retMapping) != 0 { + returns = queries.PtrsFromMapping(value, cache.retMapping) + } + + if boil.DebugMode { + _, _ = fmt.Fprintln(boil.DebugWriter, cache.query) + _, _ = fmt.Fprintln(boil.DebugWriter, vals) + } + + if len(cache.retMapping) != 0 { + err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) + if err == sql.ErrNoRows { + err = nil // CockcorachDB doesn't return anything when there's no update + } + } else { + _, err = exec.ExecContext(ctx, cache.query, vals...) + } + if err != nil { + return errors.Wrap(err, "models: unable to upsert bom_info") + } + + if !cached { + bomInfoUpsertCacheMut.Lock() + bomInfoUpsertCache[key] = cache + bomInfoUpsertCacheMut.Unlock() + } + + return o.doAfterUpsertHooks(ctx, exec) +} diff --git a/internal/models/bom_info_test.go b/internal/models/bom_info_test.go new file mode 100644 index 00000000..c68e961d --- /dev/null +++ b/internal/models/bom_info_test.go @@ -0,0 +1,1039 @@ +// 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 ( + "bytes" + "context" + "reflect" + "testing" + + "github.com/volatiletech/randomize" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/strmangle" +) + +func testBomInfosUpsert(t *testing.T) { + t.Parallel() + + if len(bomInfoAllColumns) == len(bomInfoPrimaryKeyColumns) { + t.Skip("Skipping table with only primary key columns") + } + + seed := randomize.NewSeed() + var err error + // Attempt the INSERT side of an UPSERT + o := BomInfo{} + if err = randomize.Struct(seed, &o, bomInfoDBTypes, true); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Upsert(ctx, tx, false, nil, boil.Infer(), boil.Infer()); err != nil { + t.Errorf("Unable to upsert BomInfo: %s", err) + } + + count, err := BomInfos().Count(ctx, tx) + if err != nil { + t.Error(err) + } + if count != 1 { + t.Error("want one record, got:", count) + } + + // Attempt the UPDATE side of an UPSERT + if err = randomize.Struct(seed, &o, bomInfoDBTypes, false, bomInfoPrimaryKeyColumns...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + if err = o.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer()); err != nil { + t.Errorf("Unable to upsert BomInfo: %s", err) + } + + count, err = BomInfos().Count(ctx, tx) + if err != nil { + t.Error(err) + } + if count != 1 { + t.Error("want one record, got:", count) + } +} + +var ( + // Relationships sometimes use the reflection helper queries.Equal/queries.Assign + // so force a package dependency in case they don't. + _ = queries.Equal +) + +func testBomInfos(t *testing.T) { + t.Parallel() + + query := BomInfos() + + if query.Query == nil { + t.Error("expected a query, got nothing") + } +} + +func testBomInfosDelete(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BomInfo{} + if err = randomize.Struct(seed, o, bomInfoDBTypes, true, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + if rowsAff, err := o.Delete(ctx, tx); err != nil { + t.Error(err) + } else if rowsAff != 1 { + t.Error("should only have deleted one row, but affected:", rowsAff) + } + + count, err := BomInfos().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 0 { + t.Error("want zero records, got:", count) + } +} + +func testBomInfosQueryDeleteAll(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BomInfo{} + if err = randomize.Struct(seed, o, bomInfoDBTypes, true, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + if rowsAff, err := BomInfos().DeleteAll(ctx, tx); err != nil { + t.Error(err) + } else if rowsAff != 1 { + t.Error("should only have deleted one row, but affected:", rowsAff) + } + + count, err := BomInfos().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 0 { + t.Error("want zero records, got:", count) + } +} + +func testBomInfosSliceDeleteAll(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BomInfo{} + if err = randomize.Struct(seed, o, bomInfoDBTypes, true, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + slice := BomInfoSlice{o} + + if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil { + t.Error(err) + } else if rowsAff != 1 { + t.Error("should only have deleted one row, but affected:", rowsAff) + } + + count, err := BomInfos().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 0 { + t.Error("want zero records, got:", count) + } +} + +func testBomInfosExists(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BomInfo{} + if err = randomize.Struct(seed, o, bomInfoDBTypes, true, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + e, err := BomInfoExists(ctx, tx, o.ID) + if err != nil { + t.Errorf("Unable to check if BomInfo exists: %s", err) + } + if !e { + t.Errorf("Expected BomInfoExists to return true, but got false.") + } +} + +func testBomInfosFind(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BomInfo{} + if err = randomize.Struct(seed, o, bomInfoDBTypes, true, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + bomInfoFound, err := FindBomInfo(ctx, tx, o.ID) + if err != nil { + t.Error(err) + } + + if bomInfoFound == nil { + t.Error("want a record, got nil") + } +} + +func testBomInfosBind(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BomInfo{} + if err = randomize.Struct(seed, o, bomInfoDBTypes, true, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + if err = BomInfos().Bind(ctx, tx, o); err != nil { + t.Error(err) + } +} + +func testBomInfosOne(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BomInfo{} + if err = randomize.Struct(seed, o, bomInfoDBTypes, true, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + if x, err := BomInfos().One(ctx, tx); err != nil { + t.Error(err) + } else if x == nil { + t.Error("expected to get a non nil record") + } +} + +func testBomInfosAll(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + bomInfoOne := &BomInfo{} + bomInfoTwo := &BomInfo{} + if err = randomize.Struct(seed, bomInfoOne, bomInfoDBTypes, false, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + if err = randomize.Struct(seed, bomInfoTwo, bomInfoDBTypes, false, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = bomInfoOne.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + if err = bomInfoTwo.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + slice, err := BomInfos().All(ctx, tx) + if err != nil { + t.Error(err) + } + + if len(slice) != 2 { + t.Error("want 2 records, got:", len(slice)) + } +} + +func testBomInfosCount(t *testing.T) { + t.Parallel() + + var err error + seed := randomize.NewSeed() + bomInfoOne := &BomInfo{} + bomInfoTwo := &BomInfo{} + if err = randomize.Struct(seed, bomInfoOne, bomInfoDBTypes, false, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + if err = randomize.Struct(seed, bomInfoTwo, bomInfoDBTypes, false, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = bomInfoOne.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + if err = bomInfoTwo.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + count, err := BomInfos().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 2 { + t.Error("want 2 records, got:", count) + } +} + +func bomInfoBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *BomInfo) error { + *o = BomInfo{} + return nil +} + +func bomInfoAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *BomInfo) error { + *o = BomInfo{} + return nil +} + +func bomInfoAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *BomInfo) error { + *o = BomInfo{} + return nil +} + +func bomInfoBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *BomInfo) error { + *o = BomInfo{} + return nil +} + +func bomInfoAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *BomInfo) error { + *o = BomInfo{} + return nil +} + +func bomInfoBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *BomInfo) error { + *o = BomInfo{} + return nil +} + +func bomInfoAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *BomInfo) error { + *o = BomInfo{} + return nil +} + +func bomInfoBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *BomInfo) error { + *o = BomInfo{} + return nil +} + +func bomInfoAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *BomInfo) error { + *o = BomInfo{} + return nil +} + +func testBomInfosHooks(t *testing.T) { + t.Parallel() + + var err error + + ctx := context.Background() + empty := &BomInfo{} + o := &BomInfo{} + + seed := randomize.NewSeed() + if err = randomize.Struct(seed, o, bomInfoDBTypes, false); err != nil { + t.Errorf("Unable to randomize BomInfo object: %s", err) + } + + AddBomInfoHook(boil.BeforeInsertHook, bomInfoBeforeInsertHook) + if err = o.doBeforeInsertHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doBeforeInsertHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected BeforeInsertHook function to empty object, but got: %#v", o) + } + bomInfoBeforeInsertHooks = []BomInfoHook{} + + AddBomInfoHook(boil.AfterInsertHook, bomInfoAfterInsertHook) + if err = o.doAfterInsertHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doAfterInsertHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected AfterInsertHook function to empty object, but got: %#v", o) + } + bomInfoAfterInsertHooks = []BomInfoHook{} + + AddBomInfoHook(boil.AfterSelectHook, bomInfoAfterSelectHook) + if err = o.doAfterSelectHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doAfterSelectHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected AfterSelectHook function to empty object, but got: %#v", o) + } + bomInfoAfterSelectHooks = []BomInfoHook{} + + AddBomInfoHook(boil.BeforeUpdateHook, bomInfoBeforeUpdateHook) + if err = o.doBeforeUpdateHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doBeforeUpdateHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected BeforeUpdateHook function to empty object, but got: %#v", o) + } + bomInfoBeforeUpdateHooks = []BomInfoHook{} + + AddBomInfoHook(boil.AfterUpdateHook, bomInfoAfterUpdateHook) + if err = o.doAfterUpdateHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doAfterUpdateHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected AfterUpdateHook function to empty object, but got: %#v", o) + } + bomInfoAfterUpdateHooks = []BomInfoHook{} + + AddBomInfoHook(boil.BeforeDeleteHook, bomInfoBeforeDeleteHook) + if err = o.doBeforeDeleteHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doBeforeDeleteHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected BeforeDeleteHook function to empty object, but got: %#v", o) + } + bomInfoBeforeDeleteHooks = []BomInfoHook{} + + AddBomInfoHook(boil.AfterDeleteHook, bomInfoAfterDeleteHook) + if err = o.doAfterDeleteHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doAfterDeleteHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected AfterDeleteHook function to empty object, but got: %#v", o) + } + bomInfoAfterDeleteHooks = []BomInfoHook{} + + AddBomInfoHook(boil.BeforeUpsertHook, bomInfoBeforeUpsertHook) + if err = o.doBeforeUpsertHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doBeforeUpsertHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected BeforeUpsertHook function to empty object, but got: %#v", o) + } + bomInfoBeforeUpsertHooks = []BomInfoHook{} + + AddBomInfoHook(boil.AfterUpsertHook, bomInfoAfterUpsertHook) + if err = o.doAfterUpsertHooks(ctx, nil); err != nil { + t.Errorf("Unable to execute doAfterUpsertHooks: %s", err) + } + if !reflect.DeepEqual(o, empty) { + t.Errorf("Expected AfterUpsertHook function to empty object, but got: %#v", o) + } + bomInfoAfterUpsertHooks = []BomInfoHook{} +} + +func testBomInfosInsert(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BomInfo{} + if err = randomize.Struct(seed, o, bomInfoDBTypes, true, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + count, err := BomInfos().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 1 { + t.Error("want one record, got:", count) + } +} + +func testBomInfosInsertWhitelist(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BomInfo{} + if err = randomize.Struct(seed, o, bomInfoDBTypes, true); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Whitelist(bomInfoColumnsWithoutDefault...)); err != nil { + t.Error(err) + } + + count, err := BomInfos().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 1 { + t.Error("want one record, got:", count) + } +} + +func testBomInfoToManyAocMacAddressBoms(t *testing.T) { + var err error + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + + var a BomInfo + var b, c AocMacAddressBom + + seed := randomize.NewSeed() + if err = randomize.Struct(seed, &a, bomInfoDBTypes, true, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + if err := a.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + + if err = randomize.Struct(seed, &b, aocMacAddressBomDBTypes, false, aocMacAddressBomColumnsWithDefault...); err != nil { + t.Fatal(err) + } + if err = randomize.Struct(seed, &c, aocMacAddressBomDBTypes, false, aocMacAddressBomColumnsWithDefault...); err != nil { + t.Fatal(err) + } + + b.BomInfoID = a.ID + c.BomInfoID = a.ID + + if err = b.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + if err = c.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + + check, err := a.AocMacAddressBoms().All(ctx, tx) + if err != nil { + t.Fatal(err) + } + + bFound, cFound := false, false + for _, v := range check { + if v.BomInfoID == b.BomInfoID { + bFound = true + } + if v.BomInfoID == c.BomInfoID { + cFound = true + } + } + + if !bFound { + t.Error("expected to find b") + } + if !cFound { + t.Error("expected to find c") + } + + slice := BomInfoSlice{&a} + if err = a.L.LoadAocMacAddressBoms(ctx, tx, false, (*[]*BomInfo)(&slice), nil); err != nil { + t.Fatal(err) + } + if got := len(a.R.AocMacAddressBoms); got != 2 { + t.Error("number of eager loaded records wrong, got:", got) + } + + a.R.AocMacAddressBoms = nil + if err = a.L.LoadAocMacAddressBoms(ctx, tx, true, &a, nil); err != nil { + t.Fatal(err) + } + if got := len(a.R.AocMacAddressBoms); got != 2 { + t.Error("number of eager loaded records wrong, got:", got) + } + + if t.Failed() { + t.Logf("%#v", check) + } +} + +func testBomInfoToManyBMCMacAddressBoms(t *testing.T) { + var err error + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + + var a BomInfo + var b, c BMCMacAddressBom + + seed := randomize.NewSeed() + if err = randomize.Struct(seed, &a, bomInfoDBTypes, true, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + if err := a.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + + if err = randomize.Struct(seed, &b, bmcMacAddressBomDBTypes, false, bmcMacAddressBomColumnsWithDefault...); err != nil { + t.Fatal(err) + } + if err = randomize.Struct(seed, &c, bmcMacAddressBomDBTypes, false, bmcMacAddressBomColumnsWithDefault...); err != nil { + t.Fatal(err) + } + + b.BomInfoID = a.ID + c.BomInfoID = a.ID + + if err = b.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + if err = c.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + + check, err := a.BMCMacAddressBoms().All(ctx, tx) + if err != nil { + t.Fatal(err) + } + + bFound, cFound := false, false + for _, v := range check { + if v.BomInfoID == b.BomInfoID { + bFound = true + } + if v.BomInfoID == c.BomInfoID { + cFound = true + } + } + + if !bFound { + t.Error("expected to find b") + } + if !cFound { + t.Error("expected to find c") + } + + slice := BomInfoSlice{&a} + if err = a.L.LoadBMCMacAddressBoms(ctx, tx, false, (*[]*BomInfo)(&slice), nil); err != nil { + t.Fatal(err) + } + if got := len(a.R.BMCMacAddressBoms); got != 2 { + t.Error("number of eager loaded records wrong, got:", got) + } + + a.R.BMCMacAddressBoms = nil + if err = a.L.LoadBMCMacAddressBoms(ctx, tx, true, &a, nil); err != nil { + t.Fatal(err) + } + if got := len(a.R.BMCMacAddressBoms); got != 2 { + t.Error("number of eager loaded records wrong, got:", got) + } + + if t.Failed() { + t.Logf("%#v", check) + } +} + +func testBomInfoToManyAddOpAocMacAddressBoms(t *testing.T) { + var err error + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + + var a BomInfo + var b, c, d, e AocMacAddressBom + + seed := randomize.NewSeed() + if err = randomize.Struct(seed, &a, bomInfoDBTypes, false, strmangle.SetComplement(bomInfoPrimaryKeyColumns, bomInfoColumnsWithoutDefault)...); err != nil { + t.Fatal(err) + } + foreigners := []*AocMacAddressBom{&b, &c, &d, &e} + for _, x := range foreigners { + if err = randomize.Struct(seed, x, aocMacAddressBomDBTypes, false, strmangle.SetComplement(aocMacAddressBomPrimaryKeyColumns, aocMacAddressBomColumnsWithoutDefault)...); err != nil { + t.Fatal(err) + } + } + + if err := a.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + if err = b.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + if err = c.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + + foreignersSplitByInsertion := [][]*AocMacAddressBom{ + {&b, &c}, + {&d, &e}, + } + + for i, x := range foreignersSplitByInsertion { + err = a.AddAocMacAddressBoms(ctx, tx, i != 0, x...) + if err != nil { + t.Fatal(err) + } + + first := x[0] + second := x[1] + + if a.ID != first.BomInfoID { + t.Error("foreign key was wrong value", a.ID, first.BomInfoID) + } + if a.ID != second.BomInfoID { + t.Error("foreign key was wrong value", a.ID, second.BomInfoID) + } + + if first.R.BomInfo != &a { + t.Error("relationship was not added properly to the foreign slice") + } + if second.R.BomInfo != &a { + t.Error("relationship was not added properly to the foreign slice") + } + + if a.R.AocMacAddressBoms[i*2] != first { + t.Error("relationship struct slice not set to correct value") + } + if a.R.AocMacAddressBoms[i*2+1] != second { + t.Error("relationship struct slice not set to correct value") + } + + count, err := a.AocMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Fatal(err) + } + if want := int64((i + 1) * 2); count != want { + t.Error("want", want, "got", count) + } + } +} +func testBomInfoToManyAddOpBMCMacAddressBoms(t *testing.T) { + var err error + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + + var a BomInfo + var b, c, d, e BMCMacAddressBom + + seed := randomize.NewSeed() + if err = randomize.Struct(seed, &a, bomInfoDBTypes, false, strmangle.SetComplement(bomInfoPrimaryKeyColumns, bomInfoColumnsWithoutDefault)...); err != nil { + t.Fatal(err) + } + foreigners := []*BMCMacAddressBom{&b, &c, &d, &e} + for _, x := range foreigners { + if err = randomize.Struct(seed, x, bmcMacAddressBomDBTypes, false, strmangle.SetComplement(bmcMacAddressBomPrimaryKeyColumns, bmcMacAddressBomColumnsWithoutDefault)...); err != nil { + t.Fatal(err) + } + } + + if err := a.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + if err = b.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + if err = c.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + + foreignersSplitByInsertion := [][]*BMCMacAddressBom{ + {&b, &c}, + {&d, &e}, + } + + for i, x := range foreignersSplitByInsertion { + err = a.AddBMCMacAddressBoms(ctx, tx, i != 0, x...) + if err != nil { + t.Fatal(err) + } + + first := x[0] + second := x[1] + + if a.ID != first.BomInfoID { + t.Error("foreign key was wrong value", a.ID, first.BomInfoID) + } + if a.ID != second.BomInfoID { + t.Error("foreign key was wrong value", a.ID, second.BomInfoID) + } + + if first.R.BomInfo != &a { + t.Error("relationship was not added properly to the foreign slice") + } + if second.R.BomInfo != &a { + t.Error("relationship was not added properly to the foreign slice") + } + + if a.R.BMCMacAddressBoms[i*2] != first { + t.Error("relationship struct slice not set to correct value") + } + if a.R.BMCMacAddressBoms[i*2+1] != second { + t.Error("relationship struct slice not set to correct value") + } + + count, err := a.BMCMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Fatal(err) + } + if want := int64((i + 1) * 2); count != want { + t.Error("want", want, "got", count) + } + } +} + +func testBomInfosReload(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BomInfo{} + if err = randomize.Struct(seed, o, bomInfoDBTypes, true, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + if err = o.Reload(ctx, tx); err != nil { + t.Error(err) + } +} + +func testBomInfosReloadAll(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BomInfo{} + if err = randomize.Struct(seed, o, bomInfoDBTypes, true, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + slice := BomInfoSlice{o} + + if err = slice.ReloadAll(ctx, tx); err != nil { + t.Error(err) + } +} + +func testBomInfosSelect(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &BomInfo{} + if err = randomize.Struct(seed, o, bomInfoDBTypes, true, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + slice, err := BomInfos().All(ctx, tx) + if err != nil { + t.Error(err) + } + + if len(slice) != 1 { + t.Error("want one record, got:", len(slice)) + } +} + +var ( + bomInfoDBTypes = map[string]string{`ID`: `uuid`, `SerialNum`: `string`, `AocMacAddress`: `string`, `BMCMacAddress`: `string`, `NumDefiPmi`: `string`, `NumDefPWD`: `string`, `Metro`: `string`} + _ = bytes.MinRead +) + +func testBomInfosUpdate(t *testing.T) { + t.Parallel() + + if 0 == len(bomInfoPrimaryKeyColumns) { + t.Skip("Skipping table with no primary key columns") + } + if len(bomInfoAllColumns) == len(bomInfoPrimaryKeyColumns) { + t.Skip("Skipping table with only primary key columns") + } + + seed := randomize.NewSeed() + var err error + o := &BomInfo{} + if err = randomize.Struct(seed, o, bomInfoDBTypes, true, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + count, err := BomInfos().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 1 { + t.Error("want one record, got:", count) + } + + if err = randomize.Struct(seed, o, bomInfoDBTypes, true, bomInfoPrimaryKeyColumns...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } else if rowsAff != 1 { + t.Error("should only affect one row but affected", rowsAff) + } +} + +func testBomInfosSliceUpdateAll(t *testing.T) { + t.Parallel() + + if len(bomInfoAllColumns) == len(bomInfoPrimaryKeyColumns) { + t.Skip("Skipping table with only primary key columns") + } + + seed := randomize.NewSeed() + var err error + o := &BomInfo{} + if err = randomize.Struct(seed, o, bomInfoDBTypes, true, bomInfoColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + count, err := BomInfos().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 1 { + t.Error("want one record, got:", count) + } + + if err = randomize.Struct(seed, o, bomInfoDBTypes, true, bomInfoPrimaryKeyColumns...); err != nil { + t.Errorf("Unable to randomize BomInfo struct: %s", err) + } + + // Remove Primary keys and unique columns from what we plan to update + var fields []string + if strmangle.StringSliceMatch(bomInfoAllColumns, bomInfoPrimaryKeyColumns) { + fields = bomInfoAllColumns + } else { + fields = strmangle.SetComplement( + bomInfoAllColumns, + bomInfoPrimaryKeyColumns, + ) + } + + value := reflect.Indirect(reflect.ValueOf(o)) + typ := reflect.TypeOf(o).Elem() + n := typ.NumField() + + updateMap := M{} + for _, col := range fields { + for i := 0; i < n; i++ { + f := typ.Field(i) + if f.Tag.Get("boil") == col { + updateMap[col] = value.Field(i).Interface() + } + } + } + + slice := BomInfoSlice{o} + if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil { + t.Error(err) + } else if rowsAff != 1 { + t.Error("wanted one record updated but got", rowsAff) + } +} diff --git a/internal/models/crdb_suites_test.go b/internal/models/crdb_suites_test.go index 984cf615..3fb2416f 100644 --- a/internal/models/crdb_suites_test.go +++ b/internal/models/crdb_suites_test.go @@ -6,8 +6,11 @@ package models import "testing" func TestUpsert(t *testing.T) { + t.Run("AocMacAddressBoms", testAocMacAddressBomsUpsert) t.Run("Attributes", testAttributesUpsert) t.Run("AttributesFirmwareSets", testAttributesFirmwareSetsUpsert) + t.Run("BMCMacAddressBoms", testBMCMacAddressBomsUpsert) + t.Run("BomInfos", testBomInfosUpsert) t.Run("ComponentFirmwareSets", testComponentFirmwareSetsUpsert) t.Run("ComponentFirmwareSetMaps", testComponentFirmwareSetMapsUpsert) t.Run("ComponentFirmwareVersions", testComponentFirmwareVersionsUpsert)