diff --git a/.gitignore b/.gitignore index d5a59c2..140b8b5 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,6 @@ cosign.key .vscode/ .devcontainer/ cockroach-data/ -coverage.txt \ No newline at end of file +coverage.txt +*.swp +*.swo \ No newline at end of file diff --git a/Makefile b/Makefile index 8fa08a0..7ec84b6 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ integration-test: test-database ## run lint and unit tests unit-test: | lint @echo Running unit tests... - @go test -cover -short -tags testtools ./... + @SERVERSERVICE_CRDB_URI="${TEST_DB}" go test -cover -short -tags testtools ./... ## check test coverage coverage: | test-database diff --git a/cmd/serve.go b/cmd/serve.go index 072a485..a235b0c 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -7,6 +7,7 @@ import ( "github.com/jmoiron/sqlx" "github.com/spf13/cobra" "github.com/spf13/viper" + "github.com/volatiletech/sqlboiler/boil" "go.hollow.sh/toolbox/events" "go.hollow.sh/toolbox/ginjwt" "go.infratographer.com/x/crdbx" @@ -186,6 +187,8 @@ func initDB() *sqlx.DB { logger.Fatalw("failed to initialize database connection", "error", err) } + boil.SetDB(sqldb) + db := sqlx.NewDb(sqldb, dbDriverName) return db diff --git a/go.mod b/go.mod index d52a732..8b51a4c 100644 --- a/go.mod +++ b/go.mod @@ -98,7 +98,7 @@ require ( github.com/prometheus/procfs v0.11.1 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/spf13/afero v1.9.5 // indirect - github.com/spf13/cast v1.5.1 // indirect + github.com/spf13/cast v1.6.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect @@ -120,7 +120,7 @@ require ( golang.org/x/net v0.14.0 // indirect golang.org/x/sys v0.11.0 // indirect golang.org/x/text v0.12.0 // indirect - golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect + golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect google.golang.org/api v0.137.0 // indirect google.golang.org/genproto v0.0.0-20230815205213-6bfd019c3878 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20230815205213-6bfd019c3878 // indirect diff --git a/go.sum b/go.sum index c91a542..57dee16 100644 --- a/go.sum +++ b/go.sum @@ -159,7 +159,7 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= -github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/friendsofgo/errors v0.9.2 h1:X6NYxef4efCBdwI7BgS820zFaN7Cphrmb+Pljdzjtgk= github.com/friendsofgo/errors v0.9.2/go.mod h1:yCvFW5AkDIL9qn7suHVLiI/gH228n7PC4Pn44IGoTOI= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= @@ -609,8 +609,8 @@ github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM= github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= -github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA= -github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM= github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= @@ -1081,8 +1081,8 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= -golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk= -golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= +golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= +golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= diff --git a/internal/dbtools/testtools.go b/internal/dbtools/testtools.go index 10a25f7..1e74a22 100644 --- a/internal/dbtools/testtools.go +++ b/internal/dbtools/testtools.go @@ -47,6 +47,8 @@ func testDatastore(t *testing.T) error { return err } + boil.SetDB(db) + testDB = db cleanDB(t) @@ -106,7 +108,7 @@ func cleanDB(t *testing.T) { deleteFixture(ctx, t, models.ServerComponents()) deleteFixture(ctx, t, models.ServerComponentTypes()) deleteFixture(ctx, t, models.ServerCredentials()) - if _, err := models.Servers(qm.WithDeleted()).DeleteAll(ctx, testDB, true); err != nil { + if _, err := models.Servers(qm.WithDeleted()).DeleteAll(ctx, boil.GetContextDB(), true); err != nil { t.Error(errors.Wrap(err, "table: model.Servers")) } deleteFixture(ctx, t, models.AttributesFirmwareSets()) diff --git a/internal/models/aoc_mac_address.go b/internal/models/aoc_mac_address.go index 2a8d14b..6bf0d75 100644 --- a/internal/models/aoc_mac_address.go +++ b/internal/models/aoc_mac_address.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -50,12 +50,14 @@ var AocMacAddressTableColumns = struct { type whereHelperstring struct{ field string } -func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } -func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } -func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } -func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } -func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } -func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } +func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } +func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } +func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } +func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } +func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) LIKE(x string) qm.QueryMod { return qm.Where(w.field+" LIKE ?", x) } +func (w whereHelperstring) NLIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT LIKE ?", x) } func (w whereHelperstring) IN(slice []string) qm.QueryMod { values := make([]interface{}, 0, len(slice)) for _, value := range slice { @@ -410,9 +412,25 @@ func (aocMacAddressL) LoadSerialNumBomInfo(ctx context.Context, e boil.ContextEx var object *AocMacAddress if singular { - object = maybeAocMacAddress.(*AocMacAddress) + var ok bool + object, ok = maybeAocMacAddress.(*AocMacAddress) + if !ok { + object = new(AocMacAddress) + ok = queries.SetFromEmbeddedStruct(&object, &maybeAocMacAddress) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAocMacAddress)) + } + } } else { - slice = *maybeAocMacAddress.(*[]*AocMacAddress) + s, ok := maybeAocMacAddress.(*[]*AocMacAddress) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeAocMacAddress) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAocMacAddress)) + } + } } args := make([]interface{}, 0, 1) @@ -469,7 +487,7 @@ func (aocMacAddressL) LoadSerialNumBomInfo(ctx context.Context, e boil.ContextEx return errors.Wrap(err, "error occurred during iteration of eager loaded relations for bom_info") } - if len(aocMacAddressAfterSelectHooks) != 0 { + if len(bomInfoAfterSelectHooks) != 0 { for _, obj := range resultSlice { if err := obj.doAfterSelectHooks(ctx, e); err != nil { return err @@ -969,6 +987,11 @@ func AocMacAddressExists(ctx context.Context, exec boil.ContextExecutor, aocMacA return exists, nil } +// Exists checks if the AocMacAddress row exists. +func (o *AocMacAddress) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return AocMacAddressExists(ctx, exec, o.AocMacAddress) +} + // 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 *AocMacAddress) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { diff --git a/internal/models/aoc_mac_address_test.go b/internal/models/aoc_mac_address_test.go index b7f287e..cdaedf2 100644 --- a/internal/models/aoc_mac_address_test.go +++ b/internal/models/aoc_mac_address_test.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -576,6 +576,12 @@ func testAocMacAddressToOneBomInfoUsingSerialNumBomInfo(t *testing.T) { t.Errorf("want: %v, got %v", foreign.SerialNum, check.SerialNum) } + ranAfterSelectHook := false + AddBomInfoHook(boil.AfterSelectHook, func(ctx context.Context, e boil.ContextExecutor, o *BomInfo) error { + ranAfterSelectHook = true + return nil + }) + slice := AocMacAddressSlice{&local} if err = local.L.LoadSerialNumBomInfo(ctx, tx, false, (*[]*AocMacAddress)(&slice), nil); err != nil { t.Fatal(err) @@ -591,6 +597,10 @@ func testAocMacAddressToOneBomInfoUsingSerialNumBomInfo(t *testing.T) { if local.R.SerialNumBomInfo == nil { t.Error("struct should have been eager loaded") } + + if !ranAfterSelectHook { + t.Error("failed to run AfterSelect hook for relationship") + } } func testAocMacAddressToOneSetOpBomInfoUsingSerialNumBomInfo(t *testing.T) { diff --git a/internal/models/attributes.go b/internal/models/attributes.go index b838690..f8b603c 100644 --- a/internal/models/attributes.go +++ b/internal/models/attributes.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -95,6 +95,26 @@ func (w whereHelpernull_String) GT(x null.String) qm.QueryMod { func (w whereHelpernull_String) GTE(x null.String) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_String) LIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" LIKE ?", x) +} +func (w whereHelpernull_String) NLIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" NOT LIKE ?", x) +} +func (w whereHelpernull_String) IN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) +} +func (w whereHelpernull_String) NIN(slice []string) qm.QueryMod { + values := make([]interface{}, 0, len(slice)) + for _, value := range slice { + values = append(values, value) + } + return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) +} func (w whereHelpernull_String) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } func (w whereHelpernull_String) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } @@ -514,9 +534,25 @@ func (attributeL) LoadServer(ctx context.Context, e boil.ContextExecutor, singul var object *Attribute if singular { - object = maybeAttribute.(*Attribute) + var ok bool + object, ok = maybeAttribute.(*Attribute) + if !ok { + object = new(Attribute) + ok = queries.SetFromEmbeddedStruct(&object, &maybeAttribute) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAttribute)) + } + } } else { - slice = *maybeAttribute.(*[]*Attribute) + s, ok := maybeAttribute.(*[]*Attribute) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeAttribute) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAttribute)) + } + } } args := make([]interface{}, 0, 1) @@ -578,7 +614,7 @@ func (attributeL) LoadServer(ctx context.Context, e boil.ContextExecutor, singul return errors.Wrap(err, "error occurred during iteration of eager loaded relations for servers") } - if len(attributeAfterSelectHooks) != 0 { + if len(serverAfterSelectHooks) != 0 { for _, obj := range resultSlice { if err := obj.doAfterSelectHooks(ctx, e); err != nil { return err @@ -623,9 +659,25 @@ func (attributeL) LoadServerComponent(ctx context.Context, e boil.ContextExecuto var object *Attribute if singular { - object = maybeAttribute.(*Attribute) + var ok bool + object, ok = maybeAttribute.(*Attribute) + if !ok { + object = new(Attribute) + ok = queries.SetFromEmbeddedStruct(&object, &maybeAttribute) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAttribute)) + } + } } else { - slice = *maybeAttribute.(*[]*Attribute) + s, ok := maybeAttribute.(*[]*Attribute) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeAttribute) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAttribute)) + } + } } args := make([]interface{}, 0, 1) @@ -686,7 +738,7 @@ func (attributeL) LoadServerComponent(ctx context.Context, e boil.ContextExecuto return errors.Wrap(err, "error occurred during iteration of eager loaded relations for server_components") } - if len(attributeAfterSelectHooks) != 0 { + if len(serverComponentAfterSelectHooks) != 0 { for _, obj := range resultSlice { if err := obj.doAfterSelectHooks(ctx, e); err != nil { return err @@ -1315,6 +1367,11 @@ func AttributeExists(ctx context.Context, exec boil.ContextExecutor, iD string) return exists, nil } +// Exists checks if the Attribute row exists. +func (o *Attribute) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return AttributeExists(ctx, exec, o.ID) +} + // 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 *Attribute) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { diff --git a/internal/models/attributes_firmware_set.go b/internal/models/attributes_firmware_set.go index eac927b..d805abf 100644 --- a/internal/models/attributes_firmware_set.go +++ b/internal/models/attributes_firmware_set.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -417,9 +417,25 @@ func (attributesFirmwareSetL) LoadFirmwareSet(ctx context.Context, e boil.Contex var object *AttributesFirmwareSet if singular { - object = maybeAttributesFirmwareSet.(*AttributesFirmwareSet) + var ok bool + object, ok = maybeAttributesFirmwareSet.(*AttributesFirmwareSet) + if !ok { + object = new(AttributesFirmwareSet) + ok = queries.SetFromEmbeddedStruct(&object, &maybeAttributesFirmwareSet) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAttributesFirmwareSet)) + } + } } else { - slice = *maybeAttributesFirmwareSet.(*[]*AttributesFirmwareSet) + s, ok := maybeAttributesFirmwareSet.(*[]*AttributesFirmwareSet) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeAttributesFirmwareSet) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAttributesFirmwareSet)) + } + } } args := make([]interface{}, 0, 1) @@ -480,7 +496,7 @@ func (attributesFirmwareSetL) LoadFirmwareSet(ctx context.Context, e boil.Contex return errors.Wrap(err, "error occurred during iteration of eager loaded relations for component_firmware_set") } - if len(attributesFirmwareSetAfterSelectHooks) != 0 { + if len(componentFirmwareSetAfterSelectHooks) != 0 { for _, obj := range resultSlice { if err := obj.doAfterSelectHooks(ctx, e); err != nil { return err @@ -1029,6 +1045,11 @@ func AttributesFirmwareSetExists(ctx context.Context, exec boil.ContextExecutor, return exists, nil } +// Exists checks if the AttributesFirmwareSet row exists. +func (o *AttributesFirmwareSet) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return AttributesFirmwareSetExists(ctx, exec, o.ID) +} + // 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 *AttributesFirmwareSet) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { diff --git a/internal/models/attributes_firmware_set_test.go b/internal/models/attributes_firmware_set_test.go index c27a8f3..d7021af 100644 --- a/internal/models/attributes_firmware_set_test.go +++ b/internal/models/attributes_firmware_set_test.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -576,6 +576,12 @@ func testAttributesFirmwareSetToOneComponentFirmwareSetUsingFirmwareSet(t *testi t.Errorf("want: %v, got %v", foreign.ID, check.ID) } + ranAfterSelectHook := false + AddComponentFirmwareSetHook(boil.AfterSelectHook, func(ctx context.Context, e boil.ContextExecutor, o *ComponentFirmwareSet) error { + ranAfterSelectHook = true + return nil + }) + slice := AttributesFirmwareSetSlice{&local} if err = local.L.LoadFirmwareSet(ctx, tx, false, (*[]*AttributesFirmwareSet)(&slice), nil); err != nil { t.Fatal(err) @@ -591,6 +597,10 @@ func testAttributesFirmwareSetToOneComponentFirmwareSetUsingFirmwareSet(t *testi if local.R.FirmwareSet == nil { t.Error("struct should have been eager loaded") } + + if !ranAfterSelectHook { + t.Error("failed to run AfterSelect hook for relationship") + } } func testAttributesFirmwareSetToOneSetOpComponentFirmwareSetUsingFirmwareSet(t *testing.T) { diff --git a/internal/models/attributes_test.go b/internal/models/attributes_test.go index 4922b45..66714a5 100644 --- a/internal/models/attributes_test.go +++ b/internal/models/attributes_test.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -576,6 +576,12 @@ func testAttributeToOneServerUsingServer(t *testing.T) { t.Errorf("want: %v, got %v", foreign.ID, check.ID) } + ranAfterSelectHook := false + AddServerHook(boil.AfterSelectHook, func(ctx context.Context, e boil.ContextExecutor, o *Server) error { + ranAfterSelectHook = true + return nil + }) + slice := AttributeSlice{&local} if err = local.L.LoadServer(ctx, tx, false, (*[]*Attribute)(&slice), nil); err != nil { t.Fatal(err) @@ -591,6 +597,10 @@ func testAttributeToOneServerUsingServer(t *testing.T) { if local.R.Server == nil { t.Error("struct should have been eager loaded") } + + if !ranAfterSelectHook { + t.Error("failed to run AfterSelect hook for relationship") + } } func testAttributeToOneServerComponentUsingServerComponent(t *testing.T) { @@ -627,6 +637,12 @@ func testAttributeToOneServerComponentUsingServerComponent(t *testing.T) { t.Errorf("want: %v, got %v", foreign.ID, check.ID) } + ranAfterSelectHook := false + AddServerComponentHook(boil.AfterSelectHook, func(ctx context.Context, e boil.ContextExecutor, o *ServerComponent) error { + ranAfterSelectHook = true + return nil + }) + slice := AttributeSlice{&local} if err = local.L.LoadServerComponent(ctx, tx, false, (*[]*Attribute)(&slice), nil); err != nil { t.Fatal(err) @@ -642,6 +658,10 @@ func testAttributeToOneServerComponentUsingServerComponent(t *testing.T) { if local.R.ServerComponent == nil { t.Error("struct should have been eager loaded") } + + if !ranAfterSelectHook { + t.Error("failed to run AfterSelect hook for relationship") + } } func testAttributeToOneSetOpServerUsingServer(t *testing.T) { diff --git a/internal/models/bmc_mac_address.go b/internal/models/bmc_mac_address.go index 1a21116..6a890d6 100644 --- a/internal/models/bmc_mac_address.go +++ b/internal/models/bmc_mac_address.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -387,9 +387,25 @@ func (bmcMacAddressL) LoadSerialNumBomInfo(ctx context.Context, e boil.ContextEx var object *BMCMacAddress if singular { - object = maybeBMCMacAddress.(*BMCMacAddress) + var ok bool + object, ok = maybeBMCMacAddress.(*BMCMacAddress) + if !ok { + object = new(BMCMacAddress) + ok = queries.SetFromEmbeddedStruct(&object, &maybeBMCMacAddress) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeBMCMacAddress)) + } + } } else { - slice = *maybeBMCMacAddress.(*[]*BMCMacAddress) + s, ok := maybeBMCMacAddress.(*[]*BMCMacAddress) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeBMCMacAddress) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeBMCMacAddress)) + } + } } args := make([]interface{}, 0, 1) @@ -446,7 +462,7 @@ func (bmcMacAddressL) LoadSerialNumBomInfo(ctx context.Context, e boil.ContextEx return errors.Wrap(err, "error occurred during iteration of eager loaded relations for bom_info") } - if len(bmcMacAddressAfterSelectHooks) != 0 { + if len(bomInfoAfterSelectHooks) != 0 { for _, obj := range resultSlice { if err := obj.doAfterSelectHooks(ctx, e); err != nil { return err @@ -946,6 +962,11 @@ func BMCMacAddressExists(ctx context.Context, exec boil.ContextExecutor, bMCMacA return exists, nil } +// Exists checks if the BMCMacAddress row exists. +func (o *BMCMacAddress) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return BMCMacAddressExists(ctx, exec, o.BMCMacAddress) +} + // 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 *BMCMacAddress) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { diff --git a/internal/models/bmc_mac_address_test.go b/internal/models/bmc_mac_address_test.go index baaea86..5699e3f 100644 --- a/internal/models/bmc_mac_address_test.go +++ b/internal/models/bmc_mac_address_test.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -576,6 +576,12 @@ func testBMCMacAddressToOneBomInfoUsingSerialNumBomInfo(t *testing.T) { t.Errorf("want: %v, got %v", foreign.SerialNum, check.SerialNum) } + ranAfterSelectHook := false + AddBomInfoHook(boil.AfterSelectHook, func(ctx context.Context, e boil.ContextExecutor, o *BomInfo) error { + ranAfterSelectHook = true + return nil + }) + slice := BMCMacAddressSlice{&local} if err = local.L.LoadSerialNumBomInfo(ctx, tx, false, (*[]*BMCMacAddress)(&slice), nil); err != nil { t.Fatal(err) @@ -591,6 +597,10 @@ func testBMCMacAddressToOneBomInfoUsingSerialNumBomInfo(t *testing.T) { if local.R.SerialNumBomInfo == nil { t.Error("struct should have been eager loaded") } + + if !ranAfterSelectHook { + t.Error("failed to run AfterSelect hook for relationship") + } } func testBMCMacAddressToOneSetOpBomInfoUsingSerialNumBomInfo(t *testing.T) { diff --git a/internal/models/boil_main_test.go b/internal/models/boil_main_test.go index 83c6779..3c1eb37 100644 --- a/internal/models/boil_main_test.go +++ b/internal/models/boil_main_test.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 diff --git a/internal/models/boil_queries.go b/internal/models/boil_queries.go index 7576b06..171346b 100644 --- a/internal/models/boil_queries.go +++ b/internal/models/boil_queries.go @@ -1,9 +1,11 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 ( + "regexp" + "github.com/volatiletech/sqlboiler/v4/drivers" "github.com/volatiletech/sqlboiler/v4/queries" "github.com/volatiletech/sqlboiler/v4/queries/qm" @@ -23,6 +25,9 @@ var dialect = drivers.Dialect{ UseCaseWhenExistsClause: false, } +// This is a dummy variable to prevent unused regexp import error +var _ = ®exp.Regexp{} + // NewQuery initializes a new Query using the passed in QueryMods func NewQuery(mods ...qm.QueryMod) *queries.Query { q := &queries.Query{} diff --git a/internal/models/boil_queries_test.go b/internal/models/boil_queries_test.go index 33b8712..d39183e 100644 --- a/internal/models/boil_queries_test.go +++ b/internal/models/boil_queries_test.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -7,7 +7,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "math/rand" "regexp" @@ -38,7 +37,7 @@ type fKeyDestroyer struct { func (f *fKeyDestroyer) Read(b []byte) (int, error) { if f.buf == nil { - all, err := ioutil.ReadAll(f.reader) + all, err := io.ReadAll(f.reader) if err != nil { return 0, err } diff --git a/internal/models/boil_suites_test.go b/internal/models/boil_suites_test.go index 5f58c37..9cfd933 100644 --- a/internal/models/boil_suites_test.go +++ b/internal/models/boil_suites_test.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 diff --git a/internal/models/boil_table_names.go b/internal/models/boil_table_names.go index f8efec5..a908ebe 100644 --- a/internal/models/boil_table_names.go +++ b/internal/models/boil_table_names.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 diff --git a/internal/models/boil_types.go b/internal/models/boil_types.go index 3d1f76d..23ad5ac 100644 --- a/internal/models/boil_types.go +++ b/internal/models/boil_types.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 diff --git a/internal/models/boil_view_names.go b/internal/models/boil_view_names.go index 8ae6405..9f42d9e 100644 --- a/internal/models/boil_view_names.go +++ b/internal/models/boil_view_names.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 diff --git a/internal/models/bom_info.go b/internal/models/bom_info.go index 64c600a..02277b2 100644 --- a/internal/models/bom_info.go +++ b/internal/models/bom_info.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -443,9 +443,25 @@ func (bomInfoL) LoadSerialNumAocMacAddresses(ctx context.Context, e boil.Context var object *BomInfo if singular { - object = maybeBomInfo.(*BomInfo) + var ok bool + object, ok = maybeBomInfo.(*BomInfo) + if !ok { + object = new(BomInfo) + ok = queries.SetFromEmbeddedStruct(&object, &maybeBomInfo) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeBomInfo)) + } + } } else { - slice = *maybeBomInfo.(*[]*BomInfo) + s, ok := maybeBomInfo.(*[]*BomInfo) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeBomInfo) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeBomInfo)) + } + } } args := make([]interface{}, 0, 1) @@ -541,9 +557,25 @@ func (bomInfoL) LoadSerialNumBMCMacAddresses(ctx context.Context, e boil.Context var object *BomInfo if singular { - object = maybeBomInfo.(*BomInfo) + var ok bool + object, ok = maybeBomInfo.(*BomInfo) + if !ok { + object = new(BomInfo) + ok = queries.SetFromEmbeddedStruct(&object, &maybeBomInfo) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeBomInfo)) + } + } } else { - slice = *maybeBomInfo.(*[]*BomInfo) + s, ok := maybeBomInfo.(*[]*BomInfo) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeBomInfo) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeBomInfo)) + } + } } args := make([]interface{}, 0, 1) @@ -1153,6 +1185,11 @@ func BomInfoExists(ctx context.Context, exec boil.ContextExecutor, serialNum str return exists, nil } +// Exists checks if the BomInfo row exists. +func (o *BomInfo) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return BomInfoExists(ctx, exec, o.SerialNum) +} + // 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 { diff --git a/internal/models/bom_info_test.go b/internal/models/bom_info_test.go index e1dbd28..81ec1a1 100644 --- a/internal/models/bom_info_test.go +++ b/internal/models/bom_info_test.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 diff --git a/internal/models/component_firmware_set.go b/internal/models/component_firmware_set.go index f4a5eaa..e782019 100644 --- a/internal/models/component_firmware_set.go +++ b/internal/models/component_firmware_set.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -429,9 +429,25 @@ func (componentFirmwareSetL) LoadFirmwareSetAttributesFirmwareSets(ctx context.C var object *ComponentFirmwareSet if singular { - object = maybeComponentFirmwareSet.(*ComponentFirmwareSet) + var ok bool + object, ok = maybeComponentFirmwareSet.(*ComponentFirmwareSet) + if !ok { + object = new(ComponentFirmwareSet) + ok = queries.SetFromEmbeddedStruct(&object, &maybeComponentFirmwareSet) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeComponentFirmwareSet)) + } + } } else { - slice = *maybeComponentFirmwareSet.(*[]*ComponentFirmwareSet) + s, ok := maybeComponentFirmwareSet.(*[]*ComponentFirmwareSet) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeComponentFirmwareSet) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeComponentFirmwareSet)) + } + } } args := make([]interface{}, 0, 1) @@ -527,9 +543,25 @@ func (componentFirmwareSetL) LoadFirmwareSetComponentFirmwareSetMaps(ctx context var object *ComponentFirmwareSet if singular { - object = maybeComponentFirmwareSet.(*ComponentFirmwareSet) + var ok bool + object, ok = maybeComponentFirmwareSet.(*ComponentFirmwareSet) + if !ok { + object = new(ComponentFirmwareSet) + ok = queries.SetFromEmbeddedStruct(&object, &maybeComponentFirmwareSet) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeComponentFirmwareSet)) + } + } } else { - slice = *maybeComponentFirmwareSet.(*[]*ComponentFirmwareSet) + s, ok := maybeComponentFirmwareSet.(*[]*ComponentFirmwareSet) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeComponentFirmwareSet) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeComponentFirmwareSet)) + } + } } args := make([]interface{}, 0, 1) @@ -1229,6 +1261,11 @@ func ComponentFirmwareSetExists(ctx context.Context, exec boil.ContextExecutor, return exists, nil } +// Exists checks if the ComponentFirmwareSet row exists. +func (o *ComponentFirmwareSet) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return ComponentFirmwareSetExists(ctx, exec, o.ID) +} + // 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 *ComponentFirmwareSet) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { diff --git a/internal/models/component_firmware_set_map.go b/internal/models/component_firmware_set_map.go index 99a8d78..c466510 100644 --- a/internal/models/component_firmware_set_map.go +++ b/internal/models/component_firmware_set_map.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -415,9 +415,25 @@ func (componentFirmwareSetMapL) LoadFirmwareSet(ctx context.Context, e boil.Cont var object *ComponentFirmwareSetMap if singular { - object = maybeComponentFirmwareSetMap.(*ComponentFirmwareSetMap) + var ok bool + object, ok = maybeComponentFirmwareSetMap.(*ComponentFirmwareSetMap) + if !ok { + object = new(ComponentFirmwareSetMap) + ok = queries.SetFromEmbeddedStruct(&object, &maybeComponentFirmwareSetMap) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeComponentFirmwareSetMap)) + } + } } else { - slice = *maybeComponentFirmwareSetMap.(*[]*ComponentFirmwareSetMap) + s, ok := maybeComponentFirmwareSetMap.(*[]*ComponentFirmwareSetMap) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeComponentFirmwareSetMap) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeComponentFirmwareSetMap)) + } + } } args := make([]interface{}, 0, 1) @@ -474,7 +490,7 @@ func (componentFirmwareSetMapL) LoadFirmwareSet(ctx context.Context, e boil.Cont return errors.Wrap(err, "error occurred during iteration of eager loaded relations for component_firmware_set") } - if len(componentFirmwareSetMapAfterSelectHooks) != 0 { + if len(componentFirmwareSetAfterSelectHooks) != 0 { for _, obj := range resultSlice { if err := obj.doAfterSelectHooks(ctx, e); err != nil { return err @@ -519,9 +535,25 @@ func (componentFirmwareSetMapL) LoadFirmware(ctx context.Context, e boil.Context var object *ComponentFirmwareSetMap if singular { - object = maybeComponentFirmwareSetMap.(*ComponentFirmwareSetMap) + var ok bool + object, ok = maybeComponentFirmwareSetMap.(*ComponentFirmwareSetMap) + if !ok { + object = new(ComponentFirmwareSetMap) + ok = queries.SetFromEmbeddedStruct(&object, &maybeComponentFirmwareSetMap) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeComponentFirmwareSetMap)) + } + } } else { - slice = *maybeComponentFirmwareSetMap.(*[]*ComponentFirmwareSetMap) + s, ok := maybeComponentFirmwareSetMap.(*[]*ComponentFirmwareSetMap) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeComponentFirmwareSetMap) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeComponentFirmwareSetMap)) + } + } } args := make([]interface{}, 0, 1) @@ -578,7 +610,7 @@ func (componentFirmwareSetMapL) LoadFirmware(ctx context.Context, e boil.Context return errors.Wrap(err, "error occurred during iteration of eager loaded relations for component_firmware_version") } - if len(componentFirmwareSetMapAfterSelectHooks) != 0 { + if len(componentFirmwareVersionAfterSelectHooks) != 0 { for _, obj := range resultSlice { if err := obj.doAfterSelectHooks(ctx, e); err != nil { return err @@ -1125,6 +1157,11 @@ func ComponentFirmwareSetMapExists(ctx context.Context, exec boil.ContextExecuto return exists, nil } +// Exists checks if the ComponentFirmwareSetMap row exists. +func (o *ComponentFirmwareSetMap) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return ComponentFirmwareSetMapExists(ctx, exec, o.ID) +} + // 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 *ComponentFirmwareSetMap) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { diff --git a/internal/models/component_firmware_set_map_test.go b/internal/models/component_firmware_set_map_test.go index 43d13bd..6a5bfd3 100644 --- a/internal/models/component_firmware_set_map_test.go +++ b/internal/models/component_firmware_set_map_test.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -576,6 +576,12 @@ func testComponentFirmwareSetMapToOneComponentFirmwareSetUsingFirmwareSet(t *tes t.Errorf("want: %v, got %v", foreign.ID, check.ID) } + ranAfterSelectHook := false + AddComponentFirmwareSetHook(boil.AfterSelectHook, func(ctx context.Context, e boil.ContextExecutor, o *ComponentFirmwareSet) error { + ranAfterSelectHook = true + return nil + }) + slice := ComponentFirmwareSetMapSlice{&local} if err = local.L.LoadFirmwareSet(ctx, tx, false, (*[]*ComponentFirmwareSetMap)(&slice), nil); err != nil { t.Fatal(err) @@ -591,6 +597,10 @@ func testComponentFirmwareSetMapToOneComponentFirmwareSetUsingFirmwareSet(t *tes if local.R.FirmwareSet == nil { t.Error("struct should have been eager loaded") } + + if !ranAfterSelectHook { + t.Error("failed to run AfterSelect hook for relationship") + } } func testComponentFirmwareSetMapToOneComponentFirmwareVersionUsingFirmware(t *testing.T) { @@ -627,6 +637,12 @@ func testComponentFirmwareSetMapToOneComponentFirmwareVersionUsingFirmware(t *te t.Errorf("want: %v, got %v", foreign.ID, check.ID) } + ranAfterSelectHook := false + AddComponentFirmwareVersionHook(boil.AfterSelectHook, func(ctx context.Context, e boil.ContextExecutor, o *ComponentFirmwareVersion) error { + ranAfterSelectHook = true + return nil + }) + slice := ComponentFirmwareSetMapSlice{&local} if err = local.L.LoadFirmware(ctx, tx, false, (*[]*ComponentFirmwareSetMap)(&slice), nil); err != nil { t.Fatal(err) @@ -642,6 +658,10 @@ func testComponentFirmwareSetMapToOneComponentFirmwareVersionUsingFirmware(t *te if local.R.Firmware == nil { t.Error("struct should have been eager loaded") } + + if !ranAfterSelectHook { + t.Error("failed to run AfterSelect hook for relationship") + } } func testComponentFirmwareSetMapToOneSetOpComponentFirmwareSetUsingFirmwareSet(t *testing.T) { diff --git a/internal/models/component_firmware_set_test.go b/internal/models/component_firmware_set_test.go index e7e2cb7..6628525 100644 --- a/internal/models/component_firmware_set_test.go +++ b/internal/models/component_firmware_set_test.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 diff --git a/internal/models/component_firmware_version.go b/internal/models/component_firmware_version.go index e96246f..7f32eae 100644 --- a/internal/models/component_firmware_version.go +++ b/internal/models/component_firmware_version.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -476,9 +476,25 @@ func (componentFirmwareVersionL) LoadFirmwareComponentFirmwareSetMaps(ctx contex var object *ComponentFirmwareVersion if singular { - object = maybeComponentFirmwareVersion.(*ComponentFirmwareVersion) + var ok bool + object, ok = maybeComponentFirmwareVersion.(*ComponentFirmwareVersion) + if !ok { + object = new(ComponentFirmwareVersion) + ok = queries.SetFromEmbeddedStruct(&object, &maybeComponentFirmwareVersion) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeComponentFirmwareVersion)) + } + } } else { - slice = *maybeComponentFirmwareVersion.(*[]*ComponentFirmwareVersion) + s, ok := maybeComponentFirmwareVersion.(*[]*ComponentFirmwareVersion) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeComponentFirmwareVersion) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeComponentFirmwareVersion)) + } + } } args := make([]interface{}, 0, 1) @@ -1051,6 +1067,11 @@ func ComponentFirmwareVersionExists(ctx context.Context, exec boil.ContextExecut return exists, nil } +// Exists checks if the ComponentFirmwareVersion row exists. +func (o *ComponentFirmwareVersion) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return ComponentFirmwareVersionExists(ctx, exec, o.ID) +} + // 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 *ComponentFirmwareVersion) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { diff --git a/internal/models/component_firmware_version_test.go b/internal/models/component_firmware_version_test.go index 3a4ee28..33cf085 100644 --- a/internal/models/component_firmware_version_test.go +++ b/internal/models/component_firmware_version_test.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 diff --git a/internal/models/crdb_main_test.go b/internal/models/crdb_main_test.go index c87fe10..61362d5 100644 --- a/internal/models/crdb_main_test.go +++ b/internal/models/crdb_main_test.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -66,12 +66,12 @@ func (c *crdbTester) setup() error { return err } - dumpCmd := exec.Command("cockroach", "dump", c.dbName, "--url", c.dbURL, "--insecure", "--dump-mode=schema") + dumpCmd := exec.Command("cockroach", "sql", "--url", c.dbURL, "--insecure", "-e", "SHOW CREATE ALL TABLES") createCmd := exec.Command("cockroach", "sql", "--url", c.testDBURL, "--database", c.testDBName, "--insecure") r, w := io.Pipe() dumpCmd.Stdout = w - createCmd.Stdin = newFKeyDestroyer(rgxCDBFkey, r) + createCmd.Stdin = newShowCreateTableFilter(newFKeyDestroyer(rgxCDBFkey, r)) if err = dumpCmd.Start(); err != nil { return errors.Wrap(err, "failed to start 'cockroach dump' command") @@ -168,3 +168,36 @@ func buildQueryString(user, pass, dbname, host string, port int, sslmode string) return fmt.Sprintf("postgresql://%s@%s:%d/%s?sslmode=%s", up, host, port, dbname, sslmode) } + +type showCreateFilter struct { + reader io.Reader + buf *bytes.Buffer +} + +func newShowCreateTableFilter(reader io.Reader) io.Reader { + return &showCreateFilter{ + reader: reader, + } +} + +// The new CRDB versions don't have the dump command like other DBMS +// instead the docs say to use 'SHOW CREATE ALL TABLES' but that can't +// be directly fed to the 'cockroach sql' command. +// This filter removes the non-sql parts of the new output. +func (f *showCreateFilter) Read(b []byte) (int, error) { + if f.buf == nil { + all, err := io.ReadAll(f.reader) + + if err != nil { + return 0, err + } + + all = bytes.Replace(all, []byte("create_statement"), []byte{}, -1) + all = bytes.Replace(all, []byte("\"CREATE"), []byte("CREATE"), -1) + all = bytes.Replace(all, []byte(";\""), []byte(";"), -1) + all = bytes.Replace(all, []byte(`""`), []byte(`"`), -1) + f.buf = bytes.NewBuffer(all) + } + + return f.buf.Read(b) +} diff --git a/internal/models/crdb_suites_test.go b/internal/models/crdb_suites_test.go index 1ebf0ae..71ef2b3 100644 --- a/internal/models/crdb_suites_test.go +++ b/internal/models/crdb_suites_test.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 diff --git a/internal/models/crdb_upsert.go b/internal/models/crdb_upsert.go index 8b75596..2c6c25a 100644 --- a/internal/models/crdb_upsert.go +++ b/internal/models/crdb_upsert.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 diff --git a/internal/models/server_component_types.go b/internal/models/server_component_types.go index 47b7443..23f8129 100644 --- a/internal/models/server_component_types.go +++ b/internal/models/server_component_types.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -412,9 +412,25 @@ func (serverComponentTypeL) LoadServerComponents(ctx context.Context, e boil.Con var object *ServerComponentType if singular { - object = maybeServerComponentType.(*ServerComponentType) + var ok bool + object, ok = maybeServerComponentType.(*ServerComponentType) + if !ok { + object = new(ServerComponentType) + ok = queries.SetFromEmbeddedStruct(&object, &maybeServerComponentType) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeServerComponentType)) + } + } } else { - slice = *maybeServerComponentType.(*[]*ServerComponentType) + s, ok := maybeServerComponentType.(*[]*ServerComponentType) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeServerComponentType) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeServerComponentType)) + } + } } args := make([]interface{}, 0, 1) @@ -987,6 +1003,11 @@ func ServerComponentTypeExists(ctx context.Context, exec boil.ContextExecutor, i return exists, nil } +// Exists checks if the ServerComponentType row exists. +func (o *ServerComponentType) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return ServerComponentTypeExists(ctx, exec, o.ID) +} + // 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 *ServerComponentType) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { diff --git a/internal/models/server_component_types_test.go b/internal/models/server_component_types_test.go index 6890f3a..bcb565d 100644 --- a/internal/models/server_component_types_test.go +++ b/internal/models/server_component_types_test.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 diff --git a/internal/models/server_components.go b/internal/models/server_components.go index 50e6d2e..c9709a2 100644 --- a/internal/models/server_components.go +++ b/internal/models/server_components.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -506,9 +506,25 @@ func (serverComponentL) LoadServer(ctx context.Context, e boil.ContextExecutor, var object *ServerComponent if singular { - object = maybeServerComponent.(*ServerComponent) + var ok bool + object, ok = maybeServerComponent.(*ServerComponent) + if !ok { + object = new(ServerComponent) + ok = queries.SetFromEmbeddedStruct(&object, &maybeServerComponent) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeServerComponent)) + } + } } else { - slice = *maybeServerComponent.(*[]*ServerComponent) + s, ok := maybeServerComponent.(*[]*ServerComponent) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeServerComponent) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeServerComponent)) + } + } } args := make([]interface{}, 0, 1) @@ -566,7 +582,7 @@ func (serverComponentL) LoadServer(ctx context.Context, e boil.ContextExecutor, return errors.Wrap(err, "error occurred during iteration of eager loaded relations for servers") } - if len(serverComponentAfterSelectHooks) != 0 { + if len(serverAfterSelectHooks) != 0 { for _, obj := range resultSlice { if err := obj.doAfterSelectHooks(ctx, e); err != nil { return err @@ -611,9 +627,25 @@ func (serverComponentL) LoadServerComponentType(ctx context.Context, e boil.Cont var object *ServerComponent if singular { - object = maybeServerComponent.(*ServerComponent) + var ok bool + object, ok = maybeServerComponent.(*ServerComponent) + if !ok { + object = new(ServerComponent) + ok = queries.SetFromEmbeddedStruct(&object, &maybeServerComponent) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeServerComponent)) + } + } } else { - slice = *maybeServerComponent.(*[]*ServerComponent) + s, ok := maybeServerComponent.(*[]*ServerComponent) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeServerComponent) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeServerComponent)) + } + } } args := make([]interface{}, 0, 1) @@ -670,7 +702,7 @@ func (serverComponentL) LoadServerComponentType(ctx context.Context, e boil.Cont return errors.Wrap(err, "error occurred during iteration of eager loaded relations for server_component_types") } - if len(serverComponentAfterSelectHooks) != 0 { + if len(serverComponentTypeAfterSelectHooks) != 0 { for _, obj := range resultSlice { if err := obj.doAfterSelectHooks(ctx, e); err != nil { return err @@ -715,9 +747,25 @@ func (serverComponentL) LoadAttributes(ctx context.Context, e boil.ContextExecut var object *ServerComponent if singular { - object = maybeServerComponent.(*ServerComponent) + var ok bool + object, ok = maybeServerComponent.(*ServerComponent) + if !ok { + object = new(ServerComponent) + ok = queries.SetFromEmbeddedStruct(&object, &maybeServerComponent) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeServerComponent)) + } + } } else { - slice = *maybeServerComponent.(*[]*ServerComponent) + s, ok := maybeServerComponent.(*[]*ServerComponent) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeServerComponent) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeServerComponent)) + } + } } args := make([]interface{}, 0, 1) @@ -813,9 +861,25 @@ func (serverComponentL) LoadVersionedAttributes(ctx context.Context, e boil.Cont var object *ServerComponent if singular { - object = maybeServerComponent.(*ServerComponent) + var ok bool + object, ok = maybeServerComponent.(*ServerComponent) + if !ok { + object = new(ServerComponent) + ok = queries.SetFromEmbeddedStruct(&object, &maybeServerComponent) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeServerComponent)) + } + } } else { - slice = *maybeServerComponent.(*[]*ServerComponent) + s, ok := maybeServerComponent.(*[]*ServerComponent) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeServerComponent) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeServerComponent)) + } + } } args := make([]interface{}, 0, 1) @@ -1683,6 +1747,11 @@ func ServerComponentExists(ctx context.Context, exec boil.ContextExecutor, iD st return exists, nil } +// Exists checks if the ServerComponent row exists. +func (o *ServerComponent) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return ServerComponentExists(ctx, exec, o.ID) +} + // 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 *ServerComponent) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { diff --git a/internal/models/server_components_test.go b/internal/models/server_components_test.go index 3314f91..389d779 100644 --- a/internal/models/server_components_test.go +++ b/internal/models/server_components_test.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -1232,6 +1232,12 @@ func testServerComponentToOneServerUsingServer(t *testing.T) { t.Errorf("want: %v, got %v", foreign.ID, check.ID) } + ranAfterSelectHook := false + AddServerHook(boil.AfterSelectHook, func(ctx context.Context, e boil.ContextExecutor, o *Server) error { + ranAfterSelectHook = true + return nil + }) + slice := ServerComponentSlice{&local} if err = local.L.LoadServer(ctx, tx, false, (*[]*ServerComponent)(&slice), nil); err != nil { t.Fatal(err) @@ -1247,6 +1253,10 @@ func testServerComponentToOneServerUsingServer(t *testing.T) { if local.R.Server == nil { t.Error("struct should have been eager loaded") } + + if !ranAfterSelectHook { + t.Error("failed to run AfterSelect hook for relationship") + } } func testServerComponentToOneServerComponentTypeUsingServerComponentType(t *testing.T) { @@ -1283,6 +1293,12 @@ func testServerComponentToOneServerComponentTypeUsingServerComponentType(t *test t.Errorf("want: %v, got %v", foreign.ID, check.ID) } + ranAfterSelectHook := false + AddServerComponentTypeHook(boil.AfterSelectHook, func(ctx context.Context, e boil.ContextExecutor, o *ServerComponentType) error { + ranAfterSelectHook = true + return nil + }) + slice := ServerComponentSlice{&local} if err = local.L.LoadServerComponentType(ctx, tx, false, (*[]*ServerComponent)(&slice), nil); err != nil { t.Fatal(err) @@ -1298,6 +1314,10 @@ func testServerComponentToOneServerComponentTypeUsingServerComponentType(t *test if local.R.ServerComponentType == nil { t.Error("struct should have been eager loaded") } + + if !ranAfterSelectHook { + t.Error("failed to run AfterSelect hook for relationship") + } } func testServerComponentToOneSetOpServerUsingServer(t *testing.T) { diff --git a/internal/models/server_credential_types.go b/internal/models/server_credential_types.go index 8d4f18e..2efd780 100644 --- a/internal/models/server_credential_types.go +++ b/internal/models/server_credential_types.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -448,9 +448,25 @@ func (serverCredentialTypeL) LoadServerCredentials(ctx context.Context, e boil.C var object *ServerCredentialType if singular { - object = maybeServerCredentialType.(*ServerCredentialType) + var ok bool + object, ok = maybeServerCredentialType.(*ServerCredentialType) + if !ok { + object = new(ServerCredentialType) + ok = queries.SetFromEmbeddedStruct(&object, &maybeServerCredentialType) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeServerCredentialType)) + } + } } else { - slice = *maybeServerCredentialType.(*[]*ServerCredentialType) + s, ok := maybeServerCredentialType.(*[]*ServerCredentialType) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeServerCredentialType) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeServerCredentialType)) + } + } } args := make([]interface{}, 0, 1) @@ -1023,6 +1039,11 @@ func ServerCredentialTypeExists(ctx context.Context, exec boil.ContextExecutor, return exists, nil } +// Exists checks if the ServerCredentialType row exists. +func (o *ServerCredentialType) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return ServerCredentialTypeExists(ctx, exec, o.ID) +} + // 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 *ServerCredentialType) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { diff --git a/internal/models/server_credential_types_test.go b/internal/models/server_credential_types_test.go index fb84cf2..71592a5 100644 --- a/internal/models/server_credential_types_test.go +++ b/internal/models/server_credential_types_test.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 diff --git a/internal/models/server_credentials.go b/internal/models/server_credentials.go index 1764bf6..ad9c250 100644 --- a/internal/models/server_credentials.go +++ b/internal/models/server_credentials.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -443,9 +443,25 @@ func (serverCredentialL) LoadServerCredentialType(ctx context.Context, e boil.Co var object *ServerCredential if singular { - object = maybeServerCredential.(*ServerCredential) + var ok bool + object, ok = maybeServerCredential.(*ServerCredential) + if !ok { + object = new(ServerCredential) + ok = queries.SetFromEmbeddedStruct(&object, &maybeServerCredential) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeServerCredential)) + } + } } else { - slice = *maybeServerCredential.(*[]*ServerCredential) + s, ok := maybeServerCredential.(*[]*ServerCredential) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeServerCredential) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeServerCredential)) + } + } } args := make([]interface{}, 0, 1) @@ -502,7 +518,7 @@ func (serverCredentialL) LoadServerCredentialType(ctx context.Context, e boil.Co return errors.Wrap(err, "error occurred during iteration of eager loaded relations for server_credential_types") } - if len(serverCredentialAfterSelectHooks) != 0 { + if len(serverCredentialTypeAfterSelectHooks) != 0 { for _, obj := range resultSlice { if err := obj.doAfterSelectHooks(ctx, e); err != nil { return err @@ -547,9 +563,25 @@ func (serverCredentialL) LoadServer(ctx context.Context, e boil.ContextExecutor, var object *ServerCredential if singular { - object = maybeServerCredential.(*ServerCredential) + var ok bool + object, ok = maybeServerCredential.(*ServerCredential) + if !ok { + object = new(ServerCredential) + ok = queries.SetFromEmbeddedStruct(&object, &maybeServerCredential) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeServerCredential)) + } + } } else { - slice = *maybeServerCredential.(*[]*ServerCredential) + s, ok := maybeServerCredential.(*[]*ServerCredential) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeServerCredential) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeServerCredential)) + } + } } args := make([]interface{}, 0, 1) @@ -607,7 +639,7 @@ func (serverCredentialL) LoadServer(ctx context.Context, e boil.ContextExecutor, return errors.Wrap(err, "error occurred during iteration of eager loaded relations for servers") } - if len(serverCredentialAfterSelectHooks) != 0 { + if len(serverAfterSelectHooks) != 0 { for _, obj := range resultSlice { if err := obj.doAfterSelectHooks(ctx, e); err != nil { return err @@ -1170,6 +1202,11 @@ func ServerCredentialExists(ctx context.Context, exec boil.ContextExecutor, iD s return exists, nil } +// Exists checks if the ServerCredential row exists. +func (o *ServerCredential) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return ServerCredentialExists(ctx, exec, o.ID) +} + // 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 *ServerCredential) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { diff --git a/internal/models/server_credentials_test.go b/internal/models/server_credentials_test.go index 21bbea8..7454f65 100644 --- a/internal/models/server_credentials_test.go +++ b/internal/models/server_credentials_test.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -576,6 +576,12 @@ func testServerCredentialToOneServerCredentialTypeUsingServerCredentialType(t *t t.Errorf("want: %v, got %v", foreign.ID, check.ID) } + ranAfterSelectHook := false + AddServerCredentialTypeHook(boil.AfterSelectHook, func(ctx context.Context, e boil.ContextExecutor, o *ServerCredentialType) error { + ranAfterSelectHook = true + return nil + }) + slice := ServerCredentialSlice{&local} if err = local.L.LoadServerCredentialType(ctx, tx, false, (*[]*ServerCredential)(&slice), nil); err != nil { t.Fatal(err) @@ -591,6 +597,10 @@ func testServerCredentialToOneServerCredentialTypeUsingServerCredentialType(t *t if local.R.ServerCredentialType == nil { t.Error("struct should have been eager loaded") } + + if !ranAfterSelectHook { + t.Error("failed to run AfterSelect hook for relationship") + } } func testServerCredentialToOneServerUsingServer(t *testing.T) { @@ -627,6 +637,12 @@ func testServerCredentialToOneServerUsingServer(t *testing.T) { t.Errorf("want: %v, got %v", foreign.ID, check.ID) } + ranAfterSelectHook := false + AddServerHook(boil.AfterSelectHook, func(ctx context.Context, e boil.ContextExecutor, o *Server) error { + ranAfterSelectHook = true + return nil + }) + slice := ServerCredentialSlice{&local} if err = local.L.LoadServer(ctx, tx, false, (*[]*ServerCredential)(&slice), nil); err != nil { t.Fatal(err) @@ -642,6 +658,10 @@ func testServerCredentialToOneServerUsingServer(t *testing.T) { if local.R.Server == nil { t.Error("struct should have been eager loaded") } + + if !ranAfterSelectHook { + t.Error("failed to run AfterSelect hook for relationship") + } } func testServerCredentialToOneSetOpServerCredentialTypeUsingServerCredentialType(t *testing.T) { diff --git a/internal/models/servers.go b/internal/models/servers.go index 48db2c2..0cbcbf8 100644 --- a/internal/models/servers.go +++ b/internal/models/servers.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -491,9 +491,25 @@ func (serverL) LoadAttributes(ctx context.Context, e boil.ContextExecutor, singu var object *Server if singular { - object = maybeServer.(*Server) + var ok bool + object, ok = maybeServer.(*Server) + if !ok { + object = new(Server) + ok = queries.SetFromEmbeddedStruct(&object, &maybeServer) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeServer)) + } + } } else { - slice = *maybeServer.(*[]*Server) + s, ok := maybeServer.(*[]*Server) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeServer) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeServer)) + } + } } args := make([]interface{}, 0, 1) @@ -589,9 +605,25 @@ func (serverL) LoadServerComponents(ctx context.Context, e boil.ContextExecutor, var object *Server if singular { - object = maybeServer.(*Server) + var ok bool + object, ok = maybeServer.(*Server) + if !ok { + object = new(Server) + ok = queries.SetFromEmbeddedStruct(&object, &maybeServer) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeServer)) + } + } } else { - slice = *maybeServer.(*[]*Server) + s, ok := maybeServer.(*[]*Server) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeServer) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeServer)) + } + } } args := make([]interface{}, 0, 1) @@ -687,9 +719,25 @@ func (serverL) LoadServerCredentials(ctx context.Context, e boil.ContextExecutor var object *Server if singular { - object = maybeServer.(*Server) + var ok bool + object, ok = maybeServer.(*Server) + if !ok { + object = new(Server) + ok = queries.SetFromEmbeddedStruct(&object, &maybeServer) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeServer)) + } + } } else { - slice = *maybeServer.(*[]*Server) + s, ok := maybeServer.(*[]*Server) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeServer) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeServer)) + } + } } args := make([]interface{}, 0, 1) @@ -785,9 +833,25 @@ func (serverL) LoadVersionedAttributes(ctx context.Context, e boil.ContextExecut var object *Server if singular { - object = maybeServer.(*Server) + var ok bool + object, ok = maybeServer.(*Server) + if !ok { + object = new(Server) + ok = queries.SetFromEmbeddedStruct(&object, &maybeServer) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeServer)) + } + } } else { - slice = *maybeServer.(*[]*Server) + s, ok := maybeServer.(*[]*Server) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeServer) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeServer)) + } + } } args := make([]interface{}, 0, 1) @@ -1708,6 +1772,11 @@ func ServerExists(ctx context.Context, exec boil.ContextExecutor, iD string) (bo return exists, nil } +// Exists checks if the Server row exists. +func (o *Server) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return ServerExists(ctx, exec, o.ID) +} + // 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 *Server) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { diff --git a/internal/models/servers_test.go b/internal/models/servers_test.go index a32b885..37c5c6e 100644 --- a/internal/models/servers_test.go +++ b/internal/models/servers_test.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 diff --git a/internal/models/versioned_attributes.go b/internal/models/versioned_attributes.go index 60c6b3b..8517c2a 100644 --- a/internal/models/versioned_attributes.go +++ b/internal/models/versioned_attributes.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -475,9 +475,25 @@ func (versionedAttributeL) LoadServer(ctx context.Context, e boil.ContextExecuto var object *VersionedAttribute if singular { - object = maybeVersionedAttribute.(*VersionedAttribute) + var ok bool + object, ok = maybeVersionedAttribute.(*VersionedAttribute) + if !ok { + object = new(VersionedAttribute) + ok = queries.SetFromEmbeddedStruct(&object, &maybeVersionedAttribute) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeVersionedAttribute)) + } + } } else { - slice = *maybeVersionedAttribute.(*[]*VersionedAttribute) + s, ok := maybeVersionedAttribute.(*[]*VersionedAttribute) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeVersionedAttribute) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeVersionedAttribute)) + } + } } args := make([]interface{}, 0, 1) @@ -539,7 +555,7 @@ func (versionedAttributeL) LoadServer(ctx context.Context, e boil.ContextExecuto return errors.Wrap(err, "error occurred during iteration of eager loaded relations for servers") } - if len(versionedAttributeAfterSelectHooks) != 0 { + if len(serverAfterSelectHooks) != 0 { for _, obj := range resultSlice { if err := obj.doAfterSelectHooks(ctx, e); err != nil { return err @@ -584,9 +600,25 @@ func (versionedAttributeL) LoadServerComponent(ctx context.Context, e boil.Conte var object *VersionedAttribute if singular { - object = maybeVersionedAttribute.(*VersionedAttribute) + var ok bool + object, ok = maybeVersionedAttribute.(*VersionedAttribute) + if !ok { + object = new(VersionedAttribute) + ok = queries.SetFromEmbeddedStruct(&object, &maybeVersionedAttribute) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeVersionedAttribute)) + } + } } else { - slice = *maybeVersionedAttribute.(*[]*VersionedAttribute) + s, ok := maybeVersionedAttribute.(*[]*VersionedAttribute) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeVersionedAttribute) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeVersionedAttribute)) + } + } } args := make([]interface{}, 0, 1) @@ -647,7 +679,7 @@ func (versionedAttributeL) LoadServerComponent(ctx context.Context, e boil.Conte return errors.Wrap(err, "error occurred during iteration of eager loaded relations for server_components") } - if len(versionedAttributeAfterSelectHooks) != 0 { + if len(serverComponentAfterSelectHooks) != 0 { for _, obj := range resultSlice { if err := obj.doAfterSelectHooks(ctx, e); err != nil { return err @@ -1276,6 +1308,11 @@ func VersionedAttributeExists(ctx context.Context, exec boil.ContextExecutor, iD return exists, nil } +// Exists checks if the VersionedAttribute row exists. +func (o *VersionedAttribute) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return VersionedAttributeExists(ctx, exec, o.ID) +} + // 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 *VersionedAttribute) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { diff --git a/internal/models/versioned_attributes_test.go b/internal/models/versioned_attributes_test.go index b203ce8..4fc9abb 100644 --- a/internal/models/versioned_attributes_test.go +++ b/internal/models/versioned_attributes_test.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.15.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 @@ -576,6 +576,12 @@ func testVersionedAttributeToOneServerUsingServer(t *testing.T) { t.Errorf("want: %v, got %v", foreign.ID, check.ID) } + ranAfterSelectHook := false + AddServerHook(boil.AfterSelectHook, func(ctx context.Context, e boil.ContextExecutor, o *Server) error { + ranAfterSelectHook = true + return nil + }) + slice := VersionedAttributeSlice{&local} if err = local.L.LoadServer(ctx, tx, false, (*[]*VersionedAttribute)(&slice), nil); err != nil { t.Fatal(err) @@ -591,6 +597,10 @@ func testVersionedAttributeToOneServerUsingServer(t *testing.T) { if local.R.Server == nil { t.Error("struct should have been eager loaded") } + + if !ranAfterSelectHook { + t.Error("failed to run AfterSelect hook for relationship") + } } func testVersionedAttributeToOneServerComponentUsingServerComponent(t *testing.T) { @@ -627,6 +637,12 @@ func testVersionedAttributeToOneServerComponentUsingServerComponent(t *testing.T t.Errorf("want: %v, got %v", foreign.ID, check.ID) } + ranAfterSelectHook := false + AddServerComponentHook(boil.AfterSelectHook, func(ctx context.Context, e boil.ContextExecutor, o *ServerComponent) error { + ranAfterSelectHook = true + return nil + }) + slice := VersionedAttributeSlice{&local} if err = local.L.LoadServerComponent(ctx, tx, false, (*[]*VersionedAttribute)(&slice), nil); err != nil { t.Fatal(err) @@ -642,6 +658,10 @@ func testVersionedAttributeToOneServerComponentUsingServerComponent(t *testing.T if local.R.ServerComponent == nil { t.Error("struct should have been eager loaded") } + + if !ranAfterSelectHook { + t.Error("failed to run AfterSelect hook for relationship") + } } func testVersionedAttributeToOneSetOpServerUsingServer(t *testing.T) { diff --git a/pkg/api/v1/router_server.go b/pkg/api/v1/router_server.go index 7e1faa5..0a3bba1 100644 --- a/pkg/api/v1/router_server.go +++ b/pkg/api/v1/router_server.go @@ -126,7 +126,7 @@ func (r *Router) serverDelete(c *gin.Context) { return } - if _, err = dbSRV.Delete(c.Request.Context(), r.DB, false); err != nil { + if _, err = dbSRV.Delete(c.Request.Context(), boil.GetContextDB(), false); err != nil { dbErrorResponse(c, err) return } diff --git a/pkg/api/v1/router_server_components_test.go b/pkg/api/v1/router_server_components_test.go index 9ff092f..7b46fa1 100644 --- a/pkg/api/v1/router_server_components_test.go +++ b/pkg/api/v1/router_server_components_test.go @@ -289,15 +289,15 @@ func TestIntegrationServerGetComponents(t *testing.T) { got, ) - if gotc == nil { + if gotc != nil { + // zero variable values before comparison + gotc.UUID = uuid.Nil + zeroTimeValues(gotc) + + assert.Equal(t, tt.expectedInSlice, *gotc) + } else { t.Fatal("expected component, got nil") } - - // zero variable values before comparison - gotc.UUID = uuid.Nil - zeroTimeValues(gotc) - - assert.Equal(t, tt.expectedInSlice, *gotc) }) } }