diff --git a/db/migrations/00021_bom.sql b/db/migrations/00021_bom.sql new file mode 100644 index 00000000..14d7f220 --- /dev/null +++ b/db/migrations/00021_bom.sql @@ -0,0 +1,32 @@ +-- +goose Up +-- +goose StatementBegin + +CREATE TABLE bom_info ( + serial_num STRING PRIMARY KEY NOT NULL, + mac_aoc_address STRING NULL, + num_defi_pmi STRING NULL, + num_def_pwd STRING NULL, + metro STRING NULL +); + +CREATE TABLE mac_aoc_address_bom ( + mac_aoc_address STRING PRIMARY KEY NOT NULL, + serial_num STRING NOT NULL REFERENCES bom_info(serial_num) ON DELETE CASCADE +); + +CREATE TABLE bmc_mac_address_bom ( + bmc_mac_address STRING PRIMARY KEY NOT NULL, + serial_num STRING NOT NULL REFERENCES bom_info(serial_num) 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/bmc_mac_address_bom.go b/internal/models/bmc_mac_address_bom.go new file mode 100644 index 00000000..a5da1a52 --- /dev/null +++ b/internal/models/bmc_mac_address_bom.go @@ -0,0 +1,1062 @@ +// 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/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 { + BMCMacAddress string `boil:"bmc_mac_address" json:"bmc_mac_address" toml:"bmc_mac_address" yaml:"bmc_mac_address"` + SerialNum string `boil:"serial_num" json:"serial_num" toml:"serial_num" yaml:"serial_num"` + + R *bmcMacAddressBomR `boil:"-" json:"-" toml:"-" yaml:"-"` + L bmcMacAddressBomL `boil:"-" json:"-" toml:"-" yaml:"-"` +} + +var BMCMacAddressBomColumns = struct { + BMCMacAddress string + SerialNum string +}{ + BMCMacAddress: "bmc_mac_address", + SerialNum: "serial_num", +} + +var BMCMacAddressBomTableColumns = struct { + BMCMacAddress string + SerialNum string +}{ + BMCMacAddress: "bmc_mac_address_bom.bmc_mac_address", + SerialNum: "bmc_mac_address_bom.serial_num", +} + +// Generated where + +var BMCMacAddressBomWhere = struct { + BMCMacAddress whereHelperstring + SerialNum whereHelperstring +}{ + BMCMacAddress: whereHelperstring{field: "\"bmc_mac_address_bom\".\"bmc_mac_address\""}, + SerialNum: whereHelperstring{field: "\"bmc_mac_address_bom\".\"serial_num\""}, +} + +// BMCMacAddressBomRels is where relationship names are stored. +var BMCMacAddressBomRels = struct { + SerialNumBomInfo string +}{ + SerialNumBomInfo: "SerialNumBomInfo", +} + +// bmcMacAddressBomR is where relationships are stored. +type bmcMacAddressBomR struct { + SerialNumBomInfo *BomInfo `boil:"SerialNumBomInfo" json:"SerialNumBomInfo" toml:"SerialNumBomInfo" yaml:"SerialNumBomInfo"` +} + +// NewStruct creates a new relationship struct +func (*bmcMacAddressBomR) NewStruct() *bmcMacAddressBomR { + return &bmcMacAddressBomR{} +} + +func (r *bmcMacAddressBomR) GetSerialNumBomInfo() *BomInfo { + if r == nil { + return nil + } + return r.SerialNumBomInfo +} + +// bmcMacAddressBomL is where Load methods for each relationship are stored. +type bmcMacAddressBomL struct{} + +var ( + bmcMacAddressBomAllColumns = []string{"bmc_mac_address", "serial_num"} + bmcMacAddressBomColumnsWithoutDefault = []string{"bmc_mac_address", "serial_num"} + bmcMacAddressBomColumnsWithDefault = []string{} + bmcMacAddressBomPrimaryKeyColumns = []string{"bmc_mac_address"} + 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 +} + +// SerialNumBomInfo pointed to by the foreign key. +func (o *BMCMacAddressBom) SerialNumBomInfo(mods ...qm.QueryMod) bomInfoQuery { + queryMods := []qm.QueryMod{ + qm.Where("\"serial_num\" = ?", o.SerialNum), + } + + queryMods = append(queryMods, mods...) + + return BomInfos(queryMods...) +} + +// LoadSerialNumBomInfo allows an eager lookup of values, cached into the +// loaded structs of the objects. This is for an N-1 relationship. +func (bmcMacAddressBomL) LoadSerialNumBomInfo(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.SerialNum) + + } else { + Outer: + for _, obj := range slice { + if obj.R == nil { + obj.R = &bmcMacAddressBomR{} + } + + for _, a := range args { + if a == obj.SerialNum { + continue Outer + } + } + + args = append(args, obj.SerialNum) + + } + } + + if len(args) == 0 { + return nil + } + + query := NewQuery( + qm.From(`bom_info`), + qm.WhereIn(`bom_info.serial_num 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.SerialNumBomInfo = foreign + if foreign.R == nil { + foreign.R = &bomInfoR{} + } + foreign.R.SerialNumBMCMacAddressBoms = append(foreign.R.SerialNumBMCMacAddressBoms, object) + return nil + } + + for _, local := range slice { + for _, foreign := range resultSlice { + if local.SerialNum == foreign.SerialNum { + local.R.SerialNumBomInfo = foreign + if foreign.R == nil { + foreign.R = &bomInfoR{} + } + foreign.R.SerialNumBMCMacAddressBoms = append(foreign.R.SerialNumBMCMacAddressBoms, local) + break + } + } + } + + return nil +} + +// SetSerialNumBomInfo of the bmcMacAddressBom to the related item. +// Sets o.R.SerialNumBomInfo to related. +// Adds o to related.R.SerialNumBMCMacAddressBoms. +func (o *BMCMacAddressBom) SetSerialNumBomInfo(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{"serial_num"}), + strmangle.WhereClause("\"", "\"", 2, bmcMacAddressBomPrimaryKeyColumns), + ) + values := []interface{}{related.SerialNum, o.BMCMacAddress} + + 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.SerialNum = related.SerialNum + if o.R == nil { + o.R = &bmcMacAddressBomR{ + SerialNumBomInfo: related, + } + } else { + o.R.SerialNumBomInfo = related + } + + if related.R == nil { + related.R = &bomInfoR{ + SerialNumBMCMacAddressBoms: BMCMacAddressBomSlice{o}, + } + } else { + related.R.SerialNumBMCMacAddressBoms = append(related.R.SerialNumBMCMacAddressBoms, 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, bMCMacAddress 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 \"bmc_mac_address\"=$1", sel, + ) + + q := queries.Raw(query, bMCMacAddress) + + 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 \"bmc_mac_address\"=$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.BMCMacAddress) + 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, bMCMacAddress string) (bool, error) { + var exists bool + sql := "select exists(select 1 from \"bmc_mac_address_bom\" where \"bmc_mac_address\"=$1 limit 1)" + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, bMCMacAddress) + } + row := exec.QueryRowContext(ctx, sql, bMCMacAddress) + + 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..48f407a7 --- /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.BMCMacAddress) + 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.BMCMacAddress) + 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 testBMCMacAddressBomToOneBomInfoUsingSerialNumBomInfo(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.SerialNum = foreign.SerialNum + if err := local.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + + check, err := local.SerialNumBomInfo().One(ctx, tx) + if err != nil { + t.Fatal(err) + } + + if check.SerialNum != foreign.SerialNum { + t.Errorf("want: %v, got %v", foreign.SerialNum, check.SerialNum) + } + + slice := BMCMacAddressBomSlice{&local} + if err = local.L.LoadSerialNumBomInfo(ctx, tx, false, (*[]*BMCMacAddressBom)(&slice), nil); err != nil { + t.Fatal(err) + } + if local.R.SerialNumBomInfo == nil { + t.Error("struct should have been eager loaded") + } + + local.R.SerialNumBomInfo = nil + if err = local.L.LoadSerialNumBomInfo(ctx, tx, true, &local, nil); err != nil { + t.Fatal(err) + } + if local.R.SerialNumBomInfo == nil { + t.Error("struct should have been eager loaded") + } +} + +func testBMCMacAddressBomToOneSetOpBomInfoUsingSerialNumBomInfo(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.SetSerialNumBomInfo(ctx, tx, i != 0, x) + if err != nil { + t.Fatal(err) + } + + if a.R.SerialNumBomInfo != x { + t.Error("relationship struct not set to correct value") + } + + if x.R.SerialNumBMCMacAddressBoms[0] != &a { + t.Error("failed to append to foreign relationship struct") + } + if a.SerialNum != x.SerialNum { + t.Error("foreign key was wrong value", a.SerialNum) + } + + zero := reflect.Zero(reflect.TypeOf(a.SerialNum)) + reflect.Indirect(reflect.ValueOf(&a.SerialNum)).Set(zero) + + if err = a.Reload(ctx, tx); err != nil { + t.Fatal("failed to reload", err) + } + + if a.SerialNum != x.SerialNum { + t.Error("foreign key was wrong value", a.SerialNum, x.SerialNum) + } + } +} + +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{`BMCMacAddress`: `string`, `SerialNum`: `string`} + _ = 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..a36cf5bb 100644 --- a/internal/models/boil_suites_test.go +++ b/internal/models/boil_suites_test.go @@ -14,9 +14,12 @@ import "testing" func TestParent(t *testing.T) { 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) + t.Run("MacAocAddressBoms", testMacAocAddressBoms) t.Run("ServerComponentTypes", testServerComponentTypes) t.Run("ServerComponents", testServerComponents) t.Run("ServerCredentialTypes", testServerCredentialTypes) @@ -40,9 +43,12 @@ func TestSliceSoftDeleteAll(t *testing.T) { func TestDelete(t *testing.T) { 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) + t.Run("MacAocAddressBoms", testMacAocAddressBomsDelete) t.Run("ServerComponentTypes", testServerComponentTypesDelete) t.Run("ServerComponents", testServerComponentsDelete) t.Run("ServerCredentialTypes", testServerCredentialTypesDelete) @@ -54,9 +60,12 @@ func TestDelete(t *testing.T) { func TestQueryDeleteAll(t *testing.T) { 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) + t.Run("MacAocAddressBoms", testMacAocAddressBomsQueryDeleteAll) t.Run("ServerComponentTypes", testServerComponentTypesQueryDeleteAll) t.Run("ServerComponents", testServerComponentsQueryDeleteAll) t.Run("ServerCredentialTypes", testServerCredentialTypesQueryDeleteAll) @@ -68,9 +77,12 @@ func TestQueryDeleteAll(t *testing.T) { func TestSliceDeleteAll(t *testing.T) { 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) + t.Run("MacAocAddressBoms", testMacAocAddressBomsSliceDeleteAll) t.Run("ServerComponentTypes", testServerComponentTypesSliceDeleteAll) t.Run("ServerComponents", testServerComponentsSliceDeleteAll) t.Run("ServerCredentialTypes", testServerCredentialTypesSliceDeleteAll) @@ -82,9 +94,12 @@ func TestSliceDeleteAll(t *testing.T) { func TestExists(t *testing.T) { 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) + t.Run("MacAocAddressBoms", testMacAocAddressBomsExists) t.Run("ServerComponentTypes", testServerComponentTypesExists) t.Run("ServerComponents", testServerComponentsExists) t.Run("ServerCredentialTypes", testServerCredentialTypesExists) @@ -96,9 +111,12 @@ func TestExists(t *testing.T) { func TestFind(t *testing.T) { 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) + t.Run("MacAocAddressBoms", testMacAocAddressBomsFind) t.Run("ServerComponentTypes", testServerComponentTypesFind) t.Run("ServerComponents", testServerComponentsFind) t.Run("ServerCredentialTypes", testServerCredentialTypesFind) @@ -110,9 +128,12 @@ func TestFind(t *testing.T) { func TestBind(t *testing.T) { 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) + t.Run("MacAocAddressBoms", testMacAocAddressBomsBind) t.Run("ServerComponentTypes", testServerComponentTypesBind) t.Run("ServerComponents", testServerComponentsBind) t.Run("ServerCredentialTypes", testServerCredentialTypesBind) @@ -124,9 +145,12 @@ func TestBind(t *testing.T) { func TestOne(t *testing.T) { 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) + t.Run("MacAocAddressBoms", testMacAocAddressBomsOne) t.Run("ServerComponentTypes", testServerComponentTypesOne) t.Run("ServerComponents", testServerComponentsOne) t.Run("ServerCredentialTypes", testServerCredentialTypesOne) @@ -138,9 +162,12 @@ func TestOne(t *testing.T) { func TestAll(t *testing.T) { 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) + t.Run("MacAocAddressBoms", testMacAocAddressBomsAll) t.Run("ServerComponentTypes", testServerComponentTypesAll) t.Run("ServerComponents", testServerComponentsAll) t.Run("ServerCredentialTypes", testServerCredentialTypesAll) @@ -152,9 +179,12 @@ func TestAll(t *testing.T) { func TestCount(t *testing.T) { 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) + t.Run("MacAocAddressBoms", testMacAocAddressBomsCount) t.Run("ServerComponentTypes", testServerComponentTypesCount) t.Run("ServerComponents", testServerComponentsCount) t.Run("ServerCredentialTypes", testServerCredentialTypesCount) @@ -166,9 +196,12 @@ func TestCount(t *testing.T) { func TestHooks(t *testing.T) { 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) + t.Run("MacAocAddressBoms", testMacAocAddressBomsHooks) t.Run("ServerComponentTypes", testServerComponentTypesHooks) t.Run("ServerComponents", testServerComponentsHooks) t.Run("ServerCredentialTypes", testServerCredentialTypesHooks) @@ -182,12 +215,18 @@ func TestInsert(t *testing.T) { 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) t.Run("ComponentFirmwareSetMaps", testComponentFirmwareSetMapsInsertWhitelist) t.Run("ComponentFirmwareVersions", testComponentFirmwareVersionsInsert) t.Run("ComponentFirmwareVersions", testComponentFirmwareVersionsInsertWhitelist) + t.Run("MacAocAddressBoms", testMacAocAddressBomsInsert) + t.Run("MacAocAddressBoms", testMacAocAddressBomsInsertWhitelist) t.Run("ServerComponentTypes", testServerComponentTypesInsert) t.Run("ServerComponentTypes", testServerComponentTypesInsertWhitelist) t.Run("ServerComponents", testServerComponentsInsert) @@ -208,8 +247,10 @@ func TestToOne(t *testing.T) { t.Run("AttributeToServerUsingServer", testAttributeToOneServerUsingServer) t.Run("AttributeToServerComponentUsingServerComponent", testAttributeToOneServerComponentUsingServerComponent) t.Run("AttributesFirmwareSetToComponentFirmwareSetUsingFirmwareSet", testAttributesFirmwareSetToOneComponentFirmwareSetUsingFirmwareSet) + t.Run("BMCMacAddressBomToBomInfoUsingSerialNumBomInfo", testBMCMacAddressBomToOneBomInfoUsingSerialNumBomInfo) t.Run("ComponentFirmwareSetMapToComponentFirmwareSetUsingFirmwareSet", testComponentFirmwareSetMapToOneComponentFirmwareSetUsingFirmwareSet) t.Run("ComponentFirmwareSetMapToComponentFirmwareVersionUsingFirmware", testComponentFirmwareSetMapToOneComponentFirmwareVersionUsingFirmware) + t.Run("MacAocAddressBomToBomInfoUsingSerialNumBomInfo", testMacAocAddressBomToOneBomInfoUsingSerialNumBomInfo) t.Run("ServerComponentToServerUsingServer", testServerComponentToOneServerUsingServer) t.Run("ServerComponentToServerComponentTypeUsingServerComponentType", testServerComponentToOneServerComponentTypeUsingServerComponentType) t.Run("ServerCredentialToServerCredentialTypeUsingServerCredentialType", testServerCredentialToOneServerCredentialTypeUsingServerCredentialType) @@ -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("BomInfoToSerialNumBMCMacAddressBoms", testBomInfoToManySerialNumBMCMacAddressBoms) + t.Run("BomInfoToSerialNumMacAocAddressBoms", testBomInfoToManySerialNumMacAocAddressBoms) t.Run("ComponentFirmwareSetToFirmwareSetAttributesFirmwareSets", testComponentFirmwareSetToManyFirmwareSetAttributesFirmwareSets) t.Run("ComponentFirmwareSetToFirmwareSetComponentFirmwareSetMaps", testComponentFirmwareSetToManyFirmwareSetComponentFirmwareSetMaps) t.Run("ComponentFirmwareVersionToFirmwareComponentFirmwareSetMaps", testComponentFirmwareVersionToManyFirmwareComponentFirmwareSetMaps) @@ -244,8 +287,10 @@ func TestToOneSet(t *testing.T) { t.Run("AttributeToServerUsingAttributes", testAttributeToOneSetOpServerUsingServer) t.Run("AttributeToServerComponentUsingAttributes", testAttributeToOneSetOpServerComponentUsingServerComponent) t.Run("AttributesFirmwareSetToComponentFirmwareSetUsingFirmwareSetAttributesFirmwareSets", testAttributesFirmwareSetToOneSetOpComponentFirmwareSetUsingFirmwareSet) + t.Run("BMCMacAddressBomToBomInfoUsingSerialNumBMCMacAddressBoms", testBMCMacAddressBomToOneSetOpBomInfoUsingSerialNumBomInfo) t.Run("ComponentFirmwareSetMapToComponentFirmwareSetUsingFirmwareSetComponentFirmwareSetMaps", testComponentFirmwareSetMapToOneSetOpComponentFirmwareSetUsingFirmwareSet) t.Run("ComponentFirmwareSetMapToComponentFirmwareVersionUsingFirmwareComponentFirmwareSetMaps", testComponentFirmwareSetMapToOneSetOpComponentFirmwareVersionUsingFirmware) + t.Run("MacAocAddressBomToBomInfoUsingSerialNumMacAocAddressBoms", testMacAocAddressBomToOneSetOpBomInfoUsingSerialNumBomInfo) t.Run("ServerComponentToServerUsingServerComponents", testServerComponentToOneSetOpServerUsingServer) t.Run("ServerComponentToServerComponentTypeUsingServerComponents", testServerComponentToOneSetOpServerComponentTypeUsingServerComponentType) t.Run("ServerCredentialToServerCredentialTypeUsingServerCredentials", testServerCredentialToOneSetOpServerCredentialTypeUsingServerCredentialType) @@ -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("BomInfoToSerialNumBMCMacAddressBoms", testBomInfoToManyAddOpSerialNumBMCMacAddressBoms) + t.Run("BomInfoToSerialNumMacAocAddressBoms", testBomInfoToManyAddOpSerialNumMacAocAddressBoms) t.Run("ComponentFirmwareSetToFirmwareSetAttributesFirmwareSets", testComponentFirmwareSetToManyAddOpFirmwareSetAttributesFirmwareSets) t.Run("ComponentFirmwareSetToFirmwareSetComponentFirmwareSetMaps", testComponentFirmwareSetToManyAddOpFirmwareSetComponentFirmwareSetMaps) t.Run("ComponentFirmwareVersionToFirmwareComponentFirmwareSetMaps", testComponentFirmwareVersionToManyAddOpFirmwareComponentFirmwareSetMaps) @@ -311,9 +358,12 @@ func TestToManyRemove(t *testing.T) { func TestReload(t *testing.T) { 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) + t.Run("MacAocAddressBoms", testMacAocAddressBomsReload) t.Run("ServerComponentTypes", testServerComponentTypesReload) t.Run("ServerComponents", testServerComponentsReload) t.Run("ServerCredentialTypes", testServerCredentialTypesReload) @@ -325,9 +375,12 @@ func TestReload(t *testing.T) { func TestReloadAll(t *testing.T) { 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) + t.Run("MacAocAddressBoms", testMacAocAddressBomsReloadAll) t.Run("ServerComponentTypes", testServerComponentTypesReloadAll) t.Run("ServerComponents", testServerComponentsReloadAll) t.Run("ServerCredentialTypes", testServerCredentialTypesReloadAll) @@ -339,9 +392,12 @@ func TestReloadAll(t *testing.T) { func TestSelect(t *testing.T) { 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) + t.Run("MacAocAddressBoms", testMacAocAddressBomsSelect) t.Run("ServerComponentTypes", testServerComponentTypesSelect) t.Run("ServerComponents", testServerComponentsSelect) t.Run("ServerCredentialTypes", testServerCredentialTypesSelect) @@ -353,9 +409,12 @@ func TestSelect(t *testing.T) { func TestUpdate(t *testing.T) { 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) + t.Run("MacAocAddressBoms", testMacAocAddressBomsUpdate) t.Run("ServerComponentTypes", testServerComponentTypesUpdate) t.Run("ServerComponents", testServerComponentsUpdate) t.Run("ServerCredentialTypes", testServerCredentialTypesUpdate) @@ -367,9 +426,12 @@ func TestUpdate(t *testing.T) { func TestSliceUpdateAll(t *testing.T) { 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) + t.Run("MacAocAddressBoms", testMacAocAddressBomsSliceUpdateAll) t.Run("ServerComponentTypes", testServerComponentTypesSliceUpdateAll) t.Run("ServerComponents", testServerComponentsSliceUpdateAll) t.Run("ServerCredentialTypes", testServerCredentialTypesSliceUpdateAll) diff --git a/internal/models/boil_table_names.go b/internal/models/boil_table_names.go index 4f33a8de..ebd7c1c3 100644 --- a/internal/models/boil_table_names.go +++ b/internal/models/boil_table_names.go @@ -6,9 +6,12 @@ package models var TableNames = struct { Attributes string AttributesFirmwareSet string + BMCMacAddressBom string + BomInfo string ComponentFirmwareSet string ComponentFirmwareSetMap string ComponentFirmwareVersion string + MacAocAddressBom string ServerComponentTypes string ServerComponents string ServerCredentialTypes string @@ -18,9 +21,12 @@ var TableNames = struct { }{ 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", + MacAocAddressBom: "mac_aoc_address_bom", ServerComponentTypes: "server_component_types", ServerComponents: "server_components", ServerCredentialTypes: "server_credential_types", diff --git a/internal/models/bom_info.go b/internal/models/bom_info.go new file mode 100644 index 00000000..1f72e196 --- /dev/null +++ b/internal/models/bom_info.go @@ -0,0 +1,1262 @@ +// 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 { + SerialNum string `boil:"serial_num" json:"serial_num" toml:"serial_num" yaml:"serial_num"` + MacAocAddress null.String `boil:"mac_aoc_address" json:"mac_aoc_address,omitempty" toml:"mac_aoc_address" yaml:"mac_aoc_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 { + SerialNum string + MacAocAddress string + NumDefiPmi string + NumDefPWD string + Metro string +}{ + SerialNum: "serial_num", + MacAocAddress: "mac_aoc_address", + NumDefiPmi: "num_defi_pmi", + NumDefPWD: "num_def_pwd", + Metro: "metro", +} + +var BomInfoTableColumns = struct { + SerialNum string + MacAocAddress string + NumDefiPmi string + NumDefPWD string + Metro string +}{ + SerialNum: "bom_info.serial_num", + MacAocAddress: "bom_info.mac_aoc_address", + NumDefiPmi: "bom_info.num_defi_pmi", + NumDefPWD: "bom_info.num_def_pwd", + Metro: "bom_info.metro", +} + +// Generated where + +var BomInfoWhere = struct { + SerialNum whereHelperstring + MacAocAddress whereHelpernull_String + NumDefiPmi whereHelpernull_String + NumDefPWD whereHelpernull_String + Metro whereHelpernull_String +}{ + SerialNum: whereHelperstring{field: "\"bom_info\".\"serial_num\""}, + MacAocAddress: whereHelpernull_String{field: "\"bom_info\".\"mac_aoc_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 { + SerialNumBMCMacAddressBoms string + SerialNumMacAocAddressBoms string +}{ + SerialNumBMCMacAddressBoms: "SerialNumBMCMacAddressBoms", + SerialNumMacAocAddressBoms: "SerialNumMacAocAddressBoms", +} + +// bomInfoR is where relationships are stored. +type bomInfoR struct { + SerialNumBMCMacAddressBoms BMCMacAddressBomSlice `boil:"SerialNumBMCMacAddressBoms" json:"SerialNumBMCMacAddressBoms" toml:"SerialNumBMCMacAddressBoms" yaml:"SerialNumBMCMacAddressBoms"` + SerialNumMacAocAddressBoms MacAocAddressBomSlice `boil:"SerialNumMacAocAddressBoms" json:"SerialNumMacAocAddressBoms" toml:"SerialNumMacAocAddressBoms" yaml:"SerialNumMacAocAddressBoms"` +} + +// NewStruct creates a new relationship struct +func (*bomInfoR) NewStruct() *bomInfoR { + return &bomInfoR{} +} + +func (r *bomInfoR) GetSerialNumBMCMacAddressBoms() BMCMacAddressBomSlice { + if r == nil { + return nil + } + return r.SerialNumBMCMacAddressBoms +} + +func (r *bomInfoR) GetSerialNumMacAocAddressBoms() MacAocAddressBomSlice { + if r == nil { + return nil + } + return r.SerialNumMacAocAddressBoms +} + +// bomInfoL is where Load methods for each relationship are stored. +type bomInfoL struct{} + +var ( + bomInfoAllColumns = []string{"serial_num", "mac_aoc_address", "num_defi_pmi", "num_def_pwd", "metro"} + bomInfoColumnsWithoutDefault = []string{"serial_num"} + bomInfoColumnsWithDefault = []string{"mac_aoc_address", "num_defi_pmi", "num_def_pwd", "metro"} + bomInfoPrimaryKeyColumns = []string{"serial_num"} + 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 +} + +// SerialNumBMCMacAddressBoms retrieves all the bmc_mac_address_bom's BMCMacAddressBoms with an executor via serial_num column. +func (o *BomInfo) SerialNumBMCMacAddressBoms(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\".\"serial_num\"=?", o.SerialNum), + ) + + return BMCMacAddressBoms(queryMods...) +} + +// SerialNumMacAocAddressBoms retrieves all the mac_aoc_address_bom's MacAocAddressBoms with an executor via serial_num column. +func (o *BomInfo) SerialNumMacAocAddressBoms(mods ...qm.QueryMod) macAocAddressBomQuery { + var queryMods []qm.QueryMod + if len(mods) != 0 { + queryMods = append(queryMods, mods...) + } + + queryMods = append(queryMods, + qm.Where("\"mac_aoc_address_bom\".\"serial_num\"=?", o.SerialNum), + ) + + return MacAocAddressBoms(queryMods...) +} + +// LoadSerialNumBMCMacAddressBoms 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) LoadSerialNumBMCMacAddressBoms(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.SerialNum) + } else { + Outer: + for _, obj := range slice { + if obj.R == nil { + obj.R = &bomInfoR{} + } + + for _, a := range args { + if a == obj.SerialNum { + continue Outer + } + } + + args = append(args, obj.SerialNum) + } + } + + if len(args) == 0 { + return nil + } + + query := NewQuery( + qm.From(`bmc_mac_address_bom`), + qm.WhereIn(`bmc_mac_address_bom.serial_num 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.SerialNumBMCMacAddressBoms = resultSlice + for _, foreign := range resultSlice { + if foreign.R == nil { + foreign.R = &bmcMacAddressBomR{} + } + foreign.R.SerialNumBomInfo = object + } + return nil + } + + for _, foreign := range resultSlice { + for _, local := range slice { + if local.SerialNum == foreign.SerialNum { + local.R.SerialNumBMCMacAddressBoms = append(local.R.SerialNumBMCMacAddressBoms, foreign) + if foreign.R == nil { + foreign.R = &bmcMacAddressBomR{} + } + foreign.R.SerialNumBomInfo = local + break + } + } + } + + return nil +} + +// LoadSerialNumMacAocAddressBoms 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) LoadSerialNumMacAocAddressBoms(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.SerialNum) + } else { + Outer: + for _, obj := range slice { + if obj.R == nil { + obj.R = &bomInfoR{} + } + + for _, a := range args { + if a == obj.SerialNum { + continue Outer + } + } + + args = append(args, obj.SerialNum) + } + } + + if len(args) == 0 { + return nil + } + + query := NewQuery( + qm.From(`mac_aoc_address_bom`), + qm.WhereIn(`mac_aoc_address_bom.serial_num 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 mac_aoc_address_bom") + } + + var resultSlice []*MacAocAddressBom + if err = queries.Bind(results, &resultSlice); err != nil { + return errors.Wrap(err, "failed to bind eager loaded slice mac_aoc_address_bom") + } + + if err = results.Close(); err != nil { + return errors.Wrap(err, "failed to close results in eager load on mac_aoc_address_bom") + } + if err = results.Err(); err != nil { + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for mac_aoc_address_bom") + } + + if len(macAocAddressBomAfterSelectHooks) != 0 { + for _, obj := range resultSlice { + if err := obj.doAfterSelectHooks(ctx, e); err != nil { + return err + } + } + } + if singular { + object.R.SerialNumMacAocAddressBoms = resultSlice + for _, foreign := range resultSlice { + if foreign.R == nil { + foreign.R = &macAocAddressBomR{} + } + foreign.R.SerialNumBomInfo = object + } + return nil + } + + for _, foreign := range resultSlice { + for _, local := range slice { + if local.SerialNum == foreign.SerialNum { + local.R.SerialNumMacAocAddressBoms = append(local.R.SerialNumMacAocAddressBoms, foreign) + if foreign.R == nil { + foreign.R = &macAocAddressBomR{} + } + foreign.R.SerialNumBomInfo = local + break + } + } + } + + return nil +} + +// AddSerialNumBMCMacAddressBoms adds the given related objects to the existing relationships +// of the bom_info, optionally inserting them as new records. +// Appends related to o.R.SerialNumBMCMacAddressBoms. +// Sets related.R.SerialNumBomInfo appropriately. +func (o *BomInfo) AddSerialNumBMCMacAddressBoms(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*BMCMacAddressBom) error { + var err error + for _, rel := range related { + if insert { + rel.SerialNum = o.SerialNum + 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{"serial_num"}), + strmangle.WhereClause("\"", "\"", 2, bmcMacAddressBomPrimaryKeyColumns), + ) + values := []interface{}{o.SerialNum, rel.BMCMacAddress} + + 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.SerialNum = o.SerialNum + } + } + + if o.R == nil { + o.R = &bomInfoR{ + SerialNumBMCMacAddressBoms: related, + } + } else { + o.R.SerialNumBMCMacAddressBoms = append(o.R.SerialNumBMCMacAddressBoms, related...) + } + + for _, rel := range related { + if rel.R == nil { + rel.R = &bmcMacAddressBomR{ + SerialNumBomInfo: o, + } + } else { + rel.R.SerialNumBomInfo = o + } + } + return nil +} + +// AddSerialNumMacAocAddressBoms adds the given related objects to the existing relationships +// of the bom_info, optionally inserting them as new records. +// Appends related to o.R.SerialNumMacAocAddressBoms. +// Sets related.R.SerialNumBomInfo appropriately. +func (o *BomInfo) AddSerialNumMacAocAddressBoms(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*MacAocAddressBom) error { + var err error + for _, rel := range related { + if insert { + rel.SerialNum = o.SerialNum + 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 \"mac_aoc_address_bom\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, []string{"serial_num"}), + strmangle.WhereClause("\"", "\"", 2, macAocAddressBomPrimaryKeyColumns), + ) + values := []interface{}{o.SerialNum, rel.MacAocAddress} + + 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.SerialNum = o.SerialNum + } + } + + if o.R == nil { + o.R = &bomInfoR{ + SerialNumMacAocAddressBoms: related, + } + } else { + o.R.SerialNumMacAocAddressBoms = append(o.R.SerialNumMacAocAddressBoms, related...) + } + + for _, rel := range related { + if rel.R == nil { + rel.R = &macAocAddressBomR{ + SerialNumBomInfo: o, + } + } else { + rel.R.SerialNumBomInfo = 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, serialNum 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 \"serial_num\"=$1", sel, + ) + + q := queries.Raw(query, serialNum) + + 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 \"serial_num\"=$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.SerialNum) + 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, serialNum string) (bool, error) { + var exists bool + sql := "select exists(select 1 from \"bom_info\" where \"serial_num\"=$1 limit 1)" + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, serialNum) + } + row := exec.QueryRowContext(ctx, sql, serialNum) + + 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..a442020c --- /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.SerialNum) + 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.SerialNum) + 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 testBomInfoToManySerialNumBMCMacAddressBoms(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.SerialNum = a.SerialNum + c.SerialNum = a.SerialNum + + 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.SerialNumBMCMacAddressBoms().All(ctx, tx) + if err != nil { + t.Fatal(err) + } + + bFound, cFound := false, false + for _, v := range check { + if v.SerialNum == b.SerialNum { + bFound = true + } + if v.SerialNum == c.SerialNum { + 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.LoadSerialNumBMCMacAddressBoms(ctx, tx, false, (*[]*BomInfo)(&slice), nil); err != nil { + t.Fatal(err) + } + if got := len(a.R.SerialNumBMCMacAddressBoms); got != 2 { + t.Error("number of eager loaded records wrong, got:", got) + } + + a.R.SerialNumBMCMacAddressBoms = nil + if err = a.L.LoadSerialNumBMCMacAddressBoms(ctx, tx, true, &a, nil); err != nil { + t.Fatal(err) + } + if got := len(a.R.SerialNumBMCMacAddressBoms); got != 2 { + t.Error("number of eager loaded records wrong, got:", got) + } + + if t.Failed() { + t.Logf("%#v", check) + } +} + +func testBomInfoToManySerialNumMacAocAddressBoms(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 MacAocAddressBom + + 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, macAocAddressBomDBTypes, false, macAocAddressBomColumnsWithDefault...); err != nil { + t.Fatal(err) + } + if err = randomize.Struct(seed, &c, macAocAddressBomDBTypes, false, macAocAddressBomColumnsWithDefault...); err != nil { + t.Fatal(err) + } + + b.SerialNum = a.SerialNum + c.SerialNum = a.SerialNum + + 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.SerialNumMacAocAddressBoms().All(ctx, tx) + if err != nil { + t.Fatal(err) + } + + bFound, cFound := false, false + for _, v := range check { + if v.SerialNum == b.SerialNum { + bFound = true + } + if v.SerialNum == c.SerialNum { + 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.LoadSerialNumMacAocAddressBoms(ctx, tx, false, (*[]*BomInfo)(&slice), nil); err != nil { + t.Fatal(err) + } + if got := len(a.R.SerialNumMacAocAddressBoms); got != 2 { + t.Error("number of eager loaded records wrong, got:", got) + } + + a.R.SerialNumMacAocAddressBoms = nil + if err = a.L.LoadSerialNumMacAocAddressBoms(ctx, tx, true, &a, nil); err != nil { + t.Fatal(err) + } + if got := len(a.R.SerialNumMacAocAddressBoms); got != 2 { + t.Error("number of eager loaded records wrong, got:", got) + } + + if t.Failed() { + t.Logf("%#v", check) + } +} + +func testBomInfoToManyAddOpSerialNumBMCMacAddressBoms(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.AddSerialNumBMCMacAddressBoms(ctx, tx, i != 0, x...) + if err != nil { + t.Fatal(err) + } + + first := x[0] + second := x[1] + + if a.SerialNum != first.SerialNum { + t.Error("foreign key was wrong value", a.SerialNum, first.SerialNum) + } + if a.SerialNum != second.SerialNum { + t.Error("foreign key was wrong value", a.SerialNum, second.SerialNum) + } + + if first.R.SerialNumBomInfo != &a { + t.Error("relationship was not added properly to the foreign slice") + } + if second.R.SerialNumBomInfo != &a { + t.Error("relationship was not added properly to the foreign slice") + } + + if a.R.SerialNumBMCMacAddressBoms[i*2] != first { + t.Error("relationship struct slice not set to correct value") + } + if a.R.SerialNumBMCMacAddressBoms[i*2+1] != second { + t.Error("relationship struct slice not set to correct value") + } + + count, err := a.SerialNumBMCMacAddressBoms().Count(ctx, tx) + if err != nil { + t.Fatal(err) + } + if want := int64((i + 1) * 2); count != want { + t.Error("want", want, "got", count) + } + } +} +func testBomInfoToManyAddOpSerialNumMacAocAddressBoms(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 MacAocAddressBom + + seed := randomize.NewSeed() + if err = randomize.Struct(seed, &a, bomInfoDBTypes, false, strmangle.SetComplement(bomInfoPrimaryKeyColumns, bomInfoColumnsWithoutDefault)...); err != nil { + t.Fatal(err) + } + foreigners := []*MacAocAddressBom{&b, &c, &d, &e} + for _, x := range foreigners { + if err = randomize.Struct(seed, x, macAocAddressBomDBTypes, false, strmangle.SetComplement(macAocAddressBomPrimaryKeyColumns, macAocAddressBomColumnsWithoutDefault)...); 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 := [][]*MacAocAddressBom{ + {&b, &c}, + {&d, &e}, + } + + for i, x := range foreignersSplitByInsertion { + err = a.AddSerialNumMacAocAddressBoms(ctx, tx, i != 0, x...) + if err != nil { + t.Fatal(err) + } + + first := x[0] + second := x[1] + + if a.SerialNum != first.SerialNum { + t.Error("foreign key was wrong value", a.SerialNum, first.SerialNum) + } + if a.SerialNum != second.SerialNum { + t.Error("foreign key was wrong value", a.SerialNum, second.SerialNum) + } + + if first.R.SerialNumBomInfo != &a { + t.Error("relationship was not added properly to the foreign slice") + } + if second.R.SerialNumBomInfo != &a { + t.Error("relationship was not added properly to the foreign slice") + } + + if a.R.SerialNumMacAocAddressBoms[i*2] != first { + t.Error("relationship struct slice not set to correct value") + } + if a.R.SerialNumMacAocAddressBoms[i*2+1] != second { + t.Error("relationship struct slice not set to correct value") + } + + count, err := a.SerialNumMacAocAddressBoms().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{`SerialNum`: `string`, `MacAocAddress`: `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..ffcc371f 100644 --- a/internal/models/crdb_suites_test.go +++ b/internal/models/crdb_suites_test.go @@ -8,9 +8,12 @@ import "testing" func TestUpsert(t *testing.T) { 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) + t.Run("MacAocAddressBoms", testMacAocAddressBomsUpsert) t.Run("ServerComponentTypes", testServerComponentTypesUpsert) t.Run("ServerComponents", testServerComponentsUpsert) t.Run("ServerCredentialTypes", testServerCredentialTypesUpsert) diff --git a/internal/models/mac_aoc_address_bom.go b/internal/models/mac_aoc_address_bom.go new file mode 100644 index 00000000..aa8cc7e7 --- /dev/null +++ b/internal/models/mac_aoc_address_bom.go @@ -0,0 +1,1062 @@ +// 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/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" +) + +// MacAocAddressBom is an object representing the database table. +type MacAocAddressBom struct { + MacAocAddress string `boil:"mac_aoc_address" json:"mac_aoc_address" toml:"mac_aoc_address" yaml:"mac_aoc_address"` + SerialNum string `boil:"serial_num" json:"serial_num" toml:"serial_num" yaml:"serial_num"` + + R *macAocAddressBomR `boil:"-" json:"-" toml:"-" yaml:"-"` + L macAocAddressBomL `boil:"-" json:"-" toml:"-" yaml:"-"` +} + +var MacAocAddressBomColumns = struct { + MacAocAddress string + SerialNum string +}{ + MacAocAddress: "mac_aoc_address", + SerialNum: "serial_num", +} + +var MacAocAddressBomTableColumns = struct { + MacAocAddress string + SerialNum string +}{ + MacAocAddress: "mac_aoc_address_bom.mac_aoc_address", + SerialNum: "mac_aoc_address_bom.serial_num", +} + +// Generated where + +var MacAocAddressBomWhere = struct { + MacAocAddress whereHelperstring + SerialNum whereHelperstring +}{ + MacAocAddress: whereHelperstring{field: "\"mac_aoc_address_bom\".\"mac_aoc_address\""}, + SerialNum: whereHelperstring{field: "\"mac_aoc_address_bom\".\"serial_num\""}, +} + +// MacAocAddressBomRels is where relationship names are stored. +var MacAocAddressBomRels = struct { + SerialNumBomInfo string +}{ + SerialNumBomInfo: "SerialNumBomInfo", +} + +// macAocAddressBomR is where relationships are stored. +type macAocAddressBomR struct { + SerialNumBomInfo *BomInfo `boil:"SerialNumBomInfo" json:"SerialNumBomInfo" toml:"SerialNumBomInfo" yaml:"SerialNumBomInfo"` +} + +// NewStruct creates a new relationship struct +func (*macAocAddressBomR) NewStruct() *macAocAddressBomR { + return &macAocAddressBomR{} +} + +func (r *macAocAddressBomR) GetSerialNumBomInfo() *BomInfo { + if r == nil { + return nil + } + return r.SerialNumBomInfo +} + +// macAocAddressBomL is where Load methods for each relationship are stored. +type macAocAddressBomL struct{} + +var ( + macAocAddressBomAllColumns = []string{"mac_aoc_address", "serial_num"} + macAocAddressBomColumnsWithoutDefault = []string{"mac_aoc_address", "serial_num"} + macAocAddressBomColumnsWithDefault = []string{} + macAocAddressBomPrimaryKeyColumns = []string{"mac_aoc_address"} + macAocAddressBomGeneratedColumns = []string{} +) + +type ( + // MacAocAddressBomSlice is an alias for a slice of pointers to MacAocAddressBom. + // This should almost always be used instead of []MacAocAddressBom. + MacAocAddressBomSlice []*MacAocAddressBom + // MacAocAddressBomHook is the signature for custom MacAocAddressBom hook methods + MacAocAddressBomHook func(context.Context, boil.ContextExecutor, *MacAocAddressBom) error + + macAocAddressBomQuery struct { + *queries.Query + } +) + +// Cache for insert, update and upsert +var ( + macAocAddressBomType = reflect.TypeOf(&MacAocAddressBom{}) + macAocAddressBomMapping = queries.MakeStructMapping(macAocAddressBomType) + macAocAddressBomPrimaryKeyMapping, _ = queries.BindMapping(macAocAddressBomType, macAocAddressBomMapping, macAocAddressBomPrimaryKeyColumns) + macAocAddressBomInsertCacheMut sync.RWMutex + macAocAddressBomInsertCache = make(map[string]insertCache) + macAocAddressBomUpdateCacheMut sync.RWMutex + macAocAddressBomUpdateCache = make(map[string]updateCache) + macAocAddressBomUpsertCacheMut sync.RWMutex + macAocAddressBomUpsertCache = 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 macAocAddressBomAfterSelectHooks []MacAocAddressBomHook + +var macAocAddressBomBeforeInsertHooks []MacAocAddressBomHook +var macAocAddressBomAfterInsertHooks []MacAocAddressBomHook + +var macAocAddressBomBeforeUpdateHooks []MacAocAddressBomHook +var macAocAddressBomAfterUpdateHooks []MacAocAddressBomHook + +var macAocAddressBomBeforeDeleteHooks []MacAocAddressBomHook +var macAocAddressBomAfterDeleteHooks []MacAocAddressBomHook + +var macAocAddressBomBeforeUpsertHooks []MacAocAddressBomHook +var macAocAddressBomAfterUpsertHooks []MacAocAddressBomHook + +// doAfterSelectHooks executes all "after Select" hooks. +func (o *MacAocAddressBom) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range macAocAddressBomAfterSelectHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeInsertHooks executes all "before insert" hooks. +func (o *MacAocAddressBom) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range macAocAddressBomBeforeInsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterInsertHooks executes all "after Insert" hooks. +func (o *MacAocAddressBom) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range macAocAddressBomAfterInsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeUpdateHooks executes all "before Update" hooks. +func (o *MacAocAddressBom) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range macAocAddressBomBeforeUpdateHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterUpdateHooks executes all "after Update" hooks. +func (o *MacAocAddressBom) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range macAocAddressBomAfterUpdateHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeDeleteHooks executes all "before Delete" hooks. +func (o *MacAocAddressBom) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range macAocAddressBomBeforeDeleteHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterDeleteHooks executes all "after Delete" hooks. +func (o *MacAocAddressBom) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range macAocAddressBomAfterDeleteHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeUpsertHooks executes all "before Upsert" hooks. +func (o *MacAocAddressBom) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range macAocAddressBomBeforeUpsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterUpsertHooks executes all "after Upsert" hooks. +func (o *MacAocAddressBom) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range macAocAddressBomAfterUpsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// AddMacAocAddressBomHook registers your hook function for all future operations. +func AddMacAocAddressBomHook(hookPoint boil.HookPoint, macAocAddressBomHook MacAocAddressBomHook) { + switch hookPoint { + case boil.AfterSelectHook: + macAocAddressBomAfterSelectHooks = append(macAocAddressBomAfterSelectHooks, macAocAddressBomHook) + case boil.BeforeInsertHook: + macAocAddressBomBeforeInsertHooks = append(macAocAddressBomBeforeInsertHooks, macAocAddressBomHook) + case boil.AfterInsertHook: + macAocAddressBomAfterInsertHooks = append(macAocAddressBomAfterInsertHooks, macAocAddressBomHook) + case boil.BeforeUpdateHook: + macAocAddressBomBeforeUpdateHooks = append(macAocAddressBomBeforeUpdateHooks, macAocAddressBomHook) + case boil.AfterUpdateHook: + macAocAddressBomAfterUpdateHooks = append(macAocAddressBomAfterUpdateHooks, macAocAddressBomHook) + case boil.BeforeDeleteHook: + macAocAddressBomBeforeDeleteHooks = append(macAocAddressBomBeforeDeleteHooks, macAocAddressBomHook) + case boil.AfterDeleteHook: + macAocAddressBomAfterDeleteHooks = append(macAocAddressBomAfterDeleteHooks, macAocAddressBomHook) + case boil.BeforeUpsertHook: + macAocAddressBomBeforeUpsertHooks = append(macAocAddressBomBeforeUpsertHooks, macAocAddressBomHook) + case boil.AfterUpsertHook: + macAocAddressBomAfterUpsertHooks = append(macAocAddressBomAfterUpsertHooks, macAocAddressBomHook) + } +} + +// One returns a single macAocAddressBom record from the query. +func (q macAocAddressBomQuery) One(ctx context.Context, exec boil.ContextExecutor) (*MacAocAddressBom, error) { + o := &MacAocAddressBom{} + + 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 mac_aoc_address_bom") + } + + if err := o.doAfterSelectHooks(ctx, exec); err != nil { + return o, err + } + + return o, nil +} + +// All returns all MacAocAddressBom records from the query. +func (q macAocAddressBomQuery) All(ctx context.Context, exec boil.ContextExecutor) (MacAocAddressBomSlice, error) { + var o []*MacAocAddressBom + + err := q.Bind(ctx, exec, &o) + if err != nil { + return nil, errors.Wrap(err, "models: failed to assign all query results to MacAocAddressBom slice") + } + + if len(macAocAddressBomAfterSelectHooks) != 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 MacAocAddressBom records in the query. +func (q macAocAddressBomQuery) 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 mac_aoc_address_bom rows") + } + + return count, nil +} + +// Exists checks if the row exists in the table. +func (q macAocAddressBomQuery) 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 mac_aoc_address_bom exists") + } + + return count > 0, nil +} + +// SerialNumBomInfo pointed to by the foreign key. +func (o *MacAocAddressBom) SerialNumBomInfo(mods ...qm.QueryMod) bomInfoQuery { + queryMods := []qm.QueryMod{ + qm.Where("\"serial_num\" = ?", o.SerialNum), + } + + queryMods = append(queryMods, mods...) + + return BomInfos(queryMods...) +} + +// LoadSerialNumBomInfo allows an eager lookup of values, cached into the +// loaded structs of the objects. This is for an N-1 relationship. +func (macAocAddressBomL) LoadSerialNumBomInfo(ctx context.Context, e boil.ContextExecutor, singular bool, maybeMacAocAddressBom interface{}, mods queries.Applicator) error { + var slice []*MacAocAddressBom + var object *MacAocAddressBom + + if singular { + object = maybeMacAocAddressBom.(*MacAocAddressBom) + } else { + slice = *maybeMacAocAddressBom.(*[]*MacAocAddressBom) + } + + args := make([]interface{}, 0, 1) + if singular { + if object.R == nil { + object.R = &macAocAddressBomR{} + } + args = append(args, object.SerialNum) + + } else { + Outer: + for _, obj := range slice { + if obj.R == nil { + obj.R = &macAocAddressBomR{} + } + + for _, a := range args { + if a == obj.SerialNum { + continue Outer + } + } + + args = append(args, obj.SerialNum) + + } + } + + if len(args) == 0 { + return nil + } + + query := NewQuery( + qm.From(`bom_info`), + qm.WhereIn(`bom_info.serial_num 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(macAocAddressBomAfterSelectHooks) != 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.SerialNumBomInfo = foreign + if foreign.R == nil { + foreign.R = &bomInfoR{} + } + foreign.R.SerialNumMacAocAddressBoms = append(foreign.R.SerialNumMacAocAddressBoms, object) + return nil + } + + for _, local := range slice { + for _, foreign := range resultSlice { + if local.SerialNum == foreign.SerialNum { + local.R.SerialNumBomInfo = foreign + if foreign.R == nil { + foreign.R = &bomInfoR{} + } + foreign.R.SerialNumMacAocAddressBoms = append(foreign.R.SerialNumMacAocAddressBoms, local) + break + } + } + } + + return nil +} + +// SetSerialNumBomInfo of the macAocAddressBom to the related item. +// Sets o.R.SerialNumBomInfo to related. +// Adds o to related.R.SerialNumMacAocAddressBoms. +func (o *MacAocAddressBom) SetSerialNumBomInfo(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 \"mac_aoc_address_bom\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, []string{"serial_num"}), + strmangle.WhereClause("\"", "\"", 2, macAocAddressBomPrimaryKeyColumns), + ) + values := []interface{}{related.SerialNum, o.MacAocAddress} + + 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.SerialNum = related.SerialNum + if o.R == nil { + o.R = &macAocAddressBomR{ + SerialNumBomInfo: related, + } + } else { + o.R.SerialNumBomInfo = related + } + + if related.R == nil { + related.R = &bomInfoR{ + SerialNumMacAocAddressBoms: MacAocAddressBomSlice{o}, + } + } else { + related.R.SerialNumMacAocAddressBoms = append(related.R.SerialNumMacAocAddressBoms, o) + } + + return nil +} + +// MacAocAddressBoms retrieves all the records using an executor. +func MacAocAddressBoms(mods ...qm.QueryMod) macAocAddressBomQuery { + mods = append(mods, qm.From("\"mac_aoc_address_bom\"")) + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"mac_aoc_address_bom\".*"}) + } + + return macAocAddressBomQuery{q} +} + +// FindMacAocAddressBom retrieves a single record by ID with an executor. +// If selectCols is empty Find will return all columns. +func FindMacAocAddressBom(ctx context.Context, exec boil.ContextExecutor, macAocAddress string, selectCols ...string) (*MacAocAddressBom, error) { + macAocAddressBomObj := &MacAocAddressBom{} + + sel := "*" + if len(selectCols) > 0 { + sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",") + } + query := fmt.Sprintf( + "select %s from \"mac_aoc_address_bom\" where \"mac_aoc_address\"=$1", sel, + ) + + q := queries.Raw(query, macAocAddress) + + err := q.Bind(ctx, exec, macAocAddressBomObj) + if err != nil { + if errors.Is(err, sql.ErrNoRows) { + return nil, sql.ErrNoRows + } + return nil, errors.Wrap(err, "models: unable to select from mac_aoc_address_bom") + } + + if err = macAocAddressBomObj.doAfterSelectHooks(ctx, exec); err != nil { + return macAocAddressBomObj, err + } + + return macAocAddressBomObj, nil +} + +// Insert a single record using an executor. +// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts. +func (o *MacAocAddressBom) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error { + if o == nil { + return errors.New("models: no mac_aoc_address_bom provided for insertion") + } + + var err error + + if err := o.doBeforeInsertHooks(ctx, exec); err != nil { + return err + } + + nzDefaults := queries.NonZeroDefaultSet(macAocAddressBomColumnsWithDefault, o) + + key := makeCacheKey(columns, nzDefaults) + macAocAddressBomInsertCacheMut.RLock() + cache, cached := macAocAddressBomInsertCache[key] + macAocAddressBomInsertCacheMut.RUnlock() + + if !cached { + wl, returnColumns := columns.InsertColumnSet( + macAocAddressBomAllColumns, + macAocAddressBomColumnsWithDefault, + macAocAddressBomColumnsWithoutDefault, + nzDefaults, + ) + + cache.valueMapping, err = queries.BindMapping(macAocAddressBomType, macAocAddressBomMapping, wl) + if err != nil { + return err + } + cache.retMapping, err = queries.BindMapping(macAocAddressBomType, macAocAddressBomMapping, returnColumns) + if err != nil { + return err + } + if len(wl) != 0 { + cache.query = fmt.Sprintf("INSERT INTO \"mac_aoc_address_bom\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1)) + } else { + cache.query = "INSERT INTO \"mac_aoc_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 mac_aoc_address_bom") + } + + if !cached { + macAocAddressBomInsertCacheMut.Lock() + macAocAddressBomInsertCache[key] = cache + macAocAddressBomInsertCacheMut.Unlock() + } + + return o.doAfterInsertHooks(ctx, exec) +} + +// Update uses an executor to update the MacAocAddressBom. +// 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 *MacAocAddressBom) 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) + macAocAddressBomUpdateCacheMut.RLock() + cache, cached := macAocAddressBomUpdateCache[key] + macAocAddressBomUpdateCacheMut.RUnlock() + + if !cached { + wl := columns.UpdateColumnSet( + macAocAddressBomAllColumns, + macAocAddressBomPrimaryKeyColumns, + ) + + if !columns.IsWhitelist() { + wl = strmangle.SetComplement(wl, []string{"created_at"}) + } + if len(wl) == 0 { + return 0, errors.New("models: unable to update mac_aoc_address_bom, could not build whitelist") + } + + cache.query = fmt.Sprintf("UPDATE \"mac_aoc_address_bom\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, wl), + strmangle.WhereClause("\"", "\"", len(wl)+1, macAocAddressBomPrimaryKeyColumns), + ) + cache.valueMapping, err = queries.BindMapping(macAocAddressBomType, macAocAddressBomMapping, append(wl, macAocAddressBomPrimaryKeyColumns...)) + 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 mac_aoc_address_bom row") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: failed to get rows affected by update for mac_aoc_address_bom") + } + + if !cached { + macAocAddressBomUpdateCacheMut.Lock() + macAocAddressBomUpdateCache[key] = cache + macAocAddressBomUpdateCacheMut.Unlock() + } + + return rowsAff, o.doAfterUpdateHooks(ctx, exec) +} + +// UpdateAll updates all rows with the specified column values. +func (q macAocAddressBomQuery) 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 mac_aoc_address_bom") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: unable to retrieve rows affected for mac_aoc_address_bom") + } + + return rowsAff, nil +} + +// UpdateAll updates all rows with the specified column values, using an executor. +func (o MacAocAddressBomSlice) 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)), macAocAddressBomPrimaryKeyMapping) + args = append(args, pkeyArgs...) + } + + sql := fmt.Sprintf("UPDATE \"mac_aoc_address_bom\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, colNames), + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, macAocAddressBomPrimaryKeyColumns, 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 macAocAddressBom slice") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all macAocAddressBom") + } + return rowsAff, nil +} + +// Delete deletes a single MacAocAddressBom record with an executor. +// Delete will match against the primary key column to find the record to delete. +func (o *MacAocAddressBom) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) { + if o == nil { + return 0, errors.New("models: no MacAocAddressBom provided for delete") + } + + if err := o.doBeforeDeleteHooks(ctx, exec); err != nil { + return 0, err + } + + args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), macAocAddressBomPrimaryKeyMapping) + sql := "DELETE FROM \"mac_aoc_address_bom\" WHERE \"mac_aoc_address\"=$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 mac_aoc_address_bom") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: failed to get rows affected by delete for mac_aoc_address_bom") + } + + if err := o.doAfterDeleteHooks(ctx, exec); err != nil { + return 0, err + } + + return rowsAff, nil +} + +// DeleteAll deletes all matching rows. +func (q macAocAddressBomQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { + if q.Query == nil { + return 0, errors.New("models: no macAocAddressBomQuery 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 mac_aoc_address_bom") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for mac_aoc_address_bom") + } + + return rowsAff, nil +} + +// DeleteAll deletes all rows in the slice, using an executor. +func (o MacAocAddressBomSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { + if len(o) == 0 { + return 0, nil + } + + if len(macAocAddressBomBeforeDeleteHooks) != 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)), macAocAddressBomPrimaryKeyMapping) + args = append(args, pkeyArgs...) + } + + sql := "DELETE FROM \"mac_aoc_address_bom\" WHERE " + + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, macAocAddressBomPrimaryKeyColumns, 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 macAocAddressBom slice") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for mac_aoc_address_bom") + } + + if len(macAocAddressBomAfterDeleteHooks) != 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 *MacAocAddressBom) Reload(ctx context.Context, exec boil.ContextExecutor) error { + ret, err := FindMacAocAddressBom(ctx, exec, o.MacAocAddress) + 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 *MacAocAddressBomSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error { + if o == nil || len(*o) == 0 { + return nil + } + + slice := MacAocAddressBomSlice{} + var args []interface{} + for _, obj := range *o { + pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), macAocAddressBomPrimaryKeyMapping) + args = append(args, pkeyArgs...) + } + + sql := "SELECT \"mac_aoc_address_bom\".* FROM \"mac_aoc_address_bom\" WHERE " + + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, macAocAddressBomPrimaryKeyColumns, 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 MacAocAddressBomSlice") + } + + *o = slice + + return nil +} + +// MacAocAddressBomExists checks if the MacAocAddressBom row exists. +func MacAocAddressBomExists(ctx context.Context, exec boil.ContextExecutor, macAocAddress string) (bool, error) { + var exists bool + sql := "select exists(select 1 from \"mac_aoc_address_bom\" where \"mac_aoc_address\"=$1 limit 1)" + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, macAocAddress) + } + row := exec.QueryRowContext(ctx, sql, macAocAddress) + + err := row.Scan(&exists) + if err != nil { + return false, errors.Wrap(err, "models: unable to check if mac_aoc_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 *MacAocAddressBom) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { + if o == nil { + return errors.New("models: no mac_aoc_address_bom provided for upsert") + } + + if err := o.doBeforeUpsertHooks(ctx, exec); err != nil { + return err + } + + nzDefaults := queries.NonZeroDefaultSet(macAocAddressBomColumnsWithDefault, 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) + + macAocAddressBomUpsertCacheMut.RLock() + cache, cached := macAocAddressBomUpsertCache[key] + macAocAddressBomUpsertCacheMut.RUnlock() + + var err error + + if !cached { + insert, ret := insertColumns.InsertColumnSet( + macAocAddressBomAllColumns, + macAocAddressBomColumnsWithDefault, + macAocAddressBomColumnsWithoutDefault, + nzDefaults, + ) + update := updateColumns.UpdateColumnSet( + macAocAddressBomAllColumns, + macAocAddressBomPrimaryKeyColumns, + ) + + if updateOnConflict && len(update) == 0 { + return errors.New("models: unable to upsert mac_aoc_address_bom, could not build update column list") + } + + conflict := conflictColumns + if len(conflict) == 0 { + conflict = make([]string, len(macAocAddressBomPrimaryKeyColumns)) + copy(conflict, macAocAddressBomPrimaryKeyColumns) + } + cache.query = buildUpsertQueryCockroachDB(dialect, "\"mac_aoc_address_bom\"", updateOnConflict, ret, update, conflict, insert) + + cache.valueMapping, err = queries.BindMapping(macAocAddressBomType, macAocAddressBomMapping, insert) + if err != nil { + return err + } + if len(ret) != 0 { + cache.retMapping, err = queries.BindMapping(macAocAddressBomType, macAocAddressBomMapping, 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 mac_aoc_address_bom") + } + + if !cached { + macAocAddressBomUpsertCacheMut.Lock() + macAocAddressBomUpsertCache[key] = cache + macAocAddressBomUpsertCacheMut.Unlock() + } + + return o.doAfterUpsertHooks(ctx, exec) +} diff --git a/internal/models/mac_aoc_address_bom_test.go b/internal/models/mac_aoc_address_bom_test.go new file mode 100644 index 00000000..dd89392b --- /dev/null +++ b/internal/models/mac_aoc_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 testMacAocAddressBomsUpsert(t *testing.T) { + t.Parallel() + + if len(macAocAddressBomAllColumns) == len(macAocAddressBomPrimaryKeyColumns) { + t.Skip("Skipping table with only primary key columns") + } + + seed := randomize.NewSeed() + var err error + // Attempt the INSERT side of an UPSERT + o := MacAocAddressBom{} + if err = randomize.Struct(seed, &o, macAocAddressBomDBTypes, true); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom 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 MacAocAddressBom: %s", err) + } + + count, err := MacAocAddressBoms().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, macAocAddressBomDBTypes, false, macAocAddressBomPrimaryKeyColumns...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom struct: %s", err) + } + + if err = o.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer()); err != nil { + t.Errorf("Unable to upsert MacAocAddressBom: %s", err) + } + + count, err = MacAocAddressBoms().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 testMacAocAddressBoms(t *testing.T) { + t.Parallel() + + query := MacAocAddressBoms() + + if query.Query == nil { + t.Error("expected a query, got nothing") + } +} + +func testMacAocAddressBomsDelete(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &MacAocAddressBom{} + if err = randomize.Struct(seed, o, macAocAddressBomDBTypes, true, macAocAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom 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 := MacAocAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 0 { + t.Error("want zero records, got:", count) + } +} + +func testMacAocAddressBomsQueryDeleteAll(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &MacAocAddressBom{} + if err = randomize.Struct(seed, o, macAocAddressBomDBTypes, true, macAocAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom 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 := MacAocAddressBoms().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 := MacAocAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 0 { + t.Error("want zero records, got:", count) + } +} + +func testMacAocAddressBomsSliceDeleteAll(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &MacAocAddressBom{} + if err = randomize.Struct(seed, o, macAocAddressBomDBTypes, true, macAocAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom 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 := MacAocAddressBomSlice{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 := MacAocAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 0 { + t.Error("want zero records, got:", count) + } +} + +func testMacAocAddressBomsExists(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &MacAocAddressBom{} + if err = randomize.Struct(seed, o, macAocAddressBomDBTypes, true, macAocAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom 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 := MacAocAddressBomExists(ctx, tx, o.MacAocAddress) + if err != nil { + t.Errorf("Unable to check if MacAocAddressBom exists: %s", err) + } + if !e { + t.Errorf("Expected MacAocAddressBomExists to return true, but got false.") + } +} + +func testMacAocAddressBomsFind(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &MacAocAddressBom{} + if err = randomize.Struct(seed, o, macAocAddressBomDBTypes, true, macAocAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom 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) + } + + macAocAddressBomFound, err := FindMacAocAddressBom(ctx, tx, o.MacAocAddress) + if err != nil { + t.Error(err) + } + + if macAocAddressBomFound == nil { + t.Error("want a record, got nil") + } +} + +func testMacAocAddressBomsBind(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &MacAocAddressBom{} + if err = randomize.Struct(seed, o, macAocAddressBomDBTypes, true, macAocAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom 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 = MacAocAddressBoms().Bind(ctx, tx, o); err != nil { + t.Error(err) + } +} + +func testMacAocAddressBomsOne(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &MacAocAddressBom{} + if err = randomize.Struct(seed, o, macAocAddressBomDBTypes, true, macAocAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom 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 := MacAocAddressBoms().One(ctx, tx); err != nil { + t.Error(err) + } else if x == nil { + t.Error("expected to get a non nil record") + } +} + +func testMacAocAddressBomsAll(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + macAocAddressBomOne := &MacAocAddressBom{} + macAocAddressBomTwo := &MacAocAddressBom{} + if err = randomize.Struct(seed, macAocAddressBomOne, macAocAddressBomDBTypes, false, macAocAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom struct: %s", err) + } + if err = randomize.Struct(seed, macAocAddressBomTwo, macAocAddressBomDBTypes, false, macAocAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = macAocAddressBomOne.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + if err = macAocAddressBomTwo.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + slice, err := MacAocAddressBoms().All(ctx, tx) + if err != nil { + t.Error(err) + } + + if len(slice) != 2 { + t.Error("want 2 records, got:", len(slice)) + } +} + +func testMacAocAddressBomsCount(t *testing.T) { + t.Parallel() + + var err error + seed := randomize.NewSeed() + macAocAddressBomOne := &MacAocAddressBom{} + macAocAddressBomTwo := &MacAocAddressBom{} + if err = randomize.Struct(seed, macAocAddressBomOne, macAocAddressBomDBTypes, false, macAocAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom struct: %s", err) + } + if err = randomize.Struct(seed, macAocAddressBomTwo, macAocAddressBomDBTypes, false, macAocAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = macAocAddressBomOne.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + if err = macAocAddressBomTwo.Insert(ctx, tx, boil.Infer()); err != nil { + t.Error(err) + } + + count, err := MacAocAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 2 { + t.Error("want 2 records, got:", count) + } +} + +func macAocAddressBomBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *MacAocAddressBom) error { + *o = MacAocAddressBom{} + return nil +} + +func macAocAddressBomAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *MacAocAddressBom) error { + *o = MacAocAddressBom{} + return nil +} + +func macAocAddressBomAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *MacAocAddressBom) error { + *o = MacAocAddressBom{} + return nil +} + +func macAocAddressBomBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *MacAocAddressBom) error { + *o = MacAocAddressBom{} + return nil +} + +func macAocAddressBomAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *MacAocAddressBom) error { + *o = MacAocAddressBom{} + return nil +} + +func macAocAddressBomBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *MacAocAddressBom) error { + *o = MacAocAddressBom{} + return nil +} + +func macAocAddressBomAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *MacAocAddressBom) error { + *o = MacAocAddressBom{} + return nil +} + +func macAocAddressBomBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *MacAocAddressBom) error { + *o = MacAocAddressBom{} + return nil +} + +func macAocAddressBomAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *MacAocAddressBom) error { + *o = MacAocAddressBom{} + return nil +} + +func testMacAocAddressBomsHooks(t *testing.T) { + t.Parallel() + + var err error + + ctx := context.Background() + empty := &MacAocAddressBom{} + o := &MacAocAddressBom{} + + seed := randomize.NewSeed() + if err = randomize.Struct(seed, o, macAocAddressBomDBTypes, false); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom object: %s", err) + } + + AddMacAocAddressBomHook(boil.BeforeInsertHook, macAocAddressBomBeforeInsertHook) + 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) + } + macAocAddressBomBeforeInsertHooks = []MacAocAddressBomHook{} + + AddMacAocAddressBomHook(boil.AfterInsertHook, macAocAddressBomAfterInsertHook) + 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) + } + macAocAddressBomAfterInsertHooks = []MacAocAddressBomHook{} + + AddMacAocAddressBomHook(boil.AfterSelectHook, macAocAddressBomAfterSelectHook) + 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) + } + macAocAddressBomAfterSelectHooks = []MacAocAddressBomHook{} + + AddMacAocAddressBomHook(boil.BeforeUpdateHook, macAocAddressBomBeforeUpdateHook) + 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) + } + macAocAddressBomBeforeUpdateHooks = []MacAocAddressBomHook{} + + AddMacAocAddressBomHook(boil.AfterUpdateHook, macAocAddressBomAfterUpdateHook) + 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) + } + macAocAddressBomAfterUpdateHooks = []MacAocAddressBomHook{} + + AddMacAocAddressBomHook(boil.BeforeDeleteHook, macAocAddressBomBeforeDeleteHook) + 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) + } + macAocAddressBomBeforeDeleteHooks = []MacAocAddressBomHook{} + + AddMacAocAddressBomHook(boil.AfterDeleteHook, macAocAddressBomAfterDeleteHook) + 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) + } + macAocAddressBomAfterDeleteHooks = []MacAocAddressBomHook{} + + AddMacAocAddressBomHook(boil.BeforeUpsertHook, macAocAddressBomBeforeUpsertHook) + 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) + } + macAocAddressBomBeforeUpsertHooks = []MacAocAddressBomHook{} + + AddMacAocAddressBomHook(boil.AfterUpsertHook, macAocAddressBomAfterUpsertHook) + 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) + } + macAocAddressBomAfterUpsertHooks = []MacAocAddressBomHook{} +} + +func testMacAocAddressBomsInsert(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &MacAocAddressBom{} + if err = randomize.Struct(seed, o, macAocAddressBomDBTypes, true, macAocAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom 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 := MacAocAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 1 { + t.Error("want one record, got:", count) + } +} + +func testMacAocAddressBomsInsertWhitelist(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &MacAocAddressBom{} + if err = randomize.Struct(seed, o, macAocAddressBomDBTypes, true); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom struct: %s", err) + } + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + if err = o.Insert(ctx, tx, boil.Whitelist(macAocAddressBomColumnsWithoutDefault...)); err != nil { + t.Error(err) + } + + count, err := MacAocAddressBoms().Count(ctx, tx) + if err != nil { + t.Error(err) + } + + if count != 1 { + t.Error("want one record, got:", count) + } +} + +func testMacAocAddressBomToOneBomInfoUsingSerialNumBomInfo(t *testing.T) { + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + + var local MacAocAddressBom + var foreign BomInfo + + seed := randomize.NewSeed() + if err := randomize.Struct(seed, &local, macAocAddressBomDBTypes, false, macAocAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom 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.SerialNum = foreign.SerialNum + if err := local.Insert(ctx, tx, boil.Infer()); err != nil { + t.Fatal(err) + } + + check, err := local.SerialNumBomInfo().One(ctx, tx) + if err != nil { + t.Fatal(err) + } + + if check.SerialNum != foreign.SerialNum { + t.Errorf("want: %v, got %v", foreign.SerialNum, check.SerialNum) + } + + slice := MacAocAddressBomSlice{&local} + if err = local.L.LoadSerialNumBomInfo(ctx, tx, false, (*[]*MacAocAddressBom)(&slice), nil); err != nil { + t.Fatal(err) + } + if local.R.SerialNumBomInfo == nil { + t.Error("struct should have been eager loaded") + } + + local.R.SerialNumBomInfo = nil + if err = local.L.LoadSerialNumBomInfo(ctx, tx, true, &local, nil); err != nil { + t.Fatal(err) + } + if local.R.SerialNumBomInfo == nil { + t.Error("struct should have been eager loaded") + } +} + +func testMacAocAddressBomToOneSetOpBomInfoUsingSerialNumBomInfo(t *testing.T) { + var err error + + ctx := context.Background() + tx := MustTx(boil.BeginTx(ctx, nil)) + defer func() { _ = tx.Rollback() }() + + var a MacAocAddressBom + var b, c BomInfo + + seed := randomize.NewSeed() + if err = randomize.Struct(seed, &a, macAocAddressBomDBTypes, false, strmangle.SetComplement(macAocAddressBomPrimaryKeyColumns, macAocAddressBomColumnsWithoutDefault)...); 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.SetSerialNumBomInfo(ctx, tx, i != 0, x) + if err != nil { + t.Fatal(err) + } + + if a.R.SerialNumBomInfo != x { + t.Error("relationship struct not set to correct value") + } + + if x.R.SerialNumMacAocAddressBoms[0] != &a { + t.Error("failed to append to foreign relationship struct") + } + if a.SerialNum != x.SerialNum { + t.Error("foreign key was wrong value", a.SerialNum) + } + + zero := reflect.Zero(reflect.TypeOf(a.SerialNum)) + reflect.Indirect(reflect.ValueOf(&a.SerialNum)).Set(zero) + + if err = a.Reload(ctx, tx); err != nil { + t.Fatal("failed to reload", err) + } + + if a.SerialNum != x.SerialNum { + t.Error("foreign key was wrong value", a.SerialNum, x.SerialNum) + } + } +} + +func testMacAocAddressBomsReload(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &MacAocAddressBom{} + if err = randomize.Struct(seed, o, macAocAddressBomDBTypes, true, macAocAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom 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 testMacAocAddressBomsReloadAll(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &MacAocAddressBom{} + if err = randomize.Struct(seed, o, macAocAddressBomDBTypes, true, macAocAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom 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 := MacAocAddressBomSlice{o} + + if err = slice.ReloadAll(ctx, tx); err != nil { + t.Error(err) + } +} + +func testMacAocAddressBomsSelect(t *testing.T) { + t.Parallel() + + seed := randomize.NewSeed() + var err error + o := &MacAocAddressBom{} + if err = randomize.Struct(seed, o, macAocAddressBomDBTypes, true, macAocAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom 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 := MacAocAddressBoms().All(ctx, tx) + if err != nil { + t.Error(err) + } + + if len(slice) != 1 { + t.Error("want one record, got:", len(slice)) + } +} + +var ( + macAocAddressBomDBTypes = map[string]string{`MacAocAddress`: `string`, `SerialNum`: `string`} + _ = bytes.MinRead +) + +func testMacAocAddressBomsUpdate(t *testing.T) { + t.Parallel() + + if 0 == len(macAocAddressBomPrimaryKeyColumns) { + t.Skip("Skipping table with no primary key columns") + } + if len(macAocAddressBomAllColumns) == len(macAocAddressBomPrimaryKeyColumns) { + t.Skip("Skipping table with only primary key columns") + } + + seed := randomize.NewSeed() + var err error + o := &MacAocAddressBom{} + if err = randomize.Struct(seed, o, macAocAddressBomDBTypes, true, macAocAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom 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 := MacAocAddressBoms().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, macAocAddressBomDBTypes, true, macAocAddressBomPrimaryKeyColumns...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom 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 testMacAocAddressBomsSliceUpdateAll(t *testing.T) { + t.Parallel() + + if len(macAocAddressBomAllColumns) == len(macAocAddressBomPrimaryKeyColumns) { + t.Skip("Skipping table with only primary key columns") + } + + seed := randomize.NewSeed() + var err error + o := &MacAocAddressBom{} + if err = randomize.Struct(seed, o, macAocAddressBomDBTypes, true, macAocAddressBomColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom 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 := MacAocAddressBoms().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, macAocAddressBomDBTypes, true, macAocAddressBomPrimaryKeyColumns...); err != nil { + t.Errorf("Unable to randomize MacAocAddressBom struct: %s", err) + } + + // Remove Primary keys and unique columns from what we plan to update + var fields []string + if strmangle.StringSliceMatch(macAocAddressBomAllColumns, macAocAddressBomPrimaryKeyColumns) { + fields = macAocAddressBomAllColumns + } else { + fields = strmangle.SetComplement( + macAocAddressBomAllColumns, + macAocAddressBomPrimaryKeyColumns, + ) + } + + 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 := MacAocAddressBomSlice{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) + } +}