diff --git a/.gitignore b/.gitignore index 4ae7a099..ba7202fd 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ .vscode _DS_Store .bin/ +vendor +confighub \ No newline at end of file diff --git a/cmd/analyze.go b/cmd/analyze.go index 09f241ec..9896f3c5 100644 --- a/cmd/analyze.go +++ b/cmd/analyze.go @@ -13,10 +13,13 @@ import ( var outputFile, outputFormat string +// Analyzers ... var Analyzers = []v1.Analyzer{ analyzers.PatchAnalyzer, aws.EC2InstanceAnalyzer, } + +// Analyze ... var Analyze = &cobra.Command{ Use: "analyze ", Short: "Analyze configuration items and report discrepencies/issues.", diff --git a/cmd/offline.go b/cmd/offline.go index f5ffc954..d29f096f 100644 --- a/cmd/offline.go +++ b/cmd/offline.go @@ -6,6 +6,7 @@ import ( "github.com/spf13/cobra" ) +// GoOffline ... var GoOffline = &cobra.Command{ Use: "go-offline", Long: "Download all dependencies so that confighub can work without an internet connection", diff --git a/cmd/root.go b/cmd/root.go index cab11d7b..c2be709c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -9,6 +9,7 @@ import ( "github.com/spf13/pflag" ) +// Root ... var Root = &cobra.Command{ Use: "confighub", PersistentPreRun: func(cmd *cobra.Command, args []string) { @@ -31,6 +32,7 @@ var ( date = "unknown" ) +// ServerFlags ... func ServerFlags(flags *pflag.FlagSet) { flags.IntVar(&httpPort, "httpPort", 8080, "Port to expose a health dashboard ") flags.IntVar(&devGuiPort, "devGuiPort", 3004, "Port used by a local npm server in development mode") diff --git a/cmd/run.go b/cmd/run.go index 734ce659..94a77517 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -8,6 +8,8 @@ import ( var outputDir string var filename string + +// Run ... var Run = &cobra.Command{ Use: "run ", Short: "Run scrapers and return", diff --git a/cmd/server.go b/cmd/server.go index f53e2755..3badd791 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -18,6 +18,7 @@ import ( "github.com/spf13/cobra" ) +// Serve ... var Serve = &cobra.Command{ Use: "serve", Run: func(cmd *cobra.Command, args []string) { @@ -29,7 +30,7 @@ var Serve = &cobra.Command{ return c.String(http.StatusOK, "Hello, World!") }) // PostgREST needs to know how it is exposed to create the correct links - db.HttpEndpoint = publicEndpoint + "/db" + db.HTTPEndpoint = publicEndpoint + "/db" go db.StartPostgrest() url, err := url.Parse("http://localhost:3000") diff --git a/db/ext.go b/db/ext.go index c5fd2b24..f9137262 100644 --- a/db/ext.go +++ b/db/ext.go @@ -7,6 +7,7 @@ import ( "github.com/flanksource/confighub/db/models" ) +// GetJSON ... func GetJSON(ci models.ConfigItem) []byte { data, err := json.Marshal(ci.Config) if err != nil { diff --git a/db/init.go b/db/init.go index 2314117a..9c6f3c34 100644 --- a/db/init.go +++ b/db/init.go @@ -5,6 +5,7 @@ import ( "database/sql" "embed" "os" + "time" "github.com/flanksource/commons/logger" "github.com/jackc/pgx/v4/log/logrusadapter" @@ -13,14 +14,20 @@ import ( "github.com/pressly/goose/v3" "github.com/sirupsen/logrus" "github.com/spf13/pflag" - "github.com/volatiletech/sqlboiler/v4/boil" + "gorm.io/driver/postgres" + "gorm.io/gorm" ) -var ConnectionString string -var Schema = "public" -var LogLevel = "info" -var HttpEndpoint = "http://localhost:8080/db" +// connection variables +var ( + ConnectionString string + Schema = "public" + LogLevel = "info" + HTTPEndpoint = "http://localhost:8080/db" + defaultDB *gorm.DB +) +// Flags ... func Flags(flags *pflag.FlagSet) { flags.StringVar(&ConnectionString, "db", "DB_URL", "Connection string for the postgres database") flags.StringVar(&Schema, "db-schema", "public", "") @@ -29,6 +36,8 @@ func Flags(flags *pflag.FlagSet) { //go:embed migrations/*.sql var embedMigrations embed.FS + +// Pool ... var Pool *pgxpool.Pool var pgxConnectionString string @@ -40,6 +49,7 @@ func readFromEnv(v string) string { return v } +// Init ... func Init(connection string) error { ConnectionString = readFromEnv(connection) Schema = readFromEnv(Schema) @@ -83,12 +93,27 @@ func Init(connection string) error { if err != nil { return err } - boil.SetDB(db) - logger.Infof("Initialized DB: %s", boil.GetDB()) + + gormDB, err := gorm.Open(postgres.New(postgres.Config{ + Conn: db, + }), &gorm.Config{ + NowFunc: func() time.Time { + return time.Now().UTC() + }, + }) + + if err != nil { + return err + } + + defaultDB = gormDB + + logger.Infof("Initialized DB: %s", defaultDB) return nil } +// Migrate ... func Migrate() error { goose.SetBaseFS(embedMigrations) db, err := GetDB() @@ -103,6 +128,18 @@ func Migrate() error { return nil } +// GetDB ... func GetDB() (*sql.DB, error) { return sql.Open("pgx", pgxConnectionString) } + +// Ping pings the database for health check +func Ping() error { + d, _ := defaultDB.DB() // returns *sql.DB + return d.Ping() +} + +// DefaultDB returns the default database connection instance +func DefaultDB() *gorm.DB { + return defaultDB +} diff --git a/db/models/boil_queries.go b/db/models/boil_queries.go deleted file mode 100644 index ff2104dc..00000000 --- a/db/models/boil_queries.go +++ /dev/null @@ -1,33 +0,0 @@ -// Code generated by SQLBoiler 4.8.3 (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 ( - "github.com/volatiletech/sqlboiler/v4/drivers" - "github.com/volatiletech/sqlboiler/v4/queries" - "github.com/volatiletech/sqlboiler/v4/queries/qm" -) - -var dialect = drivers.Dialect{ - LQ: 0x22, - RQ: 0x22, - - UseIndexPlaceholders: true, - UseLastInsertID: false, - UseSchema: false, - UseDefaultKeyword: true, - UseAutoColumns: false, - UseTopClause: false, - UseOutputClause: false, - UseCaseWhenExistsClause: false, -} - -// NewQuery initializes a new Query using the passed in QueryMods -func NewQuery(mods ...qm.QueryMod) *queries.Query { - q := &queries.Query{} - queries.SetDialect(q, &dialect) - qm.Apply(q, mods...) - - return q -} diff --git a/db/models/boil_table_names.go b/db/models/boil_table_names.go deleted file mode 100644 index 095ca5e0..00000000 --- a/db/models/boil_table_names.go +++ /dev/null @@ -1,16 +0,0 @@ -// Code generated by SQLBoiler 4.8.3 (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 - -var TableNames = struct { - ConfigAnalysis string - ConfigChange string - ConfigItem string - ConfigScraper string -}{ - ConfigAnalysis: "config_analysis", - ConfigChange: "config_change", - ConfigItem: "config_item", - ConfigScraper: "config_scraper", -} diff --git a/db/models/boil_types.go b/db/models/boil_types.go deleted file mode 100644 index a55f017a..00000000 --- a/db/models/boil_types.go +++ /dev/null @@ -1,52 +0,0 @@ -// Code generated by SQLBoiler 4.8.3 (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 ( - "strconv" - - "github.com/friendsofgo/errors" - "github.com/volatiletech/sqlboiler/v4/boil" - "github.com/volatiletech/strmangle" -) - -// M type is for providing columns and column values to UpdateAll. -type M map[string]interface{} - -// ErrSyncFail occurs during insert when the record could not be retrieved in -// order to populate default value information. This usually happens when LastInsertId -// fails or there was a primary key configuration that was not resolvable. -var ErrSyncFail = errors.New("models: failed to synchronize data after insert") - -type insertCache struct { - query string - retQuery string - valueMapping []uint64 - retMapping []uint64 -} - -type updateCache struct { - query string - valueMapping []uint64 -} - -func makeCacheKey(cols boil.Columns, nzDefaults []string) string { - buf := strmangle.GetBuffer() - - buf.WriteString(strconv.Itoa(cols.Kind)) - for _, w := range cols.Cols { - buf.WriteString(w) - } - - if len(nzDefaults) != 0 { - buf.WriteByte('.') - } - for _, nz := range nzDefaults { - buf.WriteString(nz) - } - - str := buf.String() - strmangle.PutBuffer(buf) - return str -} diff --git a/db/models/config_analysis.go b/db/models/config_analysis.go deleted file mode 100644 index 7e18d44c..00000000 --- a/db/models/config_analysis.go +++ /dev/null @@ -1,1261 +0,0 @@ -// Code generated by SQLBoiler 4.8.3 (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 ( - "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" -) - -// ConfigAnalysis is an object representing the database table. -type ConfigAnalysis struct { - ID string `boil:"id" json:"id" toml:"id" yaml:"id"` - ConfigID string `boil:"config_id" json:"config_id" toml:"config_id" yaml:"config_id"` - Analyzer string `boil:"analyzer" json:"analyzer" toml:"analyzer" yaml:"analyzer"` - Summary null.String `boil:"summary" json:"summary,omitempty" toml:"summary" yaml:"summary,omitempty"` - AnalysisType string `boil:"analysis_type" json:"analysis_type" toml:"analysis_type" yaml:"analysis_type"` - Analysis null.JSON `boil:"analysis" json:"analysis,omitempty" toml:"analysis" yaml:"analysis,omitempty"` - FirstObserved time.Time `boil:"first_observed" json:"first_observed" toml:"first_observed" yaml:"first_observed"` - LastObserved null.Time `boil:"last_observed" json:"last_observed,omitempty" toml:"last_observed" yaml:"last_observed,omitempty"` - - R *configAnalysisR `boil:"-" json:"-" toml:"-" yaml:"-"` - L configAnalysisL `boil:"-" json:"-" toml:"-" yaml:"-"` -} - -var ConfigAnalysisColumns = struct { - ID string - ConfigID string - Analyzer string - Summary string - AnalysisType string - Analysis string - FirstObserved string - LastObserved string -}{ - ID: "id", - ConfigID: "config_id", - Analyzer: "analyzer", - Summary: "summary", - AnalysisType: "analysis_type", - Analysis: "analysis", - FirstObserved: "first_observed", - LastObserved: "last_observed", -} - -var ConfigAnalysisTableColumns = struct { - ID string - ConfigID string - Analyzer string - Summary string - AnalysisType string - Analysis string - FirstObserved string - LastObserved string -}{ - ID: "config_analysis.id", - ConfigID: "config_analysis.config_id", - Analyzer: "config_analysis.analyzer", - Summary: "config_analysis.summary", - AnalysisType: "config_analysis.analysis_type", - Analysis: "config_analysis.analysis", - FirstObserved: "config_analysis.first_observed", - LastObserved: "config_analysis.last_observed", -} - -// Generated where - -type whereHelperstring struct{ field string } - -func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } -func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } -func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } -func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } -func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } -func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } -func (w whereHelperstring) IN(slice []string) qm.QueryMod { - values := make([]interface{}, 0, len(slice)) - for _, value := range slice { - values = append(values, value) - } - return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...) -} -func (w whereHelperstring) NIN(slice []string) qm.QueryMod { - values := make([]interface{}, 0, len(slice)) - for _, value := range slice { - values = append(values, value) - } - return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...) -} - -type whereHelpernull_String struct{ field string } - -func (w whereHelpernull_String) EQ(x null.String) qm.QueryMod { - return qmhelper.WhereNullEQ(w.field, false, x) -} -func (w whereHelpernull_String) NEQ(x null.String) qm.QueryMod { - return qmhelper.WhereNullEQ(w.field, true, x) -} -func (w whereHelpernull_String) LT(x null.String) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.LT, x) -} -func (w whereHelpernull_String) LTE(x null.String) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.LTE, x) -} -func (w whereHelpernull_String) GT(x null.String) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.GT, x) -} -func (w whereHelpernull_String) GTE(x null.String) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.GTE, x) -} - -func (w whereHelpernull_String) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_String) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } - -type whereHelpernull_JSON struct{ field string } - -func (w whereHelpernull_JSON) EQ(x null.JSON) qm.QueryMod { - return qmhelper.WhereNullEQ(w.field, false, x) -} -func (w whereHelpernull_JSON) NEQ(x null.JSON) qm.QueryMod { - return qmhelper.WhereNullEQ(w.field, true, x) -} -func (w whereHelpernull_JSON) LT(x null.JSON) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.LT, x) -} -func (w whereHelpernull_JSON) LTE(x null.JSON) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.LTE, x) -} -func (w whereHelpernull_JSON) GT(x null.JSON) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.GT, x) -} -func (w whereHelpernull_JSON) GTE(x null.JSON) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.GTE, x) -} - -func (w whereHelpernull_JSON) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_JSON) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } - -type whereHelpertime_Time struct{ field string } - -func (w whereHelpertime_Time) EQ(x time.Time) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.EQ, x) -} -func (w whereHelpertime_Time) NEQ(x time.Time) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.NEQ, x) -} -func (w whereHelpertime_Time) LT(x time.Time) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.LT, x) -} -func (w whereHelpertime_Time) LTE(x time.Time) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.LTE, x) -} -func (w whereHelpertime_Time) GT(x time.Time) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.GT, x) -} -func (w whereHelpertime_Time) GTE(x time.Time) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.GTE, x) -} - -type whereHelpernull_Time struct{ field string } - -func (w whereHelpernull_Time) EQ(x null.Time) qm.QueryMod { - return qmhelper.WhereNullEQ(w.field, false, x) -} -func (w whereHelpernull_Time) NEQ(x null.Time) qm.QueryMod { - return qmhelper.WhereNullEQ(w.field, true, x) -} -func (w whereHelpernull_Time) LT(x null.Time) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.LT, x) -} -func (w whereHelpernull_Time) LTE(x null.Time) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.LTE, x) -} -func (w whereHelpernull_Time) GT(x null.Time) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.GT, x) -} -func (w whereHelpernull_Time) GTE(x null.Time) qm.QueryMod { - return qmhelper.Where(w.field, qmhelper.GTE, x) -} - -func (w whereHelpernull_Time) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } -func (w whereHelpernull_Time) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } - -var ConfigAnalysisWhere = struct { - ID whereHelperstring - ConfigID whereHelperstring - Analyzer whereHelperstring - Summary whereHelpernull_String - AnalysisType whereHelperstring - Analysis whereHelpernull_JSON - FirstObserved whereHelpertime_Time - LastObserved whereHelpernull_Time -}{ - ID: whereHelperstring{field: "\"config_analysis\".\"id\""}, - ConfigID: whereHelperstring{field: "\"config_analysis\".\"config_id\""}, - Analyzer: whereHelperstring{field: "\"config_analysis\".\"analyzer\""}, - Summary: whereHelpernull_String{field: "\"config_analysis\".\"summary\""}, - AnalysisType: whereHelperstring{field: "\"config_analysis\".\"analysis_type\""}, - Analysis: whereHelpernull_JSON{field: "\"config_analysis\".\"analysis\""}, - FirstObserved: whereHelpertime_Time{field: "\"config_analysis\".\"first_observed\""}, - LastObserved: whereHelpernull_Time{field: "\"config_analysis\".\"last_observed\""}, -} - -// ConfigAnalysisRels is where relationship names are stored. -var ConfigAnalysisRels = struct { - Config string -}{ - Config: "Config", -} - -// configAnalysisR is where relationships are stored. -type configAnalysisR struct { - Config *ConfigItem `boil:"Config" json:"Config" toml:"Config" yaml:"Config"` -} - -// NewStruct creates a new relationship struct -func (*configAnalysisR) NewStruct() *configAnalysisR { - return &configAnalysisR{} -} - -// configAnalysisL is where Load methods for each relationship are stored. -type configAnalysisL struct{} - -var ( - configAnalysisAllColumns = []string{"id", "config_id", "analyzer", "summary", "analysis_type", "analysis", "first_observed", "last_observed"} - configAnalysisColumnsWithoutDefault = []string{"config_id", "analyzer", "summary", "analysis_type", "analysis", "last_observed"} - configAnalysisColumnsWithDefault = []string{"id", "first_observed"} - configAnalysisPrimaryKeyColumns = []string{"id"} -) - -type ( - // ConfigAnalysisSlice is an alias for a slice of pointers to ConfigAnalysis. - // This should almost always be used instead of []ConfigAnalysis. - ConfigAnalysisSlice []*ConfigAnalysis - // ConfigAnalysisHook is the signature for custom ConfigAnalysis hook methods - ConfigAnalysisHook func(boil.Executor, *ConfigAnalysis) error - - configAnalysisQuery struct { - *queries.Query - } -) - -// Cache for insert, update and upsert -var ( - configAnalysisType = reflect.TypeOf(&ConfigAnalysis{}) - configAnalysisMapping = queries.MakeStructMapping(configAnalysisType) - configAnalysisPrimaryKeyMapping, _ = queries.BindMapping(configAnalysisType, configAnalysisMapping, configAnalysisPrimaryKeyColumns) - configAnalysisInsertCacheMut sync.RWMutex - configAnalysisInsertCache = make(map[string]insertCache) - configAnalysisUpdateCacheMut sync.RWMutex - configAnalysisUpdateCache = make(map[string]updateCache) - configAnalysisUpsertCacheMut sync.RWMutex - configAnalysisUpsertCache = 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 configAnalysisBeforeInsertHooks []ConfigAnalysisHook -var configAnalysisBeforeUpdateHooks []ConfigAnalysisHook -var configAnalysisBeforeDeleteHooks []ConfigAnalysisHook -var configAnalysisBeforeUpsertHooks []ConfigAnalysisHook - -var configAnalysisAfterInsertHooks []ConfigAnalysisHook -var configAnalysisAfterSelectHooks []ConfigAnalysisHook -var configAnalysisAfterUpdateHooks []ConfigAnalysisHook -var configAnalysisAfterDeleteHooks []ConfigAnalysisHook -var configAnalysisAfterUpsertHooks []ConfigAnalysisHook - -// doBeforeInsertHooks executes all "before insert" hooks. -func (o *ConfigAnalysis) doBeforeInsertHooks(exec boil.Executor) (err error) { - for _, hook := range configAnalysisBeforeInsertHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doBeforeUpdateHooks executes all "before Update" hooks. -func (o *ConfigAnalysis) doBeforeUpdateHooks(exec boil.Executor) (err error) { - for _, hook := range configAnalysisBeforeUpdateHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doBeforeDeleteHooks executes all "before Delete" hooks. -func (o *ConfigAnalysis) doBeforeDeleteHooks(exec boil.Executor) (err error) { - for _, hook := range configAnalysisBeforeDeleteHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doBeforeUpsertHooks executes all "before Upsert" hooks. -func (o *ConfigAnalysis) doBeforeUpsertHooks(exec boil.Executor) (err error) { - for _, hook := range configAnalysisBeforeUpsertHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doAfterInsertHooks executes all "after Insert" hooks. -func (o *ConfigAnalysis) doAfterInsertHooks(exec boil.Executor) (err error) { - for _, hook := range configAnalysisAfterInsertHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doAfterSelectHooks executes all "after Select" hooks. -func (o *ConfigAnalysis) doAfterSelectHooks(exec boil.Executor) (err error) { - for _, hook := range configAnalysisAfterSelectHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doAfterUpdateHooks executes all "after Update" hooks. -func (o *ConfigAnalysis) doAfterUpdateHooks(exec boil.Executor) (err error) { - for _, hook := range configAnalysisAfterUpdateHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doAfterDeleteHooks executes all "after Delete" hooks. -func (o *ConfigAnalysis) doAfterDeleteHooks(exec boil.Executor) (err error) { - for _, hook := range configAnalysisAfterDeleteHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doAfterUpsertHooks executes all "after Upsert" hooks. -func (o *ConfigAnalysis) doAfterUpsertHooks(exec boil.Executor) (err error) { - for _, hook := range configAnalysisAfterUpsertHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// AddConfigAnalysisHook registers your hook function for all future operations. -func AddConfigAnalysisHook(hookPoint boil.HookPoint, configAnalysisHook ConfigAnalysisHook) { - switch hookPoint { - case boil.BeforeInsertHook: - configAnalysisBeforeInsertHooks = append(configAnalysisBeforeInsertHooks, configAnalysisHook) - case boil.BeforeUpdateHook: - configAnalysisBeforeUpdateHooks = append(configAnalysisBeforeUpdateHooks, configAnalysisHook) - case boil.BeforeDeleteHook: - configAnalysisBeforeDeleteHooks = append(configAnalysisBeforeDeleteHooks, configAnalysisHook) - case boil.BeforeUpsertHook: - configAnalysisBeforeUpsertHooks = append(configAnalysisBeforeUpsertHooks, configAnalysisHook) - case boil.AfterInsertHook: - configAnalysisAfterInsertHooks = append(configAnalysisAfterInsertHooks, configAnalysisHook) - case boil.AfterSelectHook: - configAnalysisAfterSelectHooks = append(configAnalysisAfterSelectHooks, configAnalysisHook) - case boil.AfterUpdateHook: - configAnalysisAfterUpdateHooks = append(configAnalysisAfterUpdateHooks, configAnalysisHook) - case boil.AfterDeleteHook: - configAnalysisAfterDeleteHooks = append(configAnalysisAfterDeleteHooks, configAnalysisHook) - case boil.AfterUpsertHook: - configAnalysisAfterUpsertHooks = append(configAnalysisAfterUpsertHooks, configAnalysisHook) - } -} - -// OneG returns a single configAnalysis record from the query using the global executor. -func (q configAnalysisQuery) OneG() (*ConfigAnalysis, error) { - return q.One(boil.GetDB()) -} - -// One returns a single configAnalysis record from the query. -func (q configAnalysisQuery) One(exec boil.Executor) (*ConfigAnalysis, error) { - o := &ConfigAnalysis{} - - queries.SetLimit(q.Query, 1) - - err := q.Bind(nil, exec, o) - if err != nil { - if errors.Cause(err) == sql.ErrNoRows { - return nil, sql.ErrNoRows - } - return nil, errors.Wrap(err, "models: failed to execute a one query for config_analysis") - } - - if err := o.doAfterSelectHooks(exec); err != nil { - return o, err - } - - return o, nil -} - -// AllG returns all ConfigAnalysis records from the query using the global executor. -func (q configAnalysisQuery) AllG() (ConfigAnalysisSlice, error) { - return q.All(boil.GetDB()) -} - -// All returns all ConfigAnalysis records from the query. -func (q configAnalysisQuery) All(exec boil.Executor) (ConfigAnalysisSlice, error) { - var o []*ConfigAnalysis - - err := q.Bind(nil, exec, &o) - if err != nil { - return nil, errors.Wrap(err, "models: failed to assign all query results to ConfigAnalysis slice") - } - - if len(configAnalysisAfterSelectHooks) != 0 { - for _, obj := range o { - if err := obj.doAfterSelectHooks(exec); err != nil { - return o, err - } - } - } - - return o, nil -} - -// CountG returns the count of all ConfigAnalysis records in the query, and panics on error. -func (q configAnalysisQuery) CountG() (int64, error) { - return q.Count(boil.GetDB()) -} - -// Count returns the count of all ConfigAnalysis records in the query. -func (q configAnalysisQuery) Count(exec boil.Executor) (int64, error) { - var count int64 - - queries.SetSelect(q.Query, nil) - queries.SetCount(q.Query) - - err := q.Query.QueryRow(exec).Scan(&count) - if err != nil { - return 0, errors.Wrap(err, "models: failed to count config_analysis rows") - } - - return count, nil -} - -// ExistsG checks if the row exists in the table, and panics on error. -func (q configAnalysisQuery) ExistsG() (bool, error) { - return q.Exists(boil.GetDB()) -} - -// Exists checks if the row exists in the table. -func (q configAnalysisQuery) Exists(exec boil.Executor) (bool, error) { - var count int64 - - queries.SetSelect(q.Query, nil) - queries.SetCount(q.Query) - queries.SetLimit(q.Query, 1) - - err := q.Query.QueryRow(exec).Scan(&count) - if err != nil { - return false, errors.Wrap(err, "models: failed to check if config_analysis exists") - } - - return count > 0, nil -} - -// Config pointed to by the foreign key. -func (o *ConfigAnalysis) Config(mods ...qm.QueryMod) configItemQuery { - queryMods := []qm.QueryMod{ - qm.Where("\"id\" = ?", o.ConfigID), - } - - queryMods = append(queryMods, mods...) - - query := ConfigItems(queryMods...) - queries.SetFrom(query.Query, "\"config_item\"") - - return query -} - -// LoadConfig allows an eager lookup of values, cached into the -// loaded structs of the objects. This is for an N-1 relationship. -func (configAnalysisL) LoadConfig(e boil.Executor, singular bool, maybeConfigAnalysis interface{}, mods queries.Applicator) error { - var slice []*ConfigAnalysis - var object *ConfigAnalysis - - if singular { - object = maybeConfigAnalysis.(*ConfigAnalysis) - } else { - slice = *maybeConfigAnalysis.(*[]*ConfigAnalysis) - } - - args := make([]interface{}, 0, 1) - if singular { - if object.R == nil { - object.R = &configAnalysisR{} - } - args = append(args, object.ConfigID) - - } else { - Outer: - for _, obj := range slice { - if obj.R == nil { - obj.R = &configAnalysisR{} - } - - for _, a := range args { - if a == obj.ConfigID { - continue Outer - } - } - - args = append(args, obj.ConfigID) - - } - } - - if len(args) == 0 { - return nil - } - - query := NewQuery( - qm.From(`config_item`), - qm.WhereIn(`config_item.id in ?`, args...), - ) - if mods != nil { - mods.Apply(query) - } - - results, err := query.Query(e) - if err != nil { - return errors.Wrap(err, "failed to eager load ConfigItem") - } - - var resultSlice []*ConfigItem - if err = queries.Bind(results, &resultSlice); err != nil { - return errors.Wrap(err, "failed to bind eager loaded slice ConfigItem") - } - - if err = results.Close(); err != nil { - return errors.Wrap(err, "failed to close results of eager load for config_item") - } - if err = results.Err(); err != nil { - return errors.Wrap(err, "error occurred during iteration of eager loaded relations for config_item") - } - - if len(configAnalysisAfterSelectHooks) != 0 { - for _, obj := range resultSlice { - if err := obj.doAfterSelectHooks(e); err != nil { - return err - } - } - } - - if len(resultSlice) == 0 { - return nil - } - - if singular { - foreign := resultSlice[0] - object.R.Config = foreign - if foreign.R == nil { - foreign.R = &configItemR{} - } - foreign.R.ConfigConfigAnalyses = append(foreign.R.ConfigConfigAnalyses, object) - return nil - } - - for _, local := range slice { - for _, foreign := range resultSlice { - if local.ConfigID == foreign.ID { - local.R.Config = foreign - if foreign.R == nil { - foreign.R = &configItemR{} - } - foreign.R.ConfigConfigAnalyses = append(foreign.R.ConfigConfigAnalyses, local) - break - } - } - } - - return nil -} - -// SetConfigG of the configAnalysis to the related item. -// Sets o.R.Config to related. -// Adds o to related.R.ConfigConfigAnalyses. -// Uses the global database handle. -func (o *ConfigAnalysis) SetConfigG(insert bool, related *ConfigItem) error { - return o.SetConfig(boil.GetDB(), insert, related) -} - -// SetConfig of the configAnalysis to the related item. -// Sets o.R.Config to related. -// Adds o to related.R.ConfigConfigAnalyses. -func (o *ConfigAnalysis) SetConfig(exec boil.Executor, insert bool, related *ConfigItem) error { - var err error - if insert { - if err = related.Insert(exec, boil.Infer()); err != nil { - return errors.Wrap(err, "failed to insert into foreign table") - } - } - - updateQuery := fmt.Sprintf( - "UPDATE \"config_analysis\" SET %s WHERE %s", - strmangle.SetParamNames("\"", "\"", 1, []string{"config_id"}), - strmangle.WhereClause("\"", "\"", 2, configAnalysisPrimaryKeyColumns), - ) - values := []interface{}{related.ID, o.ID} - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) - } - if _, err = exec.Exec(updateQuery, values...); err != nil { - return errors.Wrap(err, "failed to update local table") - } - - o.ConfigID = related.ID - if o.R == nil { - o.R = &configAnalysisR{ - Config: related, - } - } else { - o.R.Config = related - } - - if related.R == nil { - related.R = &configItemR{ - ConfigConfigAnalyses: ConfigAnalysisSlice{o}, - } - } else { - related.R.ConfigConfigAnalyses = append(related.R.ConfigConfigAnalyses, o) - } - - return nil -} - -// ConfigAnalyses retrieves all the records using an executor. -func ConfigAnalyses(mods ...qm.QueryMod) configAnalysisQuery { - mods = append(mods, qm.From("\"config_analysis\"")) - return configAnalysisQuery{NewQuery(mods...)} -} - -// FindConfigAnalysisG retrieves a single record by ID. -func FindConfigAnalysisG(iD string, selectCols ...string) (*ConfigAnalysis, error) { - return FindConfigAnalysis(boil.GetDB(), iD, selectCols...) -} - -// FindConfigAnalysis retrieves a single record by ID with an executor. -// If selectCols is empty Find will return all columns. -func FindConfigAnalysis(exec boil.Executor, iD string, selectCols ...string) (*ConfigAnalysis, error) { - configAnalysisObj := &ConfigAnalysis{} - - sel := "*" - if len(selectCols) > 0 { - sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",") - } - query := fmt.Sprintf( - "select %s from \"config_analysis\" where \"id\"=$1", sel, - ) - - q := queries.Raw(query, iD) - - err := q.Bind(nil, exec, configAnalysisObj) - if err != nil { - if errors.Cause(err) == sql.ErrNoRows { - return nil, sql.ErrNoRows - } - return nil, errors.Wrap(err, "models: unable to select from config_analysis") - } - - if err = configAnalysisObj.doAfterSelectHooks(exec); err != nil { - return configAnalysisObj, err - } - - return configAnalysisObj, nil -} - -// InsertG a single record. See Insert for whitelist behavior description. -func (o *ConfigAnalysis) InsertG(columns boil.Columns) error { - return o.Insert(boil.GetDB(), columns) -} - -// Insert a single record using an executor. -// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts. -func (o *ConfigAnalysis) Insert(exec boil.Executor, columns boil.Columns) error { - if o == nil { - return errors.New("models: no config_analysis provided for insertion") - } - - var err error - - if err := o.doBeforeInsertHooks(exec); err != nil { - return err - } - - nzDefaults := queries.NonZeroDefaultSet(configAnalysisColumnsWithDefault, o) - - key := makeCacheKey(columns, nzDefaults) - configAnalysisInsertCacheMut.RLock() - cache, cached := configAnalysisInsertCache[key] - configAnalysisInsertCacheMut.RUnlock() - - if !cached { - wl, returnColumns := columns.InsertColumnSet( - configAnalysisAllColumns, - configAnalysisColumnsWithDefault, - configAnalysisColumnsWithoutDefault, - nzDefaults, - ) - - cache.valueMapping, err = queries.BindMapping(configAnalysisType, configAnalysisMapping, wl) - if err != nil { - return err - } - cache.retMapping, err = queries.BindMapping(configAnalysisType, configAnalysisMapping, returnColumns) - if err != nil { - return err - } - if len(wl) != 0 { - cache.query = fmt.Sprintf("INSERT INTO \"config_analysis\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1)) - } else { - cache.query = "INSERT INTO \"config_analysis\" %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.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) - } - - if len(cache.retMapping) != 0 { - err = exec.QueryRow(cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...) - } else { - _, err = exec.Exec(cache.query, vals...) - } - - if err != nil { - return errors.Wrap(err, "models: unable to insert into config_analysis") - } - - if !cached { - configAnalysisInsertCacheMut.Lock() - configAnalysisInsertCache[key] = cache - configAnalysisInsertCacheMut.Unlock() - } - - return o.doAfterInsertHooks(exec) -} - -// UpdateG a single ConfigAnalysis record using the global executor. -// See Update for more documentation. -func (o *ConfigAnalysis) UpdateG(columns boil.Columns) (int64, error) { - return o.Update(boil.GetDB(), columns) -} - -// Update uses an executor to update the ConfigAnalysis. -// 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 *ConfigAnalysis) Update(exec boil.Executor, columns boil.Columns) (int64, error) { - var err error - if err = o.doBeforeUpdateHooks(exec); err != nil { - return 0, err - } - key := makeCacheKey(columns, nil) - configAnalysisUpdateCacheMut.RLock() - cache, cached := configAnalysisUpdateCache[key] - configAnalysisUpdateCacheMut.RUnlock() - - if !cached { - wl := columns.UpdateColumnSet( - configAnalysisAllColumns, - configAnalysisPrimaryKeyColumns, - ) - - if !columns.IsWhitelist() { - wl = strmangle.SetComplement(wl, []string{"created_at"}) - } - if len(wl) == 0 { - return 0, errors.New("models: unable to update config_analysis, could not build whitelist") - } - - cache.query = fmt.Sprintf("UPDATE \"config_analysis\" SET %s WHERE %s", - strmangle.SetParamNames("\"", "\"", 1, wl), - strmangle.WhereClause("\"", "\"", len(wl)+1, configAnalysisPrimaryKeyColumns), - ) - cache.valueMapping, err = queries.BindMapping(configAnalysisType, configAnalysisMapping, append(wl, configAnalysisPrimaryKeyColumns...)) - if err != nil { - return 0, err - } - } - - values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) - } - var result sql.Result - result, err = exec.Exec(cache.query, values...) - if err != nil { - return 0, errors.Wrap(err, "models: unable to update config_analysis row") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: failed to get rows affected by update for config_analysis") - } - - if !cached { - configAnalysisUpdateCacheMut.Lock() - configAnalysisUpdateCache[key] = cache - configAnalysisUpdateCacheMut.Unlock() - } - - return rowsAff, o.doAfterUpdateHooks(exec) -} - -// UpdateAllG updates all rows with the specified column values. -func (q configAnalysisQuery) UpdateAllG(cols M) (int64, error) { - return q.UpdateAll(boil.GetDB(), cols) -} - -// UpdateAll updates all rows with the specified column values. -func (q configAnalysisQuery) UpdateAll(exec boil.Executor, cols M) (int64, error) { - queries.SetUpdate(q.Query, cols) - - result, err := q.Query.Exec(exec) - if err != nil { - return 0, errors.Wrap(err, "models: unable to update all for config_analysis") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: unable to retrieve rows affected for config_analysis") - } - - return rowsAff, nil -} - -// UpdateAllG updates all rows with the specified column values. -func (o ConfigAnalysisSlice) UpdateAllG(cols M) (int64, error) { - return o.UpdateAll(boil.GetDB(), cols) -} - -// UpdateAll updates all rows with the specified column values, using an executor. -func (o ConfigAnalysisSlice) UpdateAll(exec boil.Executor, 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)), configAnalysisPrimaryKeyMapping) - args = append(args, pkeyArgs...) - } - - sql := fmt.Sprintf("UPDATE \"config_analysis\" SET %s WHERE %s", - strmangle.SetParamNames("\"", "\"", 1, colNames), - strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, configAnalysisPrimaryKeyColumns, len(o))) - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) - } - result, err := exec.Exec(sql, args...) - if err != nil { - return 0, errors.Wrap(err, "models: unable to update all in configAnalysis slice") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all configAnalysis") - } - return rowsAff, nil -} - -// UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *ConfigAnalysis) UpsertG(updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(boil.GetDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) -} - -// 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 *ConfigAnalysis) Upsert(exec boil.Executor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - if o == nil { - return errors.New("models: no config_analysis provided for upsert") - } - - if err := o.doBeforeUpsertHooks(exec); err != nil { - return err - } - - nzDefaults := queries.NonZeroDefaultSet(configAnalysisColumnsWithDefault, 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) - - configAnalysisUpsertCacheMut.RLock() - cache, cached := configAnalysisUpsertCache[key] - configAnalysisUpsertCacheMut.RUnlock() - - var err error - - if !cached { - insert, ret := insertColumns.InsertColumnSet( - configAnalysisAllColumns, - configAnalysisColumnsWithDefault, - configAnalysisColumnsWithoutDefault, - nzDefaults, - ) - update := updateColumns.UpdateColumnSet( - configAnalysisAllColumns, - configAnalysisPrimaryKeyColumns, - ) - - if updateOnConflict && len(update) == 0 { - return errors.New("models: unable to upsert config_analysis, could not build update column list") - } - - conflict := conflictColumns - if len(conflict) == 0 { - conflict = make([]string, len(configAnalysisPrimaryKeyColumns)) - copy(conflict, configAnalysisPrimaryKeyColumns) - } - cache.query = buildUpsertQueryPostgres(dialect, "\"config_analysis\"", updateOnConflict, ret, update, conflict, insert) - - cache.valueMapping, err = queries.BindMapping(configAnalysisType, configAnalysisMapping, insert) - if err != nil { - return err - } - if len(ret) != 0 { - cache.retMapping, err = queries.BindMapping(configAnalysisType, configAnalysisMapping, 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.QueryRow(cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { - err = nil // Postgres doesn't return anything when there's no update - } - } else { - _, err = exec.Exec(cache.query, vals...) - } - if err != nil { - return errors.Wrap(err, "models: unable to upsert config_analysis") - } - - if !cached { - configAnalysisUpsertCacheMut.Lock() - configAnalysisUpsertCache[key] = cache - configAnalysisUpsertCacheMut.Unlock() - } - - return o.doAfterUpsertHooks(exec) -} - -// DeleteG deletes a single ConfigAnalysis record. -// DeleteG will match against the primary key column to find the record to delete. -func (o *ConfigAnalysis) DeleteG() (int64, error) { - return o.Delete(boil.GetDB()) -} - -// Delete deletes a single ConfigAnalysis record with an executor. -// Delete will match against the primary key column to find the record to delete. -func (o *ConfigAnalysis) Delete(exec boil.Executor) (int64, error) { - if o == nil { - return 0, errors.New("models: no ConfigAnalysis provided for delete") - } - - if err := o.doBeforeDeleteHooks(exec); err != nil { - return 0, err - } - - args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), configAnalysisPrimaryKeyMapping) - sql := "DELETE FROM \"config_analysis\" WHERE \"id\"=$1" - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) - } - result, err := exec.Exec(sql, args...) - if err != nil { - return 0, errors.Wrap(err, "models: unable to delete from config_analysis") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: failed to get rows affected by delete for config_analysis") - } - - if err := o.doAfterDeleteHooks(exec); err != nil { - return 0, err - } - - return rowsAff, nil -} - -func (q configAnalysisQuery) DeleteAllG() (int64, error) { - return q.DeleteAll(boil.GetDB()) -} - -// DeleteAll deletes all matching rows. -func (q configAnalysisQuery) DeleteAll(exec boil.Executor) (int64, error) { - if q.Query == nil { - return 0, errors.New("models: no configAnalysisQuery provided for delete all") - } - - queries.SetDelete(q.Query) - - result, err := q.Query.Exec(exec) - if err != nil { - return 0, errors.Wrap(err, "models: unable to delete all from config_analysis") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for config_analysis") - } - - return rowsAff, nil -} - -// DeleteAllG deletes all rows in the slice. -func (o ConfigAnalysisSlice) DeleteAllG() (int64, error) { - return o.DeleteAll(boil.GetDB()) -} - -// DeleteAll deletes all rows in the slice, using an executor. -func (o ConfigAnalysisSlice) DeleteAll(exec boil.Executor) (int64, error) { - if len(o) == 0 { - return 0, nil - } - - if len(configAnalysisBeforeDeleteHooks) != 0 { - for _, obj := range o { - if err := obj.doBeforeDeleteHooks(exec); err != nil { - return 0, err - } - } - } - - var args []interface{} - for _, obj := range o { - pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), configAnalysisPrimaryKeyMapping) - args = append(args, pkeyArgs...) - } - - sql := "DELETE FROM \"config_analysis\" WHERE " + - strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, configAnalysisPrimaryKeyColumns, len(o)) - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) - } - result, err := exec.Exec(sql, args...) - if err != nil { - return 0, errors.Wrap(err, "models: unable to delete all from configAnalysis slice") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for config_analysis") - } - - if len(configAnalysisAfterDeleteHooks) != 0 { - for _, obj := range o { - if err := obj.doAfterDeleteHooks(exec); err != nil { - return 0, err - } - } - } - - return rowsAff, nil -} - -// ReloadG refetches the object from the database using the primary keys. -func (o *ConfigAnalysis) ReloadG() error { - if o == nil { - return errors.New("models: no ConfigAnalysis provided for reload") - } - - return o.Reload(boil.GetDB()) -} - -// Reload refetches the object from the database -// using the primary keys with an executor. -func (o *ConfigAnalysis) Reload(exec boil.Executor) error { - ret, err := FindConfigAnalysis(exec, o.ID) - if err != nil { - return err - } - - *o = *ret - return nil -} - -// ReloadAllG refetches every row with matching primary key column values -// and overwrites the original object slice with the newly updated slice. -func (o *ConfigAnalysisSlice) ReloadAllG() error { - if o == nil { - return errors.New("models: empty ConfigAnalysisSlice provided for reload all") - } - - return o.ReloadAll(boil.GetDB()) -} - -// ReloadAll refetches every row with matching primary key column values -// and overwrites the original object slice with the newly updated slice. -func (o *ConfigAnalysisSlice) ReloadAll(exec boil.Executor) error { - if o == nil || len(*o) == 0 { - return nil - } - - slice := ConfigAnalysisSlice{} - var args []interface{} - for _, obj := range *o { - pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), configAnalysisPrimaryKeyMapping) - args = append(args, pkeyArgs...) - } - - sql := "SELECT \"config_analysis\".* FROM \"config_analysis\" WHERE " + - strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, configAnalysisPrimaryKeyColumns, len(*o)) - - q := queries.Raw(sql, args...) - - err := q.Bind(nil, exec, &slice) - if err != nil { - return errors.Wrap(err, "models: unable to reload all in ConfigAnalysisSlice") - } - - *o = slice - - return nil -} - -// ConfigAnalysisExistsG checks if the ConfigAnalysis row exists. -func ConfigAnalysisExistsG(iD string) (bool, error) { - return ConfigAnalysisExists(boil.GetDB(), iD) -} - -// ConfigAnalysisExists checks if the ConfigAnalysis row exists. -func ConfigAnalysisExists(exec boil.Executor, iD string) (bool, error) { - var exists bool - sql := "select exists(select 1 from \"config_analysis\" where \"id\"=$1 limit 1)" - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) - } - row := exec.QueryRow(sql, iD) - - err := row.Scan(&exists) - if err != nil { - return false, errors.Wrap(err, "models: unable to check if config_analysis exists") - } - - return exists, nil -} diff --git a/db/models/config_change.go b/db/models/config_change.go index 7d2a625c..e1f485fb 100644 --- a/db/models/config_change.go +++ b/db/models/config_change.go @@ -1,1141 +1,20 @@ -// Code generated by SQLBoiler 4.8.3 (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 ( - "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" ) -// ConfigChange is an object representing the database table. +// ConfigChange represents the config change database table type ConfigChange struct { - ID string `boil:"id" json:"id" toml:"id" yaml:"id"` - ConfigID string `boil:"config_id" json:"config_id" toml:"config_id" yaml:"config_id"` - ChangeType string `boil:"change_type" json:"change_type" toml:"change_type" yaml:"change_type"` - Summary null.String `boil:"summary" json:"summary,omitempty" toml:"summary" yaml:"summary,omitempty"` - Patches null.JSON `boil:"patches" json:"patches,omitempty" toml:"patches" yaml:"patches,omitempty"` - CreatedAt time.Time `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"` - - R *configChangeR `boil:"-" json:"-" toml:"-" yaml:"-"` - L configChangeL `boil:"-" json:"-" toml:"-" yaml:"-"` -} - -var ConfigChangeColumns = struct { - ID string - ConfigID string - ChangeType string - Summary string - Patches string - CreatedAt string -}{ - ID: "id", - ConfigID: "config_id", - ChangeType: "change_type", - Summary: "summary", - Patches: "patches", - CreatedAt: "created_at", -} - -var ConfigChangeTableColumns = struct { - ID string - ConfigID string - ChangeType string - Summary string - Patches string - CreatedAt string -}{ - ID: "config_change.id", - ConfigID: "config_change.config_id", - ChangeType: "config_change.change_type", - Summary: "config_change.summary", - Patches: "config_change.patches", - CreatedAt: "config_change.created_at", -} - -// Generated where - -var ConfigChangeWhere = struct { - ID whereHelperstring - ConfigID whereHelperstring - ChangeType whereHelperstring - Summary whereHelpernull_String - Patches whereHelpernull_JSON - CreatedAt whereHelpertime_Time -}{ - ID: whereHelperstring{field: "\"config_change\".\"id\""}, - ConfigID: whereHelperstring{field: "\"config_change\".\"config_id\""}, - ChangeType: whereHelperstring{field: "\"config_change\".\"change_type\""}, - Summary: whereHelpernull_String{field: "\"config_change\".\"summary\""}, - Patches: whereHelpernull_JSON{field: "\"config_change\".\"patches\""}, - CreatedAt: whereHelpertime_Time{field: "\"config_change\".\"created_at\""}, -} - -// ConfigChangeRels is where relationship names are stored. -var ConfigChangeRels = struct { - Config string -}{ - Config: "Config", -} - -// configChangeR is where relationships are stored. -type configChangeR struct { - Config *ConfigItem `boil:"Config" json:"Config" toml:"Config" yaml:"Config"` -} - -// NewStruct creates a new relationship struct -func (*configChangeR) NewStruct() *configChangeR { - return &configChangeR{} -} - -// configChangeL is where Load methods for each relationship are stored. -type configChangeL struct{} - -var ( - configChangeAllColumns = []string{"id", "config_id", "change_type", "summary", "patches", "created_at"} - configChangeColumnsWithoutDefault = []string{"config_id", "change_type", "summary", "patches"} - configChangeColumnsWithDefault = []string{"id", "created_at"} - configChangePrimaryKeyColumns = []string{"id"} -) - -type ( - // ConfigChangeSlice is an alias for a slice of pointers to ConfigChange. - // This should almost always be used instead of []ConfigChange. - ConfigChangeSlice []*ConfigChange - // ConfigChangeHook is the signature for custom ConfigChange hook methods - ConfigChangeHook func(boil.Executor, *ConfigChange) error - - configChangeQuery struct { - *queries.Query - } -) - -// Cache for insert, update and upsert -var ( - configChangeType = reflect.TypeOf(&ConfigChange{}) - configChangeMapping = queries.MakeStructMapping(configChangeType) - configChangePrimaryKeyMapping, _ = queries.BindMapping(configChangeType, configChangeMapping, configChangePrimaryKeyColumns) - configChangeInsertCacheMut sync.RWMutex - configChangeInsertCache = make(map[string]insertCache) - configChangeUpdateCacheMut sync.RWMutex - configChangeUpdateCache = make(map[string]updateCache) - configChangeUpsertCacheMut sync.RWMutex - configChangeUpsertCache = 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 configChangeBeforeInsertHooks []ConfigChangeHook -var configChangeBeforeUpdateHooks []ConfigChangeHook -var configChangeBeforeDeleteHooks []ConfigChangeHook -var configChangeBeforeUpsertHooks []ConfigChangeHook - -var configChangeAfterInsertHooks []ConfigChangeHook -var configChangeAfterSelectHooks []ConfigChangeHook -var configChangeAfterUpdateHooks []ConfigChangeHook -var configChangeAfterDeleteHooks []ConfigChangeHook -var configChangeAfterUpsertHooks []ConfigChangeHook - -// doBeforeInsertHooks executes all "before insert" hooks. -func (o *ConfigChange) doBeforeInsertHooks(exec boil.Executor) (err error) { - for _, hook := range configChangeBeforeInsertHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doBeforeUpdateHooks executes all "before Update" hooks. -func (o *ConfigChange) doBeforeUpdateHooks(exec boil.Executor) (err error) { - for _, hook := range configChangeBeforeUpdateHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doBeforeDeleteHooks executes all "before Delete" hooks. -func (o *ConfigChange) doBeforeDeleteHooks(exec boil.Executor) (err error) { - for _, hook := range configChangeBeforeDeleteHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doBeforeUpsertHooks executes all "before Upsert" hooks. -func (o *ConfigChange) doBeforeUpsertHooks(exec boil.Executor) (err error) { - for _, hook := range configChangeBeforeUpsertHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doAfterInsertHooks executes all "after Insert" hooks. -func (o *ConfigChange) doAfterInsertHooks(exec boil.Executor) (err error) { - for _, hook := range configChangeAfterInsertHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doAfterSelectHooks executes all "after Select" hooks. -func (o *ConfigChange) doAfterSelectHooks(exec boil.Executor) (err error) { - for _, hook := range configChangeAfterSelectHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doAfterUpdateHooks executes all "after Update" hooks. -func (o *ConfigChange) doAfterUpdateHooks(exec boil.Executor) (err error) { - for _, hook := range configChangeAfterUpdateHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doAfterDeleteHooks executes all "after Delete" hooks. -func (o *ConfigChange) doAfterDeleteHooks(exec boil.Executor) (err error) { - for _, hook := range configChangeAfterDeleteHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doAfterUpsertHooks executes all "after Upsert" hooks. -func (o *ConfigChange) doAfterUpsertHooks(exec boil.Executor) (err error) { - for _, hook := range configChangeAfterUpsertHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// AddConfigChangeHook registers your hook function for all future operations. -func AddConfigChangeHook(hookPoint boil.HookPoint, configChangeHook ConfigChangeHook) { - switch hookPoint { - case boil.BeforeInsertHook: - configChangeBeforeInsertHooks = append(configChangeBeforeInsertHooks, configChangeHook) - case boil.BeforeUpdateHook: - configChangeBeforeUpdateHooks = append(configChangeBeforeUpdateHooks, configChangeHook) - case boil.BeforeDeleteHook: - configChangeBeforeDeleteHooks = append(configChangeBeforeDeleteHooks, configChangeHook) - case boil.BeforeUpsertHook: - configChangeBeforeUpsertHooks = append(configChangeBeforeUpsertHooks, configChangeHook) - case boil.AfterInsertHook: - configChangeAfterInsertHooks = append(configChangeAfterInsertHooks, configChangeHook) - case boil.AfterSelectHook: - configChangeAfterSelectHooks = append(configChangeAfterSelectHooks, configChangeHook) - case boil.AfterUpdateHook: - configChangeAfterUpdateHooks = append(configChangeAfterUpdateHooks, configChangeHook) - case boil.AfterDeleteHook: - configChangeAfterDeleteHooks = append(configChangeAfterDeleteHooks, configChangeHook) - case boil.AfterUpsertHook: - configChangeAfterUpsertHooks = append(configChangeAfterUpsertHooks, configChangeHook) - } -} - -// OneG returns a single configChange record from the query using the global executor. -func (q configChangeQuery) OneG() (*ConfigChange, error) { - return q.One(boil.GetDB()) -} - -// One returns a single configChange record from the query. -func (q configChangeQuery) One(exec boil.Executor) (*ConfigChange, error) { - o := &ConfigChange{} - - queries.SetLimit(q.Query, 1) - - err := q.Bind(nil, exec, o) - if err != nil { - if errors.Cause(err) == sql.ErrNoRows { - return nil, sql.ErrNoRows - } - return nil, errors.Wrap(err, "models: failed to execute a one query for config_change") - } - - if err := o.doAfterSelectHooks(exec); err != nil { - return o, err - } - - return o, nil -} - -// AllG returns all ConfigChange records from the query using the global executor. -func (q configChangeQuery) AllG() (ConfigChangeSlice, error) { - return q.All(boil.GetDB()) -} - -// All returns all ConfigChange records from the query. -func (q configChangeQuery) All(exec boil.Executor) (ConfigChangeSlice, error) { - var o []*ConfigChange - - err := q.Bind(nil, exec, &o) - if err != nil { - return nil, errors.Wrap(err, "models: failed to assign all query results to ConfigChange slice") - } - - if len(configChangeAfterSelectHooks) != 0 { - for _, obj := range o { - if err := obj.doAfterSelectHooks(exec); err != nil { - return o, err - } - } - } - - return o, nil -} - -// CountG returns the count of all ConfigChange records in the query, and panics on error. -func (q configChangeQuery) CountG() (int64, error) { - return q.Count(boil.GetDB()) -} - -// Count returns the count of all ConfigChange records in the query. -func (q configChangeQuery) Count(exec boil.Executor) (int64, error) { - var count int64 - - queries.SetSelect(q.Query, nil) - queries.SetCount(q.Query) - - err := q.Query.QueryRow(exec).Scan(&count) - if err != nil { - return 0, errors.Wrap(err, "models: failed to count config_change rows") - } - - return count, nil -} - -// ExistsG checks if the row exists in the table, and panics on error. -func (q configChangeQuery) ExistsG() (bool, error) { - return q.Exists(boil.GetDB()) -} - -// Exists checks if the row exists in the table. -func (q configChangeQuery) Exists(exec boil.Executor) (bool, error) { - var count int64 - - queries.SetSelect(q.Query, nil) - queries.SetCount(q.Query) - queries.SetLimit(q.Query, 1) - - err := q.Query.QueryRow(exec).Scan(&count) - if err != nil { - return false, errors.Wrap(err, "models: failed to check if config_change exists") - } - - return count > 0, nil -} - -// Config pointed to by the foreign key. -func (o *ConfigChange) Config(mods ...qm.QueryMod) configItemQuery { - queryMods := []qm.QueryMod{ - qm.Where("\"id\" = ?", o.ConfigID), - } - - queryMods = append(queryMods, mods...) - - query := ConfigItems(queryMods...) - queries.SetFrom(query.Query, "\"config_item\"") - - return query -} - -// LoadConfig allows an eager lookup of values, cached into the -// loaded structs of the objects. This is for an N-1 relationship. -func (configChangeL) LoadConfig(e boil.Executor, singular bool, maybeConfigChange interface{}, mods queries.Applicator) error { - var slice []*ConfigChange - var object *ConfigChange - - if singular { - object = maybeConfigChange.(*ConfigChange) - } else { - slice = *maybeConfigChange.(*[]*ConfigChange) - } - - args := make([]interface{}, 0, 1) - if singular { - if object.R == nil { - object.R = &configChangeR{} - } - args = append(args, object.ConfigID) - - } else { - Outer: - for _, obj := range slice { - if obj.R == nil { - obj.R = &configChangeR{} - } - - for _, a := range args { - if a == obj.ConfigID { - continue Outer - } - } - - args = append(args, obj.ConfigID) - - } - } - - if len(args) == 0 { - return nil - } - - query := NewQuery( - qm.From(`config_item`), - qm.WhereIn(`config_item.id in ?`, args...), - ) - if mods != nil { - mods.Apply(query) - } - - results, err := query.Query(e) - if err != nil { - return errors.Wrap(err, "failed to eager load ConfigItem") - } - - var resultSlice []*ConfigItem - if err = queries.Bind(results, &resultSlice); err != nil { - return errors.Wrap(err, "failed to bind eager loaded slice ConfigItem") - } - - if err = results.Close(); err != nil { - return errors.Wrap(err, "failed to close results of eager load for config_item") - } - if err = results.Err(); err != nil { - return errors.Wrap(err, "error occurred during iteration of eager loaded relations for config_item") - } - - if len(configChangeAfterSelectHooks) != 0 { - for _, obj := range resultSlice { - if err := obj.doAfterSelectHooks(e); err != nil { - return err - } - } - } - - if len(resultSlice) == 0 { - return nil - } - - if singular { - foreign := resultSlice[0] - object.R.Config = foreign - if foreign.R == nil { - foreign.R = &configItemR{} - } - foreign.R.ConfigConfigChanges = append(foreign.R.ConfigConfigChanges, object) - return nil - } - - for _, local := range slice { - for _, foreign := range resultSlice { - if local.ConfigID == foreign.ID { - local.R.Config = foreign - if foreign.R == nil { - foreign.R = &configItemR{} - } - foreign.R.ConfigConfigChanges = append(foreign.R.ConfigConfigChanges, local) - break - } - } - } - - return nil -} - -// SetConfigG of the configChange to the related item. -// Sets o.R.Config to related. -// Adds o to related.R.ConfigConfigChanges. -// Uses the global database handle. -func (o *ConfigChange) SetConfigG(insert bool, related *ConfigItem) error { - return o.SetConfig(boil.GetDB(), insert, related) -} - -// SetConfig of the configChange to the related item. -// Sets o.R.Config to related. -// Adds o to related.R.ConfigConfigChanges. -func (o *ConfigChange) SetConfig(exec boil.Executor, insert bool, related *ConfigItem) error { - var err error - if insert { - if err = related.Insert(exec, boil.Infer()); err != nil { - return errors.Wrap(err, "failed to insert into foreign table") - } - } - - updateQuery := fmt.Sprintf( - "UPDATE \"config_change\" SET %s WHERE %s", - strmangle.SetParamNames("\"", "\"", 1, []string{"config_id"}), - strmangle.WhereClause("\"", "\"", 2, configChangePrimaryKeyColumns), - ) - values := []interface{}{related.ID, o.ID} - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) - } - if _, err = exec.Exec(updateQuery, values...); err != nil { - return errors.Wrap(err, "failed to update local table") - } - - o.ConfigID = related.ID - if o.R == nil { - o.R = &configChangeR{ - Config: related, - } - } else { - o.R.Config = related - } - - if related.R == nil { - related.R = &configItemR{ - ConfigConfigChanges: ConfigChangeSlice{o}, - } - } else { - related.R.ConfigConfigChanges = append(related.R.ConfigConfigChanges, o) - } - - return nil -} - -// ConfigChanges retrieves all the records using an executor. -func ConfigChanges(mods ...qm.QueryMod) configChangeQuery { - mods = append(mods, qm.From("\"config_change\"")) - return configChangeQuery{NewQuery(mods...)} -} - -// FindConfigChangeG retrieves a single record by ID. -func FindConfigChangeG(iD string, selectCols ...string) (*ConfigChange, error) { - return FindConfigChange(boil.GetDB(), iD, selectCols...) -} - -// FindConfigChange retrieves a single record by ID with an executor. -// If selectCols is empty Find will return all columns. -func FindConfigChange(exec boil.Executor, iD string, selectCols ...string) (*ConfigChange, error) { - configChangeObj := &ConfigChange{} - - sel := "*" - if len(selectCols) > 0 { - sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",") - } - query := fmt.Sprintf( - "select %s from \"config_change\" where \"id\"=$1", sel, - ) - - q := queries.Raw(query, iD) - - err := q.Bind(nil, exec, configChangeObj) - if err != nil { - if errors.Cause(err) == sql.ErrNoRows { - return nil, sql.ErrNoRows - } - return nil, errors.Wrap(err, "models: unable to select from config_change") - } - - if err = configChangeObj.doAfterSelectHooks(exec); err != nil { - return configChangeObj, err - } - - return configChangeObj, nil -} - -// InsertG a single record. See Insert for whitelist behavior description. -func (o *ConfigChange) InsertG(columns boil.Columns) error { - return o.Insert(boil.GetDB(), columns) -} - -// Insert a single record using an executor. -// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts. -func (o *ConfigChange) Insert(exec boil.Executor, columns boil.Columns) error { - if o == nil { - return errors.New("models: no config_change provided for insertion") - } - - var err error - currTime := time.Now().In(boil.GetLocation()) - - if o.CreatedAt.IsZero() { - o.CreatedAt = currTime - } - - if err := o.doBeforeInsertHooks(exec); err != nil { - return err - } - - nzDefaults := queries.NonZeroDefaultSet(configChangeColumnsWithDefault, o) - - key := makeCacheKey(columns, nzDefaults) - configChangeInsertCacheMut.RLock() - cache, cached := configChangeInsertCache[key] - configChangeInsertCacheMut.RUnlock() - - if !cached { - wl, returnColumns := columns.InsertColumnSet( - configChangeAllColumns, - configChangeColumnsWithDefault, - configChangeColumnsWithoutDefault, - nzDefaults, - ) - - cache.valueMapping, err = queries.BindMapping(configChangeType, configChangeMapping, wl) - if err != nil { - return err - } - cache.retMapping, err = queries.BindMapping(configChangeType, configChangeMapping, returnColumns) - if err != nil { - return err - } - if len(wl) != 0 { - cache.query = fmt.Sprintf("INSERT INTO \"config_change\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1)) - } else { - cache.query = "INSERT INTO \"config_change\" %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.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) - } - - if len(cache.retMapping) != 0 { - err = exec.QueryRow(cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...) - } else { - _, err = exec.Exec(cache.query, vals...) - } - - if err != nil { - return errors.Wrap(err, "models: unable to insert into config_change") - } - - if !cached { - configChangeInsertCacheMut.Lock() - configChangeInsertCache[key] = cache - configChangeInsertCacheMut.Unlock() - } - - return o.doAfterInsertHooks(exec) -} - -// UpdateG a single ConfigChange record using the global executor. -// See Update for more documentation. -func (o *ConfigChange) UpdateG(columns boil.Columns) (int64, error) { - return o.Update(boil.GetDB(), columns) -} - -// Update uses an executor to update the ConfigChange. -// 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 *ConfigChange) Update(exec boil.Executor, columns boil.Columns) (int64, error) { - var err error - if err = o.doBeforeUpdateHooks(exec); err != nil { - return 0, err - } - key := makeCacheKey(columns, nil) - configChangeUpdateCacheMut.RLock() - cache, cached := configChangeUpdateCache[key] - configChangeUpdateCacheMut.RUnlock() - - if !cached { - wl := columns.UpdateColumnSet( - configChangeAllColumns, - configChangePrimaryKeyColumns, - ) - - if !columns.IsWhitelist() { - wl = strmangle.SetComplement(wl, []string{"created_at"}) - } - if len(wl) == 0 { - return 0, errors.New("models: unable to update config_change, could not build whitelist") - } - - cache.query = fmt.Sprintf("UPDATE \"config_change\" SET %s WHERE %s", - strmangle.SetParamNames("\"", "\"", 1, wl), - strmangle.WhereClause("\"", "\"", len(wl)+1, configChangePrimaryKeyColumns), - ) - cache.valueMapping, err = queries.BindMapping(configChangeType, configChangeMapping, append(wl, configChangePrimaryKeyColumns...)) - if err != nil { - return 0, err - } - } - - values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) - } - var result sql.Result - result, err = exec.Exec(cache.query, values...) - if err != nil { - return 0, errors.Wrap(err, "models: unable to update config_change row") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: failed to get rows affected by update for config_change") - } - - if !cached { - configChangeUpdateCacheMut.Lock() - configChangeUpdateCache[key] = cache - configChangeUpdateCacheMut.Unlock() - } - - return rowsAff, o.doAfterUpdateHooks(exec) -} - -// UpdateAllG updates all rows with the specified column values. -func (q configChangeQuery) UpdateAllG(cols M) (int64, error) { - return q.UpdateAll(boil.GetDB(), cols) -} - -// UpdateAll updates all rows with the specified column values. -func (q configChangeQuery) UpdateAll(exec boil.Executor, cols M) (int64, error) { - queries.SetUpdate(q.Query, cols) - - result, err := q.Query.Exec(exec) - if err != nil { - return 0, errors.Wrap(err, "models: unable to update all for config_change") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: unable to retrieve rows affected for config_change") - } - - return rowsAff, nil -} - -// UpdateAllG updates all rows with the specified column values. -func (o ConfigChangeSlice) UpdateAllG(cols M) (int64, error) { - return o.UpdateAll(boil.GetDB(), cols) -} - -// UpdateAll updates all rows with the specified column values, using an executor. -func (o ConfigChangeSlice) UpdateAll(exec boil.Executor, 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)), configChangePrimaryKeyMapping) - args = append(args, pkeyArgs...) - } - - sql := fmt.Sprintf("UPDATE \"config_change\" SET %s WHERE %s", - strmangle.SetParamNames("\"", "\"", 1, colNames), - strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, configChangePrimaryKeyColumns, len(o))) - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) - } - result, err := exec.Exec(sql, args...) - if err != nil { - return 0, errors.Wrap(err, "models: unable to update all in configChange slice") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all configChange") - } - return rowsAff, nil -} - -// UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *ConfigChange) UpsertG(updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(boil.GetDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) -} - -// 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 *ConfigChange) Upsert(exec boil.Executor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - if o == nil { - return errors.New("models: no config_change provided for upsert") - } - currTime := time.Now().In(boil.GetLocation()) - - if o.CreatedAt.IsZero() { - o.CreatedAt = currTime - } - - if err := o.doBeforeUpsertHooks(exec); err != nil { - return err - } - - nzDefaults := queries.NonZeroDefaultSet(configChangeColumnsWithDefault, 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) - - configChangeUpsertCacheMut.RLock() - cache, cached := configChangeUpsertCache[key] - configChangeUpsertCacheMut.RUnlock() - - var err error - - if !cached { - insert, ret := insertColumns.InsertColumnSet( - configChangeAllColumns, - configChangeColumnsWithDefault, - configChangeColumnsWithoutDefault, - nzDefaults, - ) - update := updateColumns.UpdateColumnSet( - configChangeAllColumns, - configChangePrimaryKeyColumns, - ) - - if updateOnConflict && len(update) == 0 { - return errors.New("models: unable to upsert config_change, could not build update column list") - } - - conflict := conflictColumns - if len(conflict) == 0 { - conflict = make([]string, len(configChangePrimaryKeyColumns)) - copy(conflict, configChangePrimaryKeyColumns) - } - cache.query = buildUpsertQueryPostgres(dialect, "\"config_change\"", updateOnConflict, ret, update, conflict, insert) - - cache.valueMapping, err = queries.BindMapping(configChangeType, configChangeMapping, insert) - if err != nil { - return err - } - if len(ret) != 0 { - cache.retMapping, err = queries.BindMapping(configChangeType, configChangeMapping, 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.QueryRow(cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { - err = nil // Postgres doesn't return anything when there's no update - } - } else { - _, err = exec.Exec(cache.query, vals...) - } - if err != nil { - return errors.Wrap(err, "models: unable to upsert config_change") - } - - if !cached { - configChangeUpsertCacheMut.Lock() - configChangeUpsertCache[key] = cache - configChangeUpsertCacheMut.Unlock() - } - - return o.doAfterUpsertHooks(exec) -} - -// DeleteG deletes a single ConfigChange record. -// DeleteG will match against the primary key column to find the record to delete. -func (o *ConfigChange) DeleteG() (int64, error) { - return o.Delete(boil.GetDB()) -} - -// Delete deletes a single ConfigChange record with an executor. -// Delete will match against the primary key column to find the record to delete. -func (o *ConfigChange) Delete(exec boil.Executor) (int64, error) { - if o == nil { - return 0, errors.New("models: no ConfigChange provided for delete") - } - - if err := o.doBeforeDeleteHooks(exec); err != nil { - return 0, err - } - - args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), configChangePrimaryKeyMapping) - sql := "DELETE FROM \"config_change\" WHERE \"id\"=$1" - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) - } - result, err := exec.Exec(sql, args...) - if err != nil { - return 0, errors.Wrap(err, "models: unable to delete from config_change") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: failed to get rows affected by delete for config_change") - } - - if err := o.doAfterDeleteHooks(exec); err != nil { - return 0, err - } - - return rowsAff, nil -} - -func (q configChangeQuery) DeleteAllG() (int64, error) { - return q.DeleteAll(boil.GetDB()) -} - -// DeleteAll deletes all matching rows. -func (q configChangeQuery) DeleteAll(exec boil.Executor) (int64, error) { - if q.Query == nil { - return 0, errors.New("models: no configChangeQuery provided for delete all") - } - - queries.SetDelete(q.Query) - - result, err := q.Query.Exec(exec) - if err != nil { - return 0, errors.Wrap(err, "models: unable to delete all from config_change") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for config_change") - } - - return rowsAff, nil -} - -// DeleteAllG deletes all rows in the slice. -func (o ConfigChangeSlice) DeleteAllG() (int64, error) { - return o.DeleteAll(boil.GetDB()) + ID string `gorm:"primaryKey;unique_index;not null;column:id" json:"id" toml:"id" yaml:"id"` + ConfigID string `gorm:"column:config_type;default:''" json:"config_type" toml:"config_type" yaml:"config_type"` + ChangeType string `gorm:"column:change_type" json:"change_type" toml:"change_type" yaml:"change_type"` + Summary *string `gorm:"column:summary;default:null" json:"summary,omitempty" toml:"summary" yaml:"summary,omitempty"` + Patches *string `gorm:"column:patches;default:null" json:"patches,omitempty" toml:"patches" yaml:"patches,omitempty"` + CreatedAt time.Time `gorm:"column:created_at" json:"created_at" toml:"created_at" yaml:"created_at"` } -// DeleteAll deletes all rows in the slice, using an executor. -func (o ConfigChangeSlice) DeleteAll(exec boil.Executor) (int64, error) { - if len(o) == 0 { - return 0, nil - } - - if len(configChangeBeforeDeleteHooks) != 0 { - for _, obj := range o { - if err := obj.doBeforeDeleteHooks(exec); err != nil { - return 0, err - } - } - } - - var args []interface{} - for _, obj := range o { - pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), configChangePrimaryKeyMapping) - args = append(args, pkeyArgs...) - } - - sql := "DELETE FROM \"config_change\" WHERE " + - strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, configChangePrimaryKeyColumns, len(o)) - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) - } - result, err := exec.Exec(sql, args...) - if err != nil { - return 0, errors.Wrap(err, "models: unable to delete all from configChange slice") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for config_change") - } - - if len(configChangeAfterDeleteHooks) != 0 { - for _, obj := range o { - if err := obj.doAfterDeleteHooks(exec); err != nil { - return 0, err - } - } - } - - return rowsAff, nil -} - -// ReloadG refetches the object from the database using the primary keys. -func (o *ConfigChange) ReloadG() error { - if o == nil { - return errors.New("models: no ConfigChange provided for reload") - } - - return o.Reload(boil.GetDB()) -} - -// Reload refetches the object from the database -// using the primary keys with an executor. -func (o *ConfigChange) Reload(exec boil.Executor) error { - ret, err := FindConfigChange(exec, o.ID) - if err != nil { - return err - } - - *o = *ret - return nil -} - -// ReloadAllG refetches every row with matching primary key column values -// and overwrites the original object slice with the newly updated slice. -func (o *ConfigChangeSlice) ReloadAllG() error { - if o == nil { - return errors.New("models: empty ConfigChangeSlice provided for reload all") - } - - return o.ReloadAll(boil.GetDB()) -} - -// ReloadAll refetches every row with matching primary key column values -// and overwrites the original object slice with the newly updated slice. -func (o *ConfigChangeSlice) ReloadAll(exec boil.Executor) error { - if o == nil || len(*o) == 0 { - return nil - } - - slice := ConfigChangeSlice{} - var args []interface{} - for _, obj := range *o { - pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), configChangePrimaryKeyMapping) - args = append(args, pkeyArgs...) - } - - sql := "SELECT \"config_change\".* FROM \"config_change\" WHERE " + - strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, configChangePrimaryKeyColumns, len(*o)) - - q := queries.Raw(sql, args...) - - err := q.Bind(nil, exec, &slice) - if err != nil { - return errors.Wrap(err, "models: unable to reload all in ConfigChangeSlice") - } - - *o = slice - - return nil -} - -// ConfigChangeExistsG checks if the ConfigChange row exists. -func ConfigChangeExistsG(iD string) (bool, error) { - return ConfigChangeExists(boil.GetDB(), iD) -} - -// ConfigChangeExists checks if the ConfigChange row exists. -func ConfigChangeExists(exec boil.Executor, iD string) (bool, error) { - var exists bool - sql := "select exists(select 1 from \"config_change\" where \"id\"=$1 limit 1)" - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) - } - row := exec.QueryRow(sql, iD) - - err := row.Scan(&exists) - if err != nil { - return false, errors.Wrap(err, "models: unable to check if config_change exists") - } - - return exists, nil +// TableName returns the corresponding table name of the model +func (ci *ConfigChange) TableName() string { + return "config_change" } diff --git a/db/models/config_item.go b/db/models/config_item.go index c8b096b0..7ca50cc0 100644 --- a/db/models/config_item.go +++ b/db/models/config_item.go @@ -1,1623 +1,27 @@ -// Code generated by SQLBoiler 4.8.3 (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 ( - "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" -) +import "time" -// ConfigItem is an object representing the database table. +// ConfigItem represents the config item database table type ConfigItem struct { - ID string `boil:"id" json:"id" toml:"id" yaml:"id"` - ScraperID null.String `boil:"scraper_id" json:"scraper_id,omitempty" toml:"scraper_id" yaml:"scraper_id,omitempty"` - ConfigType string `boil:"config_type" json:"config_type" toml:"config_type" yaml:"config_type"` - ExternalID null.String `boil:"external_id" json:"external_id,omitempty" toml:"external_id" yaml:"external_id,omitempty"` - Name null.String `boil:"name" json:"name,omitempty" toml:"name" yaml:"name,omitempty"` - Namespace null.String `boil:"namespace" json:"namespace,omitempty" toml:"namespace" yaml:"namespace,omitempty"` - Description null.String `boil:"description" json:"description,omitempty" toml:"description" yaml:"description,omitempty"` - Account null.String `boil:"account" json:"account,omitempty" toml:"account" yaml:"account,omitempty"` - Region null.String `boil:"region" json:"region,omitempty" toml:"region" yaml:"region,omitempty"` - Zone null.String `boil:"zone" json:"zone,omitempty" toml:"zone" yaml:"zone,omitempty"` - Network null.String `boil:"network" json:"network,omitempty" toml:"network" yaml:"network,omitempty"` - Subnet null.String `boil:"subnet" json:"subnet,omitempty" toml:"subnet" yaml:"subnet,omitempty"` - Config null.JSON `boil:"config" json:"config,omitempty" toml:"config" yaml:"config,omitempty"` - CreatedAt time.Time `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"` - UpdatedAt time.Time `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"` - - R *configItemR `boil:"-" json:"-" toml:"-" yaml:"-"` - L configItemL `boil:"-" json:"-" toml:"-" yaml:"-"` -} - -var ConfigItemColumns = struct { - ID string - ScraperID string - ConfigType string - ExternalID string - Name string - Namespace string - Description string - Account string - Region string - Zone string - Network string - Subnet string - Config string - CreatedAt string - UpdatedAt string -}{ - ID: "id", - ScraperID: "scraper_id", - ConfigType: "config_type", - ExternalID: "external_id", - Name: "name", - Namespace: "namespace", - Description: "description", - Account: "account", - Region: "region", - Zone: "zone", - Network: "network", - Subnet: "subnet", - Config: "config", - CreatedAt: "created_at", - UpdatedAt: "updated_at", -} - -var ConfigItemTableColumns = struct { - ID string - ScraperID string - ConfigType string - ExternalID string - Name string - Namespace string - Description string - Account string - Region string - Zone string - Network string - Subnet string - Config string - CreatedAt string - UpdatedAt string -}{ - ID: "config_item.id", - ScraperID: "config_item.scraper_id", - ConfigType: "config_item.config_type", - ExternalID: "config_item.external_id", - Name: "config_item.name", - Namespace: "config_item.namespace", - Description: "config_item.description", - Account: "config_item.account", - Region: "config_item.region", - Zone: "config_item.zone", - Network: "config_item.network", - Subnet: "config_item.subnet", - Config: "config_item.config", - CreatedAt: "config_item.created_at", - UpdatedAt: "config_item.updated_at", -} - -// Generated where - -var ConfigItemWhere = struct { - ID whereHelperstring - ScraperID whereHelpernull_String - ConfigType whereHelperstring - ExternalID whereHelpernull_String - Name whereHelpernull_String - Namespace whereHelpernull_String - Description whereHelpernull_String - Account whereHelpernull_String - Region whereHelpernull_String - Zone whereHelpernull_String - Network whereHelpernull_String - Subnet whereHelpernull_String - Config whereHelpernull_JSON - CreatedAt whereHelpertime_Time - UpdatedAt whereHelpertime_Time -}{ - ID: whereHelperstring{field: "\"config_item\".\"id\""}, - ScraperID: whereHelpernull_String{field: "\"config_item\".\"scraper_id\""}, - ConfigType: whereHelperstring{field: "\"config_item\".\"config_type\""}, - ExternalID: whereHelpernull_String{field: "\"config_item\".\"external_id\""}, - Name: whereHelpernull_String{field: "\"config_item\".\"name\""}, - Namespace: whereHelpernull_String{field: "\"config_item\".\"namespace\""}, - Description: whereHelpernull_String{field: "\"config_item\".\"description\""}, - Account: whereHelpernull_String{field: "\"config_item\".\"account\""}, - Region: whereHelpernull_String{field: "\"config_item\".\"region\""}, - Zone: whereHelpernull_String{field: "\"config_item\".\"zone\""}, - Network: whereHelpernull_String{field: "\"config_item\".\"network\""}, - Subnet: whereHelpernull_String{field: "\"config_item\".\"subnet\""}, - Config: whereHelpernull_JSON{field: "\"config_item\".\"config\""}, - CreatedAt: whereHelpertime_Time{field: "\"config_item\".\"created_at\""}, - UpdatedAt: whereHelpertime_Time{field: "\"config_item\".\"updated_at\""}, -} - -// ConfigItemRels is where relationship names are stored. -var ConfigItemRels = struct { - Scraper string - ConfigConfigAnalyses string - ConfigConfigChanges string -}{ - Scraper: "Scraper", - ConfigConfigAnalyses: "ConfigConfigAnalyses", - ConfigConfigChanges: "ConfigConfigChanges", -} - -// configItemR is where relationships are stored. -type configItemR struct { - Scraper *ConfigScraper `boil:"Scraper" json:"Scraper" toml:"Scraper" yaml:"Scraper"` - ConfigConfigAnalyses ConfigAnalysisSlice `boil:"ConfigConfigAnalyses" json:"ConfigConfigAnalyses" toml:"ConfigConfigAnalyses" yaml:"ConfigConfigAnalyses"` - ConfigConfigChanges ConfigChangeSlice `boil:"ConfigConfigChanges" json:"ConfigConfigChanges" toml:"ConfigConfigChanges" yaml:"ConfigConfigChanges"` -} - -// NewStruct creates a new relationship struct -func (*configItemR) NewStruct() *configItemR { - return &configItemR{} -} - -// configItemL is where Load methods for each relationship are stored. -type configItemL struct{} - -var ( - configItemAllColumns = []string{"id", "scraper_id", "config_type", "external_id", "name", "namespace", "description", "account", "region", "zone", "network", "subnet", "config", "created_at", "updated_at"} - configItemColumnsWithoutDefault = []string{"scraper_id", "config_type", "external_id", "name", "namespace", "description", "account", "region", "zone", "network", "subnet", "config"} - configItemColumnsWithDefault = []string{"id", "created_at", "updated_at"} - configItemPrimaryKeyColumns = []string{"id"} -) - -type ( - // ConfigItemSlice is an alias for a slice of pointers to ConfigItem. - // This should almost always be used instead of []ConfigItem. - ConfigItemSlice []*ConfigItem - // ConfigItemHook is the signature for custom ConfigItem hook methods - ConfigItemHook func(boil.Executor, *ConfigItem) error - - configItemQuery struct { - *queries.Query - } -) - -// Cache for insert, update and upsert -var ( - configItemType = reflect.TypeOf(&ConfigItem{}) - configItemMapping = queries.MakeStructMapping(configItemType) - configItemPrimaryKeyMapping, _ = queries.BindMapping(configItemType, configItemMapping, configItemPrimaryKeyColumns) - configItemInsertCacheMut sync.RWMutex - configItemInsertCache = make(map[string]insertCache) - configItemUpdateCacheMut sync.RWMutex - configItemUpdateCache = make(map[string]updateCache) - configItemUpsertCacheMut sync.RWMutex - configItemUpsertCache = 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 configItemBeforeInsertHooks []ConfigItemHook -var configItemBeforeUpdateHooks []ConfigItemHook -var configItemBeforeDeleteHooks []ConfigItemHook -var configItemBeforeUpsertHooks []ConfigItemHook - -var configItemAfterInsertHooks []ConfigItemHook -var configItemAfterSelectHooks []ConfigItemHook -var configItemAfterUpdateHooks []ConfigItemHook -var configItemAfterDeleteHooks []ConfigItemHook -var configItemAfterUpsertHooks []ConfigItemHook - -// doBeforeInsertHooks executes all "before insert" hooks. -func (o *ConfigItem) doBeforeInsertHooks(exec boil.Executor) (err error) { - for _, hook := range configItemBeforeInsertHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doBeforeUpdateHooks executes all "before Update" hooks. -func (o *ConfigItem) doBeforeUpdateHooks(exec boil.Executor) (err error) { - for _, hook := range configItemBeforeUpdateHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doBeforeDeleteHooks executes all "before Delete" hooks. -func (o *ConfigItem) doBeforeDeleteHooks(exec boil.Executor) (err error) { - for _, hook := range configItemBeforeDeleteHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doBeforeUpsertHooks executes all "before Upsert" hooks. -func (o *ConfigItem) doBeforeUpsertHooks(exec boil.Executor) (err error) { - for _, hook := range configItemBeforeUpsertHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doAfterInsertHooks executes all "after Insert" hooks. -func (o *ConfigItem) doAfterInsertHooks(exec boil.Executor) (err error) { - for _, hook := range configItemAfterInsertHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doAfterSelectHooks executes all "after Select" hooks. -func (o *ConfigItem) doAfterSelectHooks(exec boil.Executor) (err error) { - for _, hook := range configItemAfterSelectHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doAfterUpdateHooks executes all "after Update" hooks. -func (o *ConfigItem) doAfterUpdateHooks(exec boil.Executor) (err error) { - for _, hook := range configItemAfterUpdateHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doAfterDeleteHooks executes all "after Delete" hooks. -func (o *ConfigItem) doAfterDeleteHooks(exec boil.Executor) (err error) { - for _, hook := range configItemAfterDeleteHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doAfterUpsertHooks executes all "after Upsert" hooks. -func (o *ConfigItem) doAfterUpsertHooks(exec boil.Executor) (err error) { - for _, hook := range configItemAfterUpsertHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// AddConfigItemHook registers your hook function for all future operations. -func AddConfigItemHook(hookPoint boil.HookPoint, configItemHook ConfigItemHook) { - switch hookPoint { - case boil.BeforeInsertHook: - configItemBeforeInsertHooks = append(configItemBeforeInsertHooks, configItemHook) - case boil.BeforeUpdateHook: - configItemBeforeUpdateHooks = append(configItemBeforeUpdateHooks, configItemHook) - case boil.BeforeDeleteHook: - configItemBeforeDeleteHooks = append(configItemBeforeDeleteHooks, configItemHook) - case boil.BeforeUpsertHook: - configItemBeforeUpsertHooks = append(configItemBeforeUpsertHooks, configItemHook) - case boil.AfterInsertHook: - configItemAfterInsertHooks = append(configItemAfterInsertHooks, configItemHook) - case boil.AfterSelectHook: - configItemAfterSelectHooks = append(configItemAfterSelectHooks, configItemHook) - case boil.AfterUpdateHook: - configItemAfterUpdateHooks = append(configItemAfterUpdateHooks, configItemHook) - case boil.AfterDeleteHook: - configItemAfterDeleteHooks = append(configItemAfterDeleteHooks, configItemHook) - case boil.AfterUpsertHook: - configItemAfterUpsertHooks = append(configItemAfterUpsertHooks, configItemHook) - } -} - -// OneG returns a single configItem record from the query using the global executor. -func (q configItemQuery) OneG() (*ConfigItem, error) { - return q.One(boil.GetDB()) -} - -// One returns a single configItem record from the query. -func (q configItemQuery) One(exec boil.Executor) (*ConfigItem, error) { - o := &ConfigItem{} - - queries.SetLimit(q.Query, 1) - - err := q.Bind(nil, exec, o) - if err != nil { - if errors.Cause(err) == sql.ErrNoRows { - return nil, sql.ErrNoRows - } - return nil, errors.Wrap(err, "models: failed to execute a one query for config_item") - } - - if err := o.doAfterSelectHooks(exec); err != nil { - return o, err - } - - return o, nil -} - -// AllG returns all ConfigItem records from the query using the global executor. -func (q configItemQuery) AllG() (ConfigItemSlice, error) { - return q.All(boil.GetDB()) -} - -// All returns all ConfigItem records from the query. -func (q configItemQuery) All(exec boil.Executor) (ConfigItemSlice, error) { - var o []*ConfigItem - - err := q.Bind(nil, exec, &o) - if err != nil { - return nil, errors.Wrap(err, "models: failed to assign all query results to ConfigItem slice") - } - - if len(configItemAfterSelectHooks) != 0 { - for _, obj := range o { - if err := obj.doAfterSelectHooks(exec); err != nil { - return o, err - } - } - } - - return o, nil -} - -// CountG returns the count of all ConfigItem records in the query, and panics on error. -func (q configItemQuery) CountG() (int64, error) { - return q.Count(boil.GetDB()) -} - -// Count returns the count of all ConfigItem records in the query. -func (q configItemQuery) Count(exec boil.Executor) (int64, error) { - var count int64 - - queries.SetSelect(q.Query, nil) - queries.SetCount(q.Query) - - err := q.Query.QueryRow(exec).Scan(&count) - if err != nil { - return 0, errors.Wrap(err, "models: failed to count config_item rows") - } - - return count, nil -} - -// ExistsG checks if the row exists in the table, and panics on error. -func (q configItemQuery) ExistsG() (bool, error) { - return q.Exists(boil.GetDB()) -} - -// Exists checks if the row exists in the table. -func (q configItemQuery) Exists(exec boil.Executor) (bool, error) { - var count int64 - - queries.SetSelect(q.Query, nil) - queries.SetCount(q.Query) - queries.SetLimit(q.Query, 1) - - err := q.Query.QueryRow(exec).Scan(&count) - if err != nil { - return false, errors.Wrap(err, "models: failed to check if config_item exists") - } - - return count > 0, nil -} - -// Scraper pointed to by the foreign key. -func (o *ConfigItem) Scraper(mods ...qm.QueryMod) configScraperQuery { - queryMods := []qm.QueryMod{ - qm.Where("\"id\" = ?", o.ScraperID), - } - - queryMods = append(queryMods, mods...) - - query := ConfigScrapers(queryMods...) - queries.SetFrom(query.Query, "\"config_scraper\"") - - return query -} - -// ConfigConfigAnalyses retrieves all the config_analysis's ConfigAnalyses with an executor via config_id column. -func (o *ConfigItem) ConfigConfigAnalyses(mods ...qm.QueryMod) configAnalysisQuery { - var queryMods []qm.QueryMod - if len(mods) != 0 { - queryMods = append(queryMods, mods...) - } - - queryMods = append(queryMods, - qm.Where("\"config_analysis\".\"config_id\"=?", o.ID), - ) - - query := ConfigAnalyses(queryMods...) - queries.SetFrom(query.Query, "\"config_analysis\"") - - if len(queries.GetSelect(query.Query)) == 0 { - queries.SetSelect(query.Query, []string{"\"config_analysis\".*"}) - } - - return query -} - -// ConfigConfigChanges retrieves all the config_change's ConfigChanges with an executor via config_id column. -func (o *ConfigItem) ConfigConfigChanges(mods ...qm.QueryMod) configChangeQuery { - var queryMods []qm.QueryMod - if len(mods) != 0 { - queryMods = append(queryMods, mods...) - } - - queryMods = append(queryMods, - qm.Where("\"config_change\".\"config_id\"=?", o.ID), - ) - - query := ConfigChanges(queryMods...) - queries.SetFrom(query.Query, "\"config_change\"") - - if len(queries.GetSelect(query.Query)) == 0 { - queries.SetSelect(query.Query, []string{"\"config_change\".*"}) - } - - return query -} - -// LoadScraper allows an eager lookup of values, cached into the -// loaded structs of the objects. This is for an N-1 relationship. -func (configItemL) LoadScraper(e boil.Executor, singular bool, maybeConfigItem interface{}, mods queries.Applicator) error { - var slice []*ConfigItem - var object *ConfigItem - - if singular { - object = maybeConfigItem.(*ConfigItem) - } else { - slice = *maybeConfigItem.(*[]*ConfigItem) - } - - args := make([]interface{}, 0, 1) - if singular { - if object.R == nil { - object.R = &configItemR{} - } - if !queries.IsNil(object.ScraperID) { - args = append(args, object.ScraperID) - } - - } else { - Outer: - for _, obj := range slice { - if obj.R == nil { - obj.R = &configItemR{} - } - - for _, a := range args { - if queries.Equal(a, obj.ScraperID) { - continue Outer - } - } - - if !queries.IsNil(obj.ScraperID) { - args = append(args, obj.ScraperID) - } - - } - } - - if len(args) == 0 { - return nil - } - - query := NewQuery( - qm.From(`config_scraper`), - qm.WhereIn(`config_scraper.id in ?`, args...), - ) - if mods != nil { - mods.Apply(query) - } - - results, err := query.Query(e) - if err != nil { - return errors.Wrap(err, "failed to eager load ConfigScraper") - } - - var resultSlice []*ConfigScraper - if err = queries.Bind(results, &resultSlice); err != nil { - return errors.Wrap(err, "failed to bind eager loaded slice ConfigScraper") - } - - if err = results.Close(); err != nil { - return errors.Wrap(err, "failed to close results of eager load for config_scraper") - } - if err = results.Err(); err != nil { - return errors.Wrap(err, "error occurred during iteration of eager loaded relations for config_scraper") - } - - if len(configItemAfterSelectHooks) != 0 { - for _, obj := range resultSlice { - if err := obj.doAfterSelectHooks(e); err != nil { - return err - } - } - } - - if len(resultSlice) == 0 { - return nil - } - - if singular { - foreign := resultSlice[0] - object.R.Scraper = foreign - if foreign.R == nil { - foreign.R = &configScraperR{} - } - foreign.R.ScraperConfigItems = append(foreign.R.ScraperConfigItems, object) - return nil - } - - for _, local := range slice { - for _, foreign := range resultSlice { - if queries.Equal(local.ScraperID, foreign.ID) { - local.R.Scraper = foreign - if foreign.R == nil { - foreign.R = &configScraperR{} - } - foreign.R.ScraperConfigItems = append(foreign.R.ScraperConfigItems, local) - break - } - } - } - - return nil -} - -// LoadConfigConfigAnalyses 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 (configItemL) LoadConfigConfigAnalyses(e boil.Executor, singular bool, maybeConfigItem interface{}, mods queries.Applicator) error { - var slice []*ConfigItem - var object *ConfigItem - - if singular { - object = maybeConfigItem.(*ConfigItem) - } else { - slice = *maybeConfigItem.(*[]*ConfigItem) - } - - args := make([]interface{}, 0, 1) - if singular { - if object.R == nil { - object.R = &configItemR{} - } - args = append(args, object.ID) - } else { - Outer: - for _, obj := range slice { - if obj.R == nil { - obj.R = &configItemR{} - } - - for _, a := range args { - if a == obj.ID { - continue Outer - } - } - - args = append(args, obj.ID) - } - } - - if len(args) == 0 { - return nil - } - - query := NewQuery( - qm.From(`config_analysis`), - qm.WhereIn(`config_analysis.config_id in ?`, args...), - ) - if mods != nil { - mods.Apply(query) - } - - results, err := query.Query(e) - if err != nil { - return errors.Wrap(err, "failed to eager load config_analysis") - } - - var resultSlice []*ConfigAnalysis - if err = queries.Bind(results, &resultSlice); err != nil { - return errors.Wrap(err, "failed to bind eager loaded slice config_analysis") - } - - if err = results.Close(); err != nil { - return errors.Wrap(err, "failed to close results in eager load on config_analysis") - } - if err = results.Err(); err != nil { - return errors.Wrap(err, "error occurred during iteration of eager loaded relations for config_analysis") - } - - if len(configAnalysisAfterSelectHooks) != 0 { - for _, obj := range resultSlice { - if err := obj.doAfterSelectHooks(e); err != nil { - return err - } - } - } - if singular { - object.R.ConfigConfigAnalyses = resultSlice - for _, foreign := range resultSlice { - if foreign.R == nil { - foreign.R = &configAnalysisR{} - } - foreign.R.Config = object - } - return nil - } - - for _, foreign := range resultSlice { - for _, local := range slice { - if local.ID == foreign.ConfigID { - local.R.ConfigConfigAnalyses = append(local.R.ConfigConfigAnalyses, foreign) - if foreign.R == nil { - foreign.R = &configAnalysisR{} - } - foreign.R.Config = local - break - } - } - } - - return nil -} - -// LoadConfigConfigChanges 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 (configItemL) LoadConfigConfigChanges(e boil.Executor, singular bool, maybeConfigItem interface{}, mods queries.Applicator) error { - var slice []*ConfigItem - var object *ConfigItem - - if singular { - object = maybeConfigItem.(*ConfigItem) - } else { - slice = *maybeConfigItem.(*[]*ConfigItem) - } - - args := make([]interface{}, 0, 1) - if singular { - if object.R == nil { - object.R = &configItemR{} - } - args = append(args, object.ID) - } else { - Outer: - for _, obj := range slice { - if obj.R == nil { - obj.R = &configItemR{} - } - - for _, a := range args { - if a == obj.ID { - continue Outer - } - } - - args = append(args, obj.ID) - } - } - - if len(args) == 0 { - return nil - } - - query := NewQuery( - qm.From(`config_change`), - qm.WhereIn(`config_change.config_id in ?`, args...), - ) - if mods != nil { - mods.Apply(query) - } - - results, err := query.Query(e) - if err != nil { - return errors.Wrap(err, "failed to eager load config_change") - } - - var resultSlice []*ConfigChange - if err = queries.Bind(results, &resultSlice); err != nil { - return errors.Wrap(err, "failed to bind eager loaded slice config_change") - } - - if err = results.Close(); err != nil { - return errors.Wrap(err, "failed to close results in eager load on config_change") - } - if err = results.Err(); err != nil { - return errors.Wrap(err, "error occurred during iteration of eager loaded relations for config_change") - } - - if len(configChangeAfterSelectHooks) != 0 { - for _, obj := range resultSlice { - if err := obj.doAfterSelectHooks(e); err != nil { - return err - } - } - } - if singular { - object.R.ConfigConfigChanges = resultSlice - for _, foreign := range resultSlice { - if foreign.R == nil { - foreign.R = &configChangeR{} - } - foreign.R.Config = object - } - return nil - } - - for _, foreign := range resultSlice { - for _, local := range slice { - if local.ID == foreign.ConfigID { - local.R.ConfigConfigChanges = append(local.R.ConfigConfigChanges, foreign) - if foreign.R == nil { - foreign.R = &configChangeR{} - } - foreign.R.Config = local - break - } - } - } - - return nil -} - -// SetScraperG of the configItem to the related item. -// Sets o.R.Scraper to related. -// Adds o to related.R.ScraperConfigItems. -// Uses the global database handle. -func (o *ConfigItem) SetScraperG(insert bool, related *ConfigScraper) error { - return o.SetScraper(boil.GetDB(), insert, related) -} - -// SetScraper of the configItem to the related item. -// Sets o.R.Scraper to related. -// Adds o to related.R.ScraperConfigItems. -func (o *ConfigItem) SetScraper(exec boil.Executor, insert bool, related *ConfigScraper) error { - var err error - if insert { - if err = related.Insert(exec, boil.Infer()); err != nil { - return errors.Wrap(err, "failed to insert into foreign table") - } - } - - updateQuery := fmt.Sprintf( - "UPDATE \"config_item\" SET %s WHERE %s", - strmangle.SetParamNames("\"", "\"", 1, []string{"scraper_id"}), - strmangle.WhereClause("\"", "\"", 2, configItemPrimaryKeyColumns), - ) - values := []interface{}{related.ID, o.ID} - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) - } - if _, err = exec.Exec(updateQuery, values...); err != nil { - return errors.Wrap(err, "failed to update local table") - } - - queries.Assign(&o.ScraperID, related.ID) - if o.R == nil { - o.R = &configItemR{ - Scraper: related, - } - } else { - o.R.Scraper = related - } - - if related.R == nil { - related.R = &configScraperR{ - ScraperConfigItems: ConfigItemSlice{o}, - } - } else { - related.R.ScraperConfigItems = append(related.R.ScraperConfigItems, o) - } - - return nil -} - -// RemoveScraperG relationship. -// Sets o.R.Scraper to nil. -// Removes o from all passed in related items' relationships struct (Optional). -// Uses the global database handle. -func (o *ConfigItem) RemoveScraperG(related *ConfigScraper) error { - return o.RemoveScraper(boil.GetDB(), related) -} - -// RemoveScraper relationship. -// Sets o.R.Scraper to nil. -// Removes o from all passed in related items' relationships struct (Optional). -func (o *ConfigItem) RemoveScraper(exec boil.Executor, related *ConfigScraper) error { - var err error - - queries.SetScanner(&o.ScraperID, nil) - if _, err = o.Update(exec, boil.Whitelist("scraper_id")); err != nil { - return errors.Wrap(err, "failed to update local table") - } - - if o.R != nil { - o.R.Scraper = nil - } - if related == nil || related.R == nil { - return nil - } - - for i, ri := range related.R.ScraperConfigItems { - if queries.Equal(o.ScraperID, ri.ScraperID) { - continue - } - - ln := len(related.R.ScraperConfigItems) - if ln > 1 && i < ln-1 { - related.R.ScraperConfigItems[i] = related.R.ScraperConfigItems[ln-1] - } - related.R.ScraperConfigItems = related.R.ScraperConfigItems[:ln-1] - break - } - return nil -} - -// AddConfigConfigAnalysesG adds the given related objects to the existing relationships -// of the config_item, optionally inserting them as new records. -// Appends related to o.R.ConfigConfigAnalyses. -// Sets related.R.Config appropriately. -// Uses the global database handle. -func (o *ConfigItem) AddConfigConfigAnalysesG(insert bool, related ...*ConfigAnalysis) error { - return o.AddConfigConfigAnalyses(boil.GetDB(), insert, related...) -} - -// AddConfigConfigAnalyses adds the given related objects to the existing relationships -// of the config_item, optionally inserting them as new records. -// Appends related to o.R.ConfigConfigAnalyses. -// Sets related.R.Config appropriately. -func (o *ConfigItem) AddConfigConfigAnalyses(exec boil.Executor, insert bool, related ...*ConfigAnalysis) error { - var err error - for _, rel := range related { - if insert { - rel.ConfigID = o.ID - if err = rel.Insert(exec, boil.Infer()); err != nil { - return errors.Wrap(err, "failed to insert into foreign table") - } - } else { - updateQuery := fmt.Sprintf( - "UPDATE \"config_analysis\" SET %s WHERE %s", - strmangle.SetParamNames("\"", "\"", 1, []string{"config_id"}), - strmangle.WhereClause("\"", "\"", 2, configAnalysisPrimaryKeyColumns), - ) - values := []interface{}{o.ID, rel.ID} - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) - } - if _, err = exec.Exec(updateQuery, values...); err != nil { - return errors.Wrap(err, "failed to update foreign table") - } - - rel.ConfigID = o.ID - } - } - - if o.R == nil { - o.R = &configItemR{ - ConfigConfigAnalyses: related, - } - } else { - o.R.ConfigConfigAnalyses = append(o.R.ConfigConfigAnalyses, related...) - } - - for _, rel := range related { - if rel.R == nil { - rel.R = &configAnalysisR{ - Config: o, - } - } else { - rel.R.Config = o - } - } - return nil -} - -// AddConfigConfigChangesG adds the given related objects to the existing relationships -// of the config_item, optionally inserting them as new records. -// Appends related to o.R.ConfigConfigChanges. -// Sets related.R.Config appropriately. -// Uses the global database handle. -func (o *ConfigItem) AddConfigConfigChangesG(insert bool, related ...*ConfigChange) error { - return o.AddConfigConfigChanges(boil.GetDB(), insert, related...) -} - -// AddConfigConfigChanges adds the given related objects to the existing relationships -// of the config_item, optionally inserting them as new records. -// Appends related to o.R.ConfigConfigChanges. -// Sets related.R.Config appropriately. -func (o *ConfigItem) AddConfigConfigChanges(exec boil.Executor, insert bool, related ...*ConfigChange) error { - var err error - for _, rel := range related { - if insert { - rel.ConfigID = o.ID - if err = rel.Insert(exec, boil.Infer()); err != nil { - return errors.Wrap(err, "failed to insert into foreign table") - } - } else { - updateQuery := fmt.Sprintf( - "UPDATE \"config_change\" SET %s WHERE %s", - strmangle.SetParamNames("\"", "\"", 1, []string{"config_id"}), - strmangle.WhereClause("\"", "\"", 2, configChangePrimaryKeyColumns), - ) - values := []interface{}{o.ID, rel.ID} - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) - } - if _, err = exec.Exec(updateQuery, values...); err != nil { - return errors.Wrap(err, "failed to update foreign table") - } - - rel.ConfigID = o.ID - } - } - - if o.R == nil { - o.R = &configItemR{ - ConfigConfigChanges: related, - } - } else { - o.R.ConfigConfigChanges = append(o.R.ConfigConfigChanges, related...) - } - - for _, rel := range related { - if rel.R == nil { - rel.R = &configChangeR{ - Config: o, - } - } else { - rel.R.Config = o - } - } - return nil -} - -// ConfigItems retrieves all the records using an executor. -func ConfigItems(mods ...qm.QueryMod) configItemQuery { - mods = append(mods, qm.From("\"config_item\"")) - return configItemQuery{NewQuery(mods...)} -} - -// FindConfigItemG retrieves a single record by ID. -func FindConfigItemG(iD string, selectCols ...string) (*ConfigItem, error) { - return FindConfigItem(boil.GetDB(), iD, selectCols...) -} - -// FindConfigItem retrieves a single record by ID with an executor. -// If selectCols is empty Find will return all columns. -func FindConfigItem(exec boil.Executor, iD string, selectCols ...string) (*ConfigItem, error) { - configItemObj := &ConfigItem{} - - sel := "*" - if len(selectCols) > 0 { - sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",") - } - query := fmt.Sprintf( - "select %s from \"config_item\" where \"id\"=$1", sel, - ) - - q := queries.Raw(query, iD) - - err := q.Bind(nil, exec, configItemObj) - if err != nil { - if errors.Cause(err) == sql.ErrNoRows { - return nil, sql.ErrNoRows - } - return nil, errors.Wrap(err, "models: unable to select from config_item") - } - - if err = configItemObj.doAfterSelectHooks(exec); err != nil { - return configItemObj, err - } - - return configItemObj, nil -} - -// InsertG a single record. See Insert for whitelist behavior description. -func (o *ConfigItem) InsertG(columns boil.Columns) error { - return o.Insert(boil.GetDB(), columns) -} - -// Insert a single record using an executor. -// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts. -func (o *ConfigItem) Insert(exec boil.Executor, columns boil.Columns) error { - if o == nil { - return errors.New("models: no config_item provided for insertion") - } - - var err error - currTime := time.Now().In(boil.GetLocation()) - - if o.CreatedAt.IsZero() { - o.CreatedAt = currTime - } - if o.UpdatedAt.IsZero() { - o.UpdatedAt = currTime - } - - if err := o.doBeforeInsertHooks(exec); err != nil { - return err - } - - nzDefaults := queries.NonZeroDefaultSet(configItemColumnsWithDefault, o) - - key := makeCacheKey(columns, nzDefaults) - configItemInsertCacheMut.RLock() - cache, cached := configItemInsertCache[key] - configItemInsertCacheMut.RUnlock() - - if !cached { - wl, returnColumns := columns.InsertColumnSet( - configItemAllColumns, - configItemColumnsWithDefault, - configItemColumnsWithoutDefault, - nzDefaults, - ) - - cache.valueMapping, err = queries.BindMapping(configItemType, configItemMapping, wl) - if err != nil { - return err - } - cache.retMapping, err = queries.BindMapping(configItemType, configItemMapping, returnColumns) - if err != nil { - return err - } - if len(wl) != 0 { - cache.query = fmt.Sprintf("INSERT INTO \"config_item\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1)) - } else { - cache.query = "INSERT INTO \"config_item\" %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.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) - } - - if len(cache.retMapping) != 0 { - err = exec.QueryRow(cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...) - } else { - _, err = exec.Exec(cache.query, vals...) - } - - if err != nil { - return errors.Wrap(err, "models: unable to insert into config_item") - } - - if !cached { - configItemInsertCacheMut.Lock() - configItemInsertCache[key] = cache - configItemInsertCacheMut.Unlock() - } - - return o.doAfterInsertHooks(exec) -} - -// UpdateG a single ConfigItem record using the global executor. -// See Update for more documentation. -func (o *ConfigItem) UpdateG(columns boil.Columns) (int64, error) { - return o.Update(boil.GetDB(), columns) -} - -// Update uses an executor to update the ConfigItem. -// 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 *ConfigItem) Update(exec boil.Executor, columns boil.Columns) (int64, error) { - currTime := time.Now().In(boil.GetLocation()) - - o.UpdatedAt = currTime - - var err error - if err = o.doBeforeUpdateHooks(exec); err != nil { - return 0, err - } - key := makeCacheKey(columns, nil) - configItemUpdateCacheMut.RLock() - cache, cached := configItemUpdateCache[key] - configItemUpdateCacheMut.RUnlock() - - if !cached { - wl := columns.UpdateColumnSet( - configItemAllColumns, - configItemPrimaryKeyColumns, - ) - - if !columns.IsWhitelist() { - wl = strmangle.SetComplement(wl, []string{"created_at"}) - } - if len(wl) == 0 { - return 0, errors.New("models: unable to update config_item, could not build whitelist") - } - - cache.query = fmt.Sprintf("UPDATE \"config_item\" SET %s WHERE %s", - strmangle.SetParamNames("\"", "\"", 1, wl), - strmangle.WhereClause("\"", "\"", len(wl)+1, configItemPrimaryKeyColumns), - ) - cache.valueMapping, err = queries.BindMapping(configItemType, configItemMapping, append(wl, configItemPrimaryKeyColumns...)) - if err != nil { - return 0, err - } - } - - values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) - } - var result sql.Result - result, err = exec.Exec(cache.query, values...) - if err != nil { - return 0, errors.Wrap(err, "models: unable to update config_item row") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: failed to get rows affected by update for config_item") - } - - if !cached { - configItemUpdateCacheMut.Lock() - configItemUpdateCache[key] = cache - configItemUpdateCacheMut.Unlock() - } - - return rowsAff, o.doAfterUpdateHooks(exec) -} - -// UpdateAllG updates all rows with the specified column values. -func (q configItemQuery) UpdateAllG(cols M) (int64, error) { - return q.UpdateAll(boil.GetDB(), cols) -} - -// UpdateAll updates all rows with the specified column values. -func (q configItemQuery) UpdateAll(exec boil.Executor, cols M) (int64, error) { - queries.SetUpdate(q.Query, cols) - - result, err := q.Query.Exec(exec) - if err != nil { - return 0, errors.Wrap(err, "models: unable to update all for config_item") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: unable to retrieve rows affected for config_item") - } - - return rowsAff, nil -} - -// UpdateAllG updates all rows with the specified column values. -func (o ConfigItemSlice) UpdateAllG(cols M) (int64, error) { - return o.UpdateAll(boil.GetDB(), cols) -} - -// UpdateAll updates all rows with the specified column values, using an executor. -func (o ConfigItemSlice) UpdateAll(exec boil.Executor, 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)), configItemPrimaryKeyMapping) - args = append(args, pkeyArgs...) - } - - sql := fmt.Sprintf("UPDATE \"config_item\" SET %s WHERE %s", - strmangle.SetParamNames("\"", "\"", 1, colNames), - strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, configItemPrimaryKeyColumns, len(o))) - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) - } - result, err := exec.Exec(sql, args...) - if err != nil { - return 0, errors.Wrap(err, "models: unable to update all in configItem slice") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all configItem") - } - return rowsAff, nil -} - -// UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *ConfigItem) UpsertG(updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(boil.GetDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) -} - -// 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 *ConfigItem) Upsert(exec boil.Executor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - if o == nil { - return errors.New("models: no config_item provided for upsert") - } - currTime := time.Now().In(boil.GetLocation()) - - if o.CreatedAt.IsZero() { - o.CreatedAt = currTime - } - o.UpdatedAt = currTime - - if err := o.doBeforeUpsertHooks(exec); err != nil { - return err - } - - nzDefaults := queries.NonZeroDefaultSet(configItemColumnsWithDefault, 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) - - configItemUpsertCacheMut.RLock() - cache, cached := configItemUpsertCache[key] - configItemUpsertCacheMut.RUnlock() - - var err error - - if !cached { - insert, ret := insertColumns.InsertColumnSet( - configItemAllColumns, - configItemColumnsWithDefault, - configItemColumnsWithoutDefault, - nzDefaults, - ) - update := updateColumns.UpdateColumnSet( - configItemAllColumns, - configItemPrimaryKeyColumns, - ) - - if updateOnConflict && len(update) == 0 { - return errors.New("models: unable to upsert config_item, could not build update column list") - } - - conflict := conflictColumns - if len(conflict) == 0 { - conflict = make([]string, len(configItemPrimaryKeyColumns)) - copy(conflict, configItemPrimaryKeyColumns) - } - cache.query = buildUpsertQueryPostgres(dialect, "\"config_item\"", updateOnConflict, ret, update, conflict, insert) - - cache.valueMapping, err = queries.BindMapping(configItemType, configItemMapping, insert) - if err != nil { - return err - } - if len(ret) != 0 { - cache.retMapping, err = queries.BindMapping(configItemType, configItemMapping, 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.QueryRow(cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { - err = nil // Postgres doesn't return anything when there's no update - } - } else { - _, err = exec.Exec(cache.query, vals...) - } - if err != nil { - return errors.Wrap(err, "models: unable to upsert config_item") - } - - if !cached { - configItemUpsertCacheMut.Lock() - configItemUpsertCache[key] = cache - configItemUpsertCacheMut.Unlock() - } - - return o.doAfterUpsertHooks(exec) -} - -// DeleteG deletes a single ConfigItem record. -// DeleteG will match against the primary key column to find the record to delete. -func (o *ConfigItem) DeleteG() (int64, error) { - return o.Delete(boil.GetDB()) -} - -// Delete deletes a single ConfigItem record with an executor. -// Delete will match against the primary key column to find the record to delete. -func (o *ConfigItem) Delete(exec boil.Executor) (int64, error) { - if o == nil { - return 0, errors.New("models: no ConfigItem provided for delete") - } - - if err := o.doBeforeDeleteHooks(exec); err != nil { - return 0, err - } - - args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), configItemPrimaryKeyMapping) - sql := "DELETE FROM \"config_item\" WHERE \"id\"=$1" - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) - } - result, err := exec.Exec(sql, args...) - if err != nil { - return 0, errors.Wrap(err, "models: unable to delete from config_item") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: failed to get rows affected by delete for config_item") - } - - if err := o.doAfterDeleteHooks(exec); err != nil { - return 0, err - } - - return rowsAff, nil -} - -func (q configItemQuery) DeleteAllG() (int64, error) { - return q.DeleteAll(boil.GetDB()) -} - -// DeleteAll deletes all matching rows. -func (q configItemQuery) DeleteAll(exec boil.Executor) (int64, error) { - if q.Query == nil { - return 0, errors.New("models: no configItemQuery provided for delete all") - } - - queries.SetDelete(q.Query) - - result, err := q.Query.Exec(exec) - if err != nil { - return 0, errors.Wrap(err, "models: unable to delete all from config_item") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for config_item") - } - - return rowsAff, nil -} - -// DeleteAllG deletes all rows in the slice. -func (o ConfigItemSlice) DeleteAllG() (int64, error) { - return o.DeleteAll(boil.GetDB()) -} - -// DeleteAll deletes all rows in the slice, using an executor. -func (o ConfigItemSlice) DeleteAll(exec boil.Executor) (int64, error) { - if len(o) == 0 { - return 0, nil - } - - if len(configItemBeforeDeleteHooks) != 0 { - for _, obj := range o { - if err := obj.doBeforeDeleteHooks(exec); err != nil { - return 0, err - } - } - } - - var args []interface{} - for _, obj := range o { - pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), configItemPrimaryKeyMapping) - args = append(args, pkeyArgs...) - } - - sql := "DELETE FROM \"config_item\" WHERE " + - strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, configItemPrimaryKeyColumns, len(o)) - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) - } - result, err := exec.Exec(sql, args...) - if err != nil { - return 0, errors.Wrap(err, "models: unable to delete all from configItem slice") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for config_item") - } - - if len(configItemAfterDeleteHooks) != 0 { - for _, obj := range o { - if err := obj.doAfterDeleteHooks(exec); err != nil { - return 0, err - } - } - } - - return rowsAff, nil -} - -// ReloadG refetches the object from the database using the primary keys. -func (o *ConfigItem) ReloadG() error { - if o == nil { - return errors.New("models: no ConfigItem provided for reload") - } - - return o.Reload(boil.GetDB()) -} - -// Reload refetches the object from the database -// using the primary keys with an executor. -func (o *ConfigItem) Reload(exec boil.Executor) error { - ret, err := FindConfigItem(exec, o.ID) - if err != nil { - return err - } - - *o = *ret - return nil -} - -// ReloadAllG refetches every row with matching primary key column values -// and overwrites the original object slice with the newly updated slice. -func (o *ConfigItemSlice) ReloadAllG() error { - if o == nil { - return errors.New("models: empty ConfigItemSlice provided for reload all") - } - - return o.ReloadAll(boil.GetDB()) -} - -// ReloadAll refetches every row with matching primary key column values -// and overwrites the original object slice with the newly updated slice. -func (o *ConfigItemSlice) ReloadAll(exec boil.Executor) error { - if o == nil || len(*o) == 0 { - return nil - } - - slice := ConfigItemSlice{} - var args []interface{} - for _, obj := range *o { - pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), configItemPrimaryKeyMapping) - args = append(args, pkeyArgs...) - } - - sql := "SELECT \"config_item\".* FROM \"config_item\" WHERE " + - strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, configItemPrimaryKeyColumns, len(*o)) - - q := queries.Raw(sql, args...) - - err := q.Bind(nil, exec, &slice) - if err != nil { - return errors.Wrap(err, "models: unable to reload all in ConfigItemSlice") - } - - *o = slice - - return nil -} - -// ConfigItemExistsG checks if the ConfigItem row exists. -func ConfigItemExistsG(iD string) (bool, error) { - return ConfigItemExists(boil.GetDB(), iD) -} - -// ConfigItemExists checks if the ConfigItem row exists. -func ConfigItemExists(exec boil.Executor, iD string) (bool, error) { - var exists bool - sql := "select exists(select 1 from \"config_item\" where \"id\"=$1 limit 1)" - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) - } - row := exec.QueryRow(sql, iD) - - err := row.Scan(&exists) - if err != nil { - return false, errors.Wrap(err, "models: unable to check if config_item exists") - } - - return exists, nil + ID string `gorm:"primaryKey;unique_index;not null;column:id" json:"id" toml:"id" yaml:"id"` + ScraperID *string `gorm:"column:scraper_id;default:null" json:"scraper_id,omitempty" toml:"scraper_id" yaml:"scraper_id,omitempty"` + ConfigType string `gorm:"column:config_type;default:''" json:"config_type" toml:"config_type" yaml:"config_type"` + ExternalID *string `gorm:"column:external_id;default:null" json:"external_id,omitempty" toml:"external_id" yaml:"external_id,omitempty"` + Name *string `gorm:"column:name;default:null" json:"name,omitempty" toml:"name" yaml:"name,omitempty"` + Namespace *string `gorm:"column:namespace;default:null" json:"namespace,omitempty" toml:"namespace" yaml:"namespace,omitempty"` + Description *string `gorm:"column:description;default:null" json:"description,omitempty" toml:"description" yaml:"description,omitempty"` + Account *string `gorm:"column:account;default:null" json:"account,omitempty" toml:"account" yaml:"account,omitempty"` + Region *string `gorm:"column:region;default:null" json:"region,omitempty" toml:"region" yaml:"region,omitempty"` + Zone *string `gorm:"column:zone;default:null" json:"zone,omitempty" toml:"zone" yaml:"zone,omitempty"` + Network *string `gorm:"column:network;default:null" json:"network,omitempty" toml:"network" yaml:"network,omitempty"` + Subnet *string `gorm:"column:subnet;default:null" json:"subnet,omitempty" toml:"subnet" yaml:"subnet,omitempty"` + Config *string `gorm:"column:config;default:null" json:"config,omitempty" toml:"config" yaml:"config,omitempty"` + CreatedAt time.Time `gorm:"column:created_at" json:"created_at" toml:"created_at" yaml:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"` +} + +// TableName returns the corresponding table name of the model +func (ci *ConfigItem) TableName() string { + return "config_item" } diff --git a/db/models/config_scraper.go b/db/models/config_scraper.go deleted file mode 100644 index ea6ca9f5..00000000 --- a/db/models/config_scraper.go +++ /dev/null @@ -1,1249 +0,0 @@ -// Code generated by SQLBoiler 4.8.3 (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 ( - "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" -) - -// ConfigScraper is an object representing the database table. -type ConfigScraper struct { - ID string `boil:"id" json:"id" toml:"id" yaml:"id"` - Description null.String `boil:"description" json:"description,omitempty" toml:"description" yaml:"description,omitempty"` - ScraperType string `boil:"scraper_type" json:"scraper_type" toml:"scraper_type" yaml:"scraper_type"` - Spec null.JSON `boil:"spec" json:"spec,omitempty" toml:"spec" yaml:"spec,omitempty"` - CreatedAt time.Time `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"` - UpdatedAt time.Time `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"` - - R *configScraperR `boil:"-" json:"-" toml:"-" yaml:"-"` - L configScraperL `boil:"-" json:"-" toml:"-" yaml:"-"` -} - -var ConfigScraperColumns = struct { - ID string - Description string - ScraperType string - Spec string - CreatedAt string - UpdatedAt string -}{ - ID: "id", - Description: "description", - ScraperType: "scraper_type", - Spec: "spec", - CreatedAt: "created_at", - UpdatedAt: "updated_at", -} - -var ConfigScraperTableColumns = struct { - ID string - Description string - ScraperType string - Spec string - CreatedAt string - UpdatedAt string -}{ - ID: "config_scraper.id", - Description: "config_scraper.description", - ScraperType: "config_scraper.scraper_type", - Spec: "config_scraper.spec", - CreatedAt: "config_scraper.created_at", - UpdatedAt: "config_scraper.updated_at", -} - -// Generated where - -var ConfigScraperWhere = struct { - ID whereHelperstring - Description whereHelpernull_String - ScraperType whereHelperstring - Spec whereHelpernull_JSON - CreatedAt whereHelpertime_Time - UpdatedAt whereHelpertime_Time -}{ - ID: whereHelperstring{field: "\"config_scraper\".\"id\""}, - Description: whereHelpernull_String{field: "\"config_scraper\".\"description\""}, - ScraperType: whereHelperstring{field: "\"config_scraper\".\"scraper_type\""}, - Spec: whereHelpernull_JSON{field: "\"config_scraper\".\"spec\""}, - CreatedAt: whereHelpertime_Time{field: "\"config_scraper\".\"created_at\""}, - UpdatedAt: whereHelpertime_Time{field: "\"config_scraper\".\"updated_at\""}, -} - -// ConfigScraperRels is where relationship names are stored. -var ConfigScraperRels = struct { - ScraperConfigItems string -}{ - ScraperConfigItems: "ScraperConfigItems", -} - -// configScraperR is where relationships are stored. -type configScraperR struct { - ScraperConfigItems ConfigItemSlice `boil:"ScraperConfigItems" json:"ScraperConfigItems" toml:"ScraperConfigItems" yaml:"ScraperConfigItems"` -} - -// NewStruct creates a new relationship struct -func (*configScraperR) NewStruct() *configScraperR { - return &configScraperR{} -} - -// configScraperL is where Load methods for each relationship are stored. -type configScraperL struct{} - -var ( - configScraperAllColumns = []string{"id", "description", "scraper_type", "spec", "created_at", "updated_at"} - configScraperColumnsWithoutDefault = []string{"description", "scraper_type", "spec"} - configScraperColumnsWithDefault = []string{"id", "created_at", "updated_at"} - configScraperPrimaryKeyColumns = []string{"id"} -) - -type ( - // ConfigScraperSlice is an alias for a slice of pointers to ConfigScraper. - // This should almost always be used instead of []ConfigScraper. - ConfigScraperSlice []*ConfigScraper - // ConfigScraperHook is the signature for custom ConfigScraper hook methods - ConfigScraperHook func(boil.Executor, *ConfigScraper) error - - configScraperQuery struct { - *queries.Query - } -) - -// Cache for insert, update and upsert -var ( - configScraperType = reflect.TypeOf(&ConfigScraper{}) - configScraperMapping = queries.MakeStructMapping(configScraperType) - configScraperPrimaryKeyMapping, _ = queries.BindMapping(configScraperType, configScraperMapping, configScraperPrimaryKeyColumns) - configScraperInsertCacheMut sync.RWMutex - configScraperInsertCache = make(map[string]insertCache) - configScraperUpdateCacheMut sync.RWMutex - configScraperUpdateCache = make(map[string]updateCache) - configScraperUpsertCacheMut sync.RWMutex - configScraperUpsertCache = 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 configScraperBeforeInsertHooks []ConfigScraperHook -var configScraperBeforeUpdateHooks []ConfigScraperHook -var configScraperBeforeDeleteHooks []ConfigScraperHook -var configScraperBeforeUpsertHooks []ConfigScraperHook - -var configScraperAfterInsertHooks []ConfigScraperHook -var configScraperAfterSelectHooks []ConfigScraperHook -var configScraperAfterUpdateHooks []ConfigScraperHook -var configScraperAfterDeleteHooks []ConfigScraperHook -var configScraperAfterUpsertHooks []ConfigScraperHook - -// doBeforeInsertHooks executes all "before insert" hooks. -func (o *ConfigScraper) doBeforeInsertHooks(exec boil.Executor) (err error) { - for _, hook := range configScraperBeforeInsertHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doBeforeUpdateHooks executes all "before Update" hooks. -func (o *ConfigScraper) doBeforeUpdateHooks(exec boil.Executor) (err error) { - for _, hook := range configScraperBeforeUpdateHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doBeforeDeleteHooks executes all "before Delete" hooks. -func (o *ConfigScraper) doBeforeDeleteHooks(exec boil.Executor) (err error) { - for _, hook := range configScraperBeforeDeleteHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doBeforeUpsertHooks executes all "before Upsert" hooks. -func (o *ConfigScraper) doBeforeUpsertHooks(exec boil.Executor) (err error) { - for _, hook := range configScraperBeforeUpsertHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doAfterInsertHooks executes all "after Insert" hooks. -func (o *ConfigScraper) doAfterInsertHooks(exec boil.Executor) (err error) { - for _, hook := range configScraperAfterInsertHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doAfterSelectHooks executes all "after Select" hooks. -func (o *ConfigScraper) doAfterSelectHooks(exec boil.Executor) (err error) { - for _, hook := range configScraperAfterSelectHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doAfterUpdateHooks executes all "after Update" hooks. -func (o *ConfigScraper) doAfterUpdateHooks(exec boil.Executor) (err error) { - for _, hook := range configScraperAfterUpdateHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doAfterDeleteHooks executes all "after Delete" hooks. -func (o *ConfigScraper) doAfterDeleteHooks(exec boil.Executor) (err error) { - for _, hook := range configScraperAfterDeleteHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// doAfterUpsertHooks executes all "after Upsert" hooks. -func (o *ConfigScraper) doAfterUpsertHooks(exec boil.Executor) (err error) { - for _, hook := range configScraperAfterUpsertHooks { - if err := hook(exec, o); err != nil { - return err - } - } - - return nil -} - -// AddConfigScraperHook registers your hook function for all future operations. -func AddConfigScraperHook(hookPoint boil.HookPoint, configScraperHook ConfigScraperHook) { - switch hookPoint { - case boil.BeforeInsertHook: - configScraperBeforeInsertHooks = append(configScraperBeforeInsertHooks, configScraperHook) - case boil.BeforeUpdateHook: - configScraperBeforeUpdateHooks = append(configScraperBeforeUpdateHooks, configScraperHook) - case boil.BeforeDeleteHook: - configScraperBeforeDeleteHooks = append(configScraperBeforeDeleteHooks, configScraperHook) - case boil.BeforeUpsertHook: - configScraperBeforeUpsertHooks = append(configScraperBeforeUpsertHooks, configScraperHook) - case boil.AfterInsertHook: - configScraperAfterInsertHooks = append(configScraperAfterInsertHooks, configScraperHook) - case boil.AfterSelectHook: - configScraperAfterSelectHooks = append(configScraperAfterSelectHooks, configScraperHook) - case boil.AfterUpdateHook: - configScraperAfterUpdateHooks = append(configScraperAfterUpdateHooks, configScraperHook) - case boil.AfterDeleteHook: - configScraperAfterDeleteHooks = append(configScraperAfterDeleteHooks, configScraperHook) - case boil.AfterUpsertHook: - configScraperAfterUpsertHooks = append(configScraperAfterUpsertHooks, configScraperHook) - } -} - -// OneG returns a single configScraper record from the query using the global executor. -func (q configScraperQuery) OneG() (*ConfigScraper, error) { - return q.One(boil.GetDB()) -} - -// One returns a single configScraper record from the query. -func (q configScraperQuery) One(exec boil.Executor) (*ConfigScraper, error) { - o := &ConfigScraper{} - - queries.SetLimit(q.Query, 1) - - err := q.Bind(nil, exec, o) - if err != nil { - if errors.Cause(err) == sql.ErrNoRows { - return nil, sql.ErrNoRows - } - return nil, errors.Wrap(err, "models: failed to execute a one query for config_scraper") - } - - if err := o.doAfterSelectHooks(exec); err != nil { - return o, err - } - - return o, nil -} - -// AllG returns all ConfigScraper records from the query using the global executor. -func (q configScraperQuery) AllG() (ConfigScraperSlice, error) { - return q.All(boil.GetDB()) -} - -// All returns all ConfigScraper records from the query. -func (q configScraperQuery) All(exec boil.Executor) (ConfigScraperSlice, error) { - var o []*ConfigScraper - - err := q.Bind(nil, exec, &o) - if err != nil { - return nil, errors.Wrap(err, "models: failed to assign all query results to ConfigScraper slice") - } - - if len(configScraperAfterSelectHooks) != 0 { - for _, obj := range o { - if err := obj.doAfterSelectHooks(exec); err != nil { - return o, err - } - } - } - - return o, nil -} - -// CountG returns the count of all ConfigScraper records in the query, and panics on error. -func (q configScraperQuery) CountG() (int64, error) { - return q.Count(boil.GetDB()) -} - -// Count returns the count of all ConfigScraper records in the query. -func (q configScraperQuery) Count(exec boil.Executor) (int64, error) { - var count int64 - - queries.SetSelect(q.Query, nil) - queries.SetCount(q.Query) - - err := q.Query.QueryRow(exec).Scan(&count) - if err != nil { - return 0, errors.Wrap(err, "models: failed to count config_scraper rows") - } - - return count, nil -} - -// ExistsG checks if the row exists in the table, and panics on error. -func (q configScraperQuery) ExistsG() (bool, error) { - return q.Exists(boil.GetDB()) -} - -// Exists checks if the row exists in the table. -func (q configScraperQuery) Exists(exec boil.Executor) (bool, error) { - var count int64 - - queries.SetSelect(q.Query, nil) - queries.SetCount(q.Query) - queries.SetLimit(q.Query, 1) - - err := q.Query.QueryRow(exec).Scan(&count) - if err != nil { - return false, errors.Wrap(err, "models: failed to check if config_scraper exists") - } - - return count > 0, nil -} - -// ScraperConfigItems retrieves all the config_item's ConfigItems with an executor via scraper_id column. -func (o *ConfigScraper) ScraperConfigItems(mods ...qm.QueryMod) configItemQuery { - var queryMods []qm.QueryMod - if len(mods) != 0 { - queryMods = append(queryMods, mods...) - } - - queryMods = append(queryMods, - qm.Where("\"config_item\".\"scraper_id\"=?", o.ID), - ) - - query := ConfigItems(queryMods...) - queries.SetFrom(query.Query, "\"config_item\"") - - if len(queries.GetSelect(query.Query)) == 0 { - queries.SetSelect(query.Query, []string{"\"config_item\".*"}) - } - - return query -} - -// LoadScraperConfigItems 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 (configScraperL) LoadScraperConfigItems(e boil.Executor, singular bool, maybeConfigScraper interface{}, mods queries.Applicator) error { - var slice []*ConfigScraper - var object *ConfigScraper - - if singular { - object = maybeConfigScraper.(*ConfigScraper) - } else { - slice = *maybeConfigScraper.(*[]*ConfigScraper) - } - - args := make([]interface{}, 0, 1) - if singular { - if object.R == nil { - object.R = &configScraperR{} - } - args = append(args, object.ID) - } else { - Outer: - for _, obj := range slice { - if obj.R == nil { - obj.R = &configScraperR{} - } - - for _, a := range args { - if queries.Equal(a, obj.ID) { - continue Outer - } - } - - args = append(args, obj.ID) - } - } - - if len(args) == 0 { - return nil - } - - query := NewQuery( - qm.From(`config_item`), - qm.WhereIn(`config_item.scraper_id in ?`, args...), - ) - if mods != nil { - mods.Apply(query) - } - - results, err := query.Query(e) - if err != nil { - return errors.Wrap(err, "failed to eager load config_item") - } - - var resultSlice []*ConfigItem - if err = queries.Bind(results, &resultSlice); err != nil { - return errors.Wrap(err, "failed to bind eager loaded slice config_item") - } - - if err = results.Close(); err != nil { - return errors.Wrap(err, "failed to close results in eager load on config_item") - } - if err = results.Err(); err != nil { - return errors.Wrap(err, "error occurred during iteration of eager loaded relations for config_item") - } - - if len(configItemAfterSelectHooks) != 0 { - for _, obj := range resultSlice { - if err := obj.doAfterSelectHooks(e); err != nil { - return err - } - } - } - if singular { - object.R.ScraperConfigItems = resultSlice - for _, foreign := range resultSlice { - if foreign.R == nil { - foreign.R = &configItemR{} - } - foreign.R.Scraper = object - } - return nil - } - - for _, foreign := range resultSlice { - for _, local := range slice { - if queries.Equal(local.ID, foreign.ScraperID) { - local.R.ScraperConfigItems = append(local.R.ScraperConfigItems, foreign) - if foreign.R == nil { - foreign.R = &configItemR{} - } - foreign.R.Scraper = local - break - } - } - } - - return nil -} - -// AddScraperConfigItemsG adds the given related objects to the existing relationships -// of the config_scraper, optionally inserting them as new records. -// Appends related to o.R.ScraperConfigItems. -// Sets related.R.Scraper appropriately. -// Uses the global database handle. -func (o *ConfigScraper) AddScraperConfigItemsG(insert bool, related ...*ConfigItem) error { - return o.AddScraperConfigItems(boil.GetDB(), insert, related...) -} - -// AddScraperConfigItems adds the given related objects to the existing relationships -// of the config_scraper, optionally inserting them as new records. -// Appends related to o.R.ScraperConfigItems. -// Sets related.R.Scraper appropriately. -func (o *ConfigScraper) AddScraperConfigItems(exec boil.Executor, insert bool, related ...*ConfigItem) error { - var err error - for _, rel := range related { - if insert { - queries.Assign(&rel.ScraperID, o.ID) - if err = rel.Insert(exec, boil.Infer()); err != nil { - return errors.Wrap(err, "failed to insert into foreign table") - } - } else { - updateQuery := fmt.Sprintf( - "UPDATE \"config_item\" SET %s WHERE %s", - strmangle.SetParamNames("\"", "\"", 1, []string{"scraper_id"}), - strmangle.WhereClause("\"", "\"", 2, configItemPrimaryKeyColumns), - ) - values := []interface{}{o.ID, rel.ID} - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, updateQuery) - fmt.Fprintln(boil.DebugWriter, values) - } - if _, err = exec.Exec(updateQuery, values...); err != nil { - return errors.Wrap(err, "failed to update foreign table") - } - - queries.Assign(&rel.ScraperID, o.ID) - } - } - - if o.R == nil { - o.R = &configScraperR{ - ScraperConfigItems: related, - } - } else { - o.R.ScraperConfigItems = append(o.R.ScraperConfigItems, related...) - } - - for _, rel := range related { - if rel.R == nil { - rel.R = &configItemR{ - Scraper: o, - } - } else { - rel.R.Scraper = o - } - } - return nil -} - -// SetScraperConfigItemsG removes all previously related items of the -// config_scraper replacing them completely with the passed -// in related items, optionally inserting them as new records. -// Sets o.R.Scraper's ScraperConfigItems accordingly. -// Replaces o.R.ScraperConfigItems with related. -// Sets related.R.Scraper's ScraperConfigItems accordingly. -// Uses the global database handle. -func (o *ConfigScraper) SetScraperConfigItemsG(insert bool, related ...*ConfigItem) error { - return o.SetScraperConfigItems(boil.GetDB(), insert, related...) -} - -// SetScraperConfigItems removes all previously related items of the -// config_scraper replacing them completely with the passed -// in related items, optionally inserting them as new records. -// Sets o.R.Scraper's ScraperConfigItems accordingly. -// Replaces o.R.ScraperConfigItems with related. -// Sets related.R.Scraper's ScraperConfigItems accordingly. -func (o *ConfigScraper) SetScraperConfigItems(exec boil.Executor, insert bool, related ...*ConfigItem) error { - query := "update \"config_item\" set \"scraper_id\" = null where \"scraper_id\" = $1" - values := []interface{}{o.ID} - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, query) - fmt.Fprintln(boil.DebugWriter, values) - } - _, err := exec.Exec(query, values...) - if err != nil { - return errors.Wrap(err, "failed to remove relationships before set") - } - - if o.R != nil { - for _, rel := range o.R.ScraperConfigItems { - queries.SetScanner(&rel.ScraperID, nil) - if rel.R == nil { - continue - } - - rel.R.Scraper = nil - } - - o.R.ScraperConfigItems = nil - } - return o.AddScraperConfigItems(exec, insert, related...) -} - -// RemoveScraperConfigItemsG relationships from objects passed in. -// Removes related items from R.ScraperConfigItems (uses pointer comparison, removal does not keep order) -// Sets related.R.Scraper. -// Uses the global database handle. -func (o *ConfigScraper) RemoveScraperConfigItemsG(related ...*ConfigItem) error { - return o.RemoveScraperConfigItems(boil.GetDB(), related...) -} - -// RemoveScraperConfigItems relationships from objects passed in. -// Removes related items from R.ScraperConfigItems (uses pointer comparison, removal does not keep order) -// Sets related.R.Scraper. -func (o *ConfigScraper) RemoveScraperConfigItems(exec boil.Executor, related ...*ConfigItem) error { - if len(related) == 0 { - return nil - } - - var err error - for _, rel := range related { - queries.SetScanner(&rel.ScraperID, nil) - if rel.R != nil { - rel.R.Scraper = nil - } - if _, err = rel.Update(exec, boil.Whitelist("scraper_id")); err != nil { - return err - } - } - if o.R == nil { - return nil - } - - for _, rel := range related { - for i, ri := range o.R.ScraperConfigItems { - if rel != ri { - continue - } - - ln := len(o.R.ScraperConfigItems) - if ln > 1 && i < ln-1 { - o.R.ScraperConfigItems[i] = o.R.ScraperConfigItems[ln-1] - } - o.R.ScraperConfigItems = o.R.ScraperConfigItems[:ln-1] - break - } - } - - return nil -} - -// ConfigScrapers retrieves all the records using an executor. -func ConfigScrapers(mods ...qm.QueryMod) configScraperQuery { - mods = append(mods, qm.From("\"config_scraper\"")) - return configScraperQuery{NewQuery(mods...)} -} - -// FindConfigScraperG retrieves a single record by ID. -func FindConfigScraperG(iD string, selectCols ...string) (*ConfigScraper, error) { - return FindConfigScraper(boil.GetDB(), iD, selectCols...) -} - -// FindConfigScraper retrieves a single record by ID with an executor. -// If selectCols is empty Find will return all columns. -func FindConfigScraper(exec boil.Executor, iD string, selectCols ...string) (*ConfigScraper, error) { - configScraperObj := &ConfigScraper{} - - sel := "*" - if len(selectCols) > 0 { - sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",") - } - query := fmt.Sprintf( - "select %s from \"config_scraper\" where \"id\"=$1", sel, - ) - - q := queries.Raw(query, iD) - - err := q.Bind(nil, exec, configScraperObj) - if err != nil { - if errors.Cause(err) == sql.ErrNoRows { - return nil, sql.ErrNoRows - } - return nil, errors.Wrap(err, "models: unable to select from config_scraper") - } - - if err = configScraperObj.doAfterSelectHooks(exec); err != nil { - return configScraperObj, err - } - - return configScraperObj, nil -} - -// InsertG a single record. See Insert for whitelist behavior description. -func (o *ConfigScraper) InsertG(columns boil.Columns) error { - return o.Insert(boil.GetDB(), columns) -} - -// Insert a single record using an executor. -// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts. -func (o *ConfigScraper) Insert(exec boil.Executor, columns boil.Columns) error { - if o == nil { - return errors.New("models: no config_scraper provided for insertion") - } - - var err error - currTime := time.Now().In(boil.GetLocation()) - - if o.CreatedAt.IsZero() { - o.CreatedAt = currTime - } - if o.UpdatedAt.IsZero() { - o.UpdatedAt = currTime - } - - if err := o.doBeforeInsertHooks(exec); err != nil { - return err - } - - nzDefaults := queries.NonZeroDefaultSet(configScraperColumnsWithDefault, o) - - key := makeCacheKey(columns, nzDefaults) - configScraperInsertCacheMut.RLock() - cache, cached := configScraperInsertCache[key] - configScraperInsertCacheMut.RUnlock() - - if !cached { - wl, returnColumns := columns.InsertColumnSet( - configScraperAllColumns, - configScraperColumnsWithDefault, - configScraperColumnsWithoutDefault, - nzDefaults, - ) - - cache.valueMapping, err = queries.BindMapping(configScraperType, configScraperMapping, wl) - if err != nil { - return err - } - cache.retMapping, err = queries.BindMapping(configScraperType, configScraperMapping, returnColumns) - if err != nil { - return err - } - if len(wl) != 0 { - cache.query = fmt.Sprintf("INSERT INTO \"config_scraper\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1)) - } else { - cache.query = "INSERT INTO \"config_scraper\" %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.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, vals) - } - - if len(cache.retMapping) != 0 { - err = exec.QueryRow(cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...) - } else { - _, err = exec.Exec(cache.query, vals...) - } - - if err != nil { - return errors.Wrap(err, "models: unable to insert into config_scraper") - } - - if !cached { - configScraperInsertCacheMut.Lock() - configScraperInsertCache[key] = cache - configScraperInsertCacheMut.Unlock() - } - - return o.doAfterInsertHooks(exec) -} - -// UpdateG a single ConfigScraper record using the global executor. -// See Update for more documentation. -func (o *ConfigScraper) UpdateG(columns boil.Columns) (int64, error) { - return o.Update(boil.GetDB(), columns) -} - -// Update uses an executor to update the ConfigScraper. -// 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 *ConfigScraper) Update(exec boil.Executor, columns boil.Columns) (int64, error) { - currTime := time.Now().In(boil.GetLocation()) - - o.UpdatedAt = currTime - - var err error - if err = o.doBeforeUpdateHooks(exec); err != nil { - return 0, err - } - key := makeCacheKey(columns, nil) - configScraperUpdateCacheMut.RLock() - cache, cached := configScraperUpdateCache[key] - configScraperUpdateCacheMut.RUnlock() - - if !cached { - wl := columns.UpdateColumnSet( - configScraperAllColumns, - configScraperPrimaryKeyColumns, - ) - - if !columns.IsWhitelist() { - wl = strmangle.SetComplement(wl, []string{"created_at"}) - } - if len(wl) == 0 { - return 0, errors.New("models: unable to update config_scraper, could not build whitelist") - } - - cache.query = fmt.Sprintf("UPDATE \"config_scraper\" SET %s WHERE %s", - strmangle.SetParamNames("\"", "\"", 1, wl), - strmangle.WhereClause("\"", "\"", len(wl)+1, configScraperPrimaryKeyColumns), - ) - cache.valueMapping, err = queries.BindMapping(configScraperType, configScraperMapping, append(wl, configScraperPrimaryKeyColumns...)) - if err != nil { - return 0, err - } - } - - values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, cache.query) - fmt.Fprintln(boil.DebugWriter, values) - } - var result sql.Result - result, err = exec.Exec(cache.query, values...) - if err != nil { - return 0, errors.Wrap(err, "models: unable to update config_scraper row") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: failed to get rows affected by update for config_scraper") - } - - if !cached { - configScraperUpdateCacheMut.Lock() - configScraperUpdateCache[key] = cache - configScraperUpdateCacheMut.Unlock() - } - - return rowsAff, o.doAfterUpdateHooks(exec) -} - -// UpdateAllG updates all rows with the specified column values. -func (q configScraperQuery) UpdateAllG(cols M) (int64, error) { - return q.UpdateAll(boil.GetDB(), cols) -} - -// UpdateAll updates all rows with the specified column values. -func (q configScraperQuery) UpdateAll(exec boil.Executor, cols M) (int64, error) { - queries.SetUpdate(q.Query, cols) - - result, err := q.Query.Exec(exec) - if err != nil { - return 0, errors.Wrap(err, "models: unable to update all for config_scraper") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: unable to retrieve rows affected for config_scraper") - } - - return rowsAff, nil -} - -// UpdateAllG updates all rows with the specified column values. -func (o ConfigScraperSlice) UpdateAllG(cols M) (int64, error) { - return o.UpdateAll(boil.GetDB(), cols) -} - -// UpdateAll updates all rows with the specified column values, using an executor. -func (o ConfigScraperSlice) UpdateAll(exec boil.Executor, 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)), configScraperPrimaryKeyMapping) - args = append(args, pkeyArgs...) - } - - sql := fmt.Sprintf("UPDATE \"config_scraper\" SET %s WHERE %s", - strmangle.SetParamNames("\"", "\"", 1, colNames), - strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, configScraperPrimaryKeyColumns, len(o))) - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) - } - result, err := exec.Exec(sql, args...) - if err != nil { - return 0, errors.Wrap(err, "models: unable to update all in configScraper slice") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all configScraper") - } - return rowsAff, nil -} - -// UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *ConfigScraper) UpsertG(updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - return o.Upsert(boil.GetDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) -} - -// 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 *ConfigScraper) Upsert(exec boil.Executor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { - if o == nil { - return errors.New("models: no config_scraper provided for upsert") - } - currTime := time.Now().In(boil.GetLocation()) - - if o.CreatedAt.IsZero() { - o.CreatedAt = currTime - } - o.UpdatedAt = currTime - - if err := o.doBeforeUpsertHooks(exec); err != nil { - return err - } - - nzDefaults := queries.NonZeroDefaultSet(configScraperColumnsWithDefault, 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) - - configScraperUpsertCacheMut.RLock() - cache, cached := configScraperUpsertCache[key] - configScraperUpsertCacheMut.RUnlock() - - var err error - - if !cached { - insert, ret := insertColumns.InsertColumnSet( - configScraperAllColumns, - configScraperColumnsWithDefault, - configScraperColumnsWithoutDefault, - nzDefaults, - ) - update := updateColumns.UpdateColumnSet( - configScraperAllColumns, - configScraperPrimaryKeyColumns, - ) - - if updateOnConflict && len(update) == 0 { - return errors.New("models: unable to upsert config_scraper, could not build update column list") - } - - conflict := conflictColumns - if len(conflict) == 0 { - conflict = make([]string, len(configScraperPrimaryKeyColumns)) - copy(conflict, configScraperPrimaryKeyColumns) - } - cache.query = buildUpsertQueryPostgres(dialect, "\"config_scraper\"", updateOnConflict, ret, update, conflict, insert) - - cache.valueMapping, err = queries.BindMapping(configScraperType, configScraperMapping, insert) - if err != nil { - return err - } - if len(ret) != 0 { - cache.retMapping, err = queries.BindMapping(configScraperType, configScraperMapping, 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.QueryRow(cache.query, vals...).Scan(returns...) - if err == sql.ErrNoRows { - err = nil // Postgres doesn't return anything when there's no update - } - } else { - _, err = exec.Exec(cache.query, vals...) - } - if err != nil { - return errors.Wrap(err, "models: unable to upsert config_scraper") - } - - if !cached { - configScraperUpsertCacheMut.Lock() - configScraperUpsertCache[key] = cache - configScraperUpsertCacheMut.Unlock() - } - - return o.doAfterUpsertHooks(exec) -} - -// DeleteG deletes a single ConfigScraper record. -// DeleteG will match against the primary key column to find the record to delete. -func (o *ConfigScraper) DeleteG() (int64, error) { - return o.Delete(boil.GetDB()) -} - -// Delete deletes a single ConfigScraper record with an executor. -// Delete will match against the primary key column to find the record to delete. -func (o *ConfigScraper) Delete(exec boil.Executor) (int64, error) { - if o == nil { - return 0, errors.New("models: no ConfigScraper provided for delete") - } - - if err := o.doBeforeDeleteHooks(exec); err != nil { - return 0, err - } - - args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), configScraperPrimaryKeyMapping) - sql := "DELETE FROM \"config_scraper\" WHERE \"id\"=$1" - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args...) - } - result, err := exec.Exec(sql, args...) - if err != nil { - return 0, errors.Wrap(err, "models: unable to delete from config_scraper") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: failed to get rows affected by delete for config_scraper") - } - - if err := o.doAfterDeleteHooks(exec); err != nil { - return 0, err - } - - return rowsAff, nil -} - -func (q configScraperQuery) DeleteAllG() (int64, error) { - return q.DeleteAll(boil.GetDB()) -} - -// DeleteAll deletes all matching rows. -func (q configScraperQuery) DeleteAll(exec boil.Executor) (int64, error) { - if q.Query == nil { - return 0, errors.New("models: no configScraperQuery provided for delete all") - } - - queries.SetDelete(q.Query) - - result, err := q.Query.Exec(exec) - if err != nil { - return 0, errors.Wrap(err, "models: unable to delete all from config_scraper") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for config_scraper") - } - - return rowsAff, nil -} - -// DeleteAllG deletes all rows in the slice. -func (o ConfigScraperSlice) DeleteAllG() (int64, error) { - return o.DeleteAll(boil.GetDB()) -} - -// DeleteAll deletes all rows in the slice, using an executor. -func (o ConfigScraperSlice) DeleteAll(exec boil.Executor) (int64, error) { - if len(o) == 0 { - return 0, nil - } - - if len(configScraperBeforeDeleteHooks) != 0 { - for _, obj := range o { - if err := obj.doBeforeDeleteHooks(exec); err != nil { - return 0, err - } - } - } - - var args []interface{} - for _, obj := range o { - pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), configScraperPrimaryKeyMapping) - args = append(args, pkeyArgs...) - } - - sql := "DELETE FROM \"config_scraper\" WHERE " + - strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, configScraperPrimaryKeyColumns, len(o)) - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, args) - } - result, err := exec.Exec(sql, args...) - if err != nil { - return 0, errors.Wrap(err, "models: unable to delete all from configScraper slice") - } - - rowsAff, err := result.RowsAffected() - if err != nil { - return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for config_scraper") - } - - if len(configScraperAfterDeleteHooks) != 0 { - for _, obj := range o { - if err := obj.doAfterDeleteHooks(exec); err != nil { - return 0, err - } - } - } - - return rowsAff, nil -} - -// ReloadG refetches the object from the database using the primary keys. -func (o *ConfigScraper) ReloadG() error { - if o == nil { - return errors.New("models: no ConfigScraper provided for reload") - } - - return o.Reload(boil.GetDB()) -} - -// Reload refetches the object from the database -// using the primary keys with an executor. -func (o *ConfigScraper) Reload(exec boil.Executor) error { - ret, err := FindConfigScraper(exec, o.ID) - if err != nil { - return err - } - - *o = *ret - return nil -} - -// ReloadAllG refetches every row with matching primary key column values -// and overwrites the original object slice with the newly updated slice. -func (o *ConfigScraperSlice) ReloadAllG() error { - if o == nil { - return errors.New("models: empty ConfigScraperSlice provided for reload all") - } - - return o.ReloadAll(boil.GetDB()) -} - -// ReloadAll refetches every row with matching primary key column values -// and overwrites the original object slice with the newly updated slice. -func (o *ConfigScraperSlice) ReloadAll(exec boil.Executor) error { - if o == nil || len(*o) == 0 { - return nil - } - - slice := ConfigScraperSlice{} - var args []interface{} - for _, obj := range *o { - pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), configScraperPrimaryKeyMapping) - args = append(args, pkeyArgs...) - } - - sql := "SELECT \"config_scraper\".* FROM \"config_scraper\" WHERE " + - strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, configScraperPrimaryKeyColumns, len(*o)) - - q := queries.Raw(sql, args...) - - err := q.Bind(nil, exec, &slice) - if err != nil { - return errors.Wrap(err, "models: unable to reload all in ConfigScraperSlice") - } - - *o = slice - - return nil -} - -// ConfigScraperExistsG checks if the ConfigScraper row exists. -func ConfigScraperExistsG(iD string) (bool, error) { - return ConfigScraperExists(boil.GetDB(), iD) -} - -// ConfigScraperExists checks if the ConfigScraper row exists. -func ConfigScraperExists(exec boil.Executor, iD string) (bool, error) { - var exists bool - sql := "select exists(select 1 from \"config_scraper\" where \"id\"=$1 limit 1)" - - if boil.DebugMode { - fmt.Fprintln(boil.DebugWriter, sql) - fmt.Fprintln(boil.DebugWriter, iD) - } - row := exec.QueryRow(sql, iD) - - err := row.Scan(&exists) - if err != nil { - return false, errors.Wrap(err, "models: unable to check if config_scraper exists") - } - - return exists, nil -} diff --git a/db/models/psql_upsert.go b/db/models/psql_upsert.go deleted file mode 100644 index e17215d7..00000000 --- a/db/models/psql_upsert.go +++ /dev/null @@ -1,61 +0,0 @@ -// Code generated by SQLBoiler 4.8.3 (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 ( - "fmt" - "strings" - - "github.com/volatiletech/sqlboiler/v4/drivers" - "github.com/volatiletech/strmangle" -) - -// buildUpsertQueryPostgres builds a SQL statement string using the upsertData provided. -func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string { - conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict) - whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist) - ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret) - - buf := strmangle.GetBuffer() - defer strmangle.PutBuffer(buf) - - columns := "DEFAULT VALUES" - if len(whitelist) != 0 { - columns = fmt.Sprintf("(%s) VALUES (%s)", - strings.Join(whitelist, ", "), - strmangle.Placeholders(dia.UseIndexPlaceholders, len(whitelist), 1, 1)) - } - - fmt.Fprintf( - buf, - "INSERT INTO %s %s ON CONFLICT ", - tableName, - columns, - ) - - if !updateOnConflict || len(update) == 0 { - buf.WriteString("DO NOTHING") - } else { - buf.WriteByte('(') - buf.WriteString(strings.Join(conflict, ", ")) - buf.WriteString(") DO UPDATE SET ") - - for i, v := range update { - if i != 0 { - buf.WriteByte(',') - } - quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) - buf.WriteString(quoted) - buf.WriteString(" = EXCLUDED.") - buf.WriteString(quoted) - } - } - - if len(ret) != 0 { - buf.WriteString(" RETURNING ") - buf.WriteString(strings.Join(ret, ", ")) - } - - return buf.String() -} diff --git a/db/postgrest.go b/db/postgrest.go index 4c7975b8..f3acdaf7 100644 --- a/db/postgrest.go +++ b/db/postgrest.go @@ -5,8 +5,10 @@ import ( "github.com/flanksource/commons/logger" ) +// PostgRESTVersion ... var PostgRESTVersion = "v9.0.0" +// GoOffline ... func GoOffline() error { return getBinary()("--help") } @@ -16,10 +18,12 @@ func getBinary() deps.BinaryFunc { "PGRST_DB_URI": ConnectionString, "PGRST_DB_SCHEMA": Schema, "PGRST_DB_ANON_ROLE": "postgrest_api", - "PGRST_OPENAPI_SERVER_PROXY_URI": HttpEndpoint, + "PGRST_OPENAPI_SERVER_PROXY_URI": HTTPEndpoint, "PGRST_LOG_LEVEL": LogLevel, }) } + +// StartPostgrest ... func StartPostgrest() { if err := getBinary()(""); err != nil { logger.Errorf("Failed to start postgREST: %v", err) diff --git a/db/repository/config_item.go b/db/repository/config_item.go new file mode 100644 index 00000000..f583cec6 --- /dev/null +++ b/db/repository/config_item.go @@ -0,0 +1,59 @@ +package repository + +import ( + "github.com/flanksource/confighub/db/models" + "gorm.io/gorm" +) + +// DBRepo should satisfy the database repository interface +type DBRepo struct { + db *gorm.DB +} + +// NewRepo is the factory function for the database repo instance +func NewRepo(db *gorm.DB) Database { + return &DBRepo{ + db: db, + } +} + +// GetConfigItem returns a single config item result +func (d *DBRepo) GetConfigItem(extID string) (*models.ConfigItem, error) { + + ci := models.ConfigItem{} + if err := d.db.First(&ci, "external_id = ?", extID).Error; err != nil { + return nil, err + } + + return &ci, nil +} + +// CreateConfigItem inserts a new config item row in the db +func (d *DBRepo) CreateConfigItem(ci *models.ConfigItem) error { + + if err := d.db.Create(ci).Error; err != nil { + return err + } + + return nil +} + +// UpdateConfigItem updates all the fields of a given config item row +func (d *DBRepo) UpdateConfigItem(ci *models.ConfigItem) error { + + if err := d.db.Save(ci).Error; err != nil { + return err + } + + return nil +} + +// CreateConfigChange inserts a new config change row in the db +func (d *DBRepo) CreateConfigChange(cc *models.ConfigChange) error { + + if err := d.db.Create(cc).Error; err != nil { + return err + } + + return nil +} diff --git a/db/repository/interface.go b/db/repository/interface.go new file mode 100644 index 00000000..5fcc56e2 --- /dev/null +++ b/db/repository/interface.go @@ -0,0 +1,11 @@ +package repository + +import "github.com/flanksource/confighub/db/models" + +// Database holds all the repository function contracts +type Database interface { + GetConfigItem(string) (*models.ConfigItem, error) + CreateConfigItem(*models.ConfigItem) error + UpdateConfigItem(*models.ConfigItem) error + CreateConfigChange(*models.ConfigChange) error +} diff --git a/db/update.go b/db/update.go index 20dd22b8..944bc77c 100644 --- a/db/update.go +++ b/db/update.go @@ -1,35 +1,35 @@ package db import ( - "database/sql" "encoding/json" jsonpatch "github.com/evanphx/json-patch" "github.com/flanksource/commons/logger" v1 "github.com/flanksource/confighub/api/v1" "github.com/flanksource/confighub/db/models" - . "github.com/flanksource/confighub/db/models" + "github.com/flanksource/confighub/db/repository" "github.com/flanksource/confighub/db/ulid" cmap "github.com/orcaman/concurrent-map" - "github.com/volatiletech/null/v8" - "github.com/volatiletech/sqlboiler/v4/boil" + "gorm.io/gorm" ) var idCache = cmap.New() -func NewConfigItemFromResult(result v1.ScrapeResult) ConfigItem { - return ConfigItem{ +// NewConfigItemFromResult creates a new config item instance from result +func NewConfigItemFromResult(result v1.ScrapeResult) models.ConfigItem { + return models.ConfigItem{ ConfigType: result.Type, - ExternalID: null.StringFrom(result.Id), - Account: null.StringFrom(result.Account), - Region: null.StringFrom(result.Region), - Zone: null.StringFrom(result.Zone), - Network: null.StringFrom(result.Network), - Subnet: null.StringFrom(result.Subnet), - Name: null.StringFrom(result.Name), + ExternalID: &result.Id, + Account: &result.Account, + Region: &result.Region, + Zone: &result.Zone, + Network: &result.Network, + Subnet: &result.Subnet, + Name: &result.Name, } } +// Update creates or update a configuartion with config changes func Update(ctx v1.ScrapeContext, results []v1.ScrapeResult) error { // boil.DebugMode = true for _, result := range results { @@ -39,15 +39,18 @@ func Update(ctx v1.ScrapeContext, results []v1.ScrapeResult) error { } ci := NewConfigItemFromResult(result) - ci.Config = null.JSONFrom(data) + dataStr := string(data) + ci.Config = &dataStr - existing, err := models.ConfigItems(ConfigItemWhere.ExternalID.EQ(null.StringFrom(result.Id))).OneG() - if err != nil && err != sql.ErrNoRows { + repo := repository.NewRepo(DefaultDB()) + + existing, err := repo.GetConfigItem(result.Id) + if err != nil && err != gorm.ErrRecordNotFound { return err } - if err == sql.ErrNoRows { + if err == gorm.ErrRecordNotFound { ci.ID = ulid.MustNew().AsUUID() - if err := ci.InsertG(boil.Infer()); err != nil { + if err := repo.CreateConfigItem(&ci); err != nil { return err } continue @@ -55,7 +58,7 @@ func Update(ctx v1.ScrapeContext, results []v1.ScrapeResult) error { } ci.ID = existing.ID - if _, err := ci.UpdateG(boil.Infer()); err != nil { + if err := repo.UpdateConfigItem(&ci); err != nil { return err } changes, err := compare(ci, *existing) @@ -64,8 +67,8 @@ func Update(ctx v1.ScrapeContext, results []v1.ScrapeResult) error { } if changes != nil { - logger.Infof("[%s/%s] detected changes", ci.ConfigType, ci.ExternalID.String) - if err := changes.InsertG(boil.Infer()); err != nil { + logger.Infof("[%s/%s] detected changes", ci.ConfigType, *ci.ExternalID) + if err := repo.CreateConfigChange(changes); err != nil { return err } } @@ -82,11 +85,14 @@ func compare(a, b models.ConfigItem) (*models.ConfigChange, error) { if len(patch) <= 2 { // no patch or empty array return nil, nil } + + patchStr := string(patch) + return &models.ConfigChange{ ConfigID: a.ID, ChangeType: "diff", ID: ulid.MustNew().AsUUID(), - Patches: null.JSONFrom(patch), + Patches: &patchStr, }, nil } diff --git a/go.mod b/go.mod index a54bd1d8..cd23da3e 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,6 @@ require ( github.com/evanphx/json-patch v4.9.0+incompatible github.com/flanksource/commons v1.5.11 github.com/flanksource/kommons v0.26.0 - github.com/friendsofgo/errors v0.9.2 github.com/google/uuid v1.3.0 github.com/henvic/httpretty v0.0.6 github.com/jackc/pgx/v4 v4.14.1 @@ -28,10 +27,9 @@ require ( github.com/sirupsen/logrus v1.8.1 github.com/spf13/cobra v1.2.1 github.com/spf13/pflag v1.0.5 - github.com/volatiletech/null/v8 v8.1.2 - github.com/volatiletech/sqlboiler/v4 v4.8.3 - github.com/volatiletech/strmangle v0.0.1 gopkg.in/flanksource/yaml.v3 v3.1.1 + gorm.io/driver/postgres v1.3.1 + gorm.io/gorm v1.23.2 k8s.io/apimachinery v0.20.4 k8s.io/client-go v11.0.0+incompatible ) @@ -39,6 +37,7 @@ require ( require ( cloud.google.com/go v0.93.3 // indirect cloud.google.com/go/storage v1.10.0 // indirect + contrib.go.opencensus.io/integrations/ocsql v0.1.4 // indirect github.com/AlekSi/pointer v1.1.0 // indirect github.com/Masterminds/goutils v1.1.0 // indirect github.com/PuerkitoBio/purell v1.1.1 // indirect @@ -69,6 +68,7 @@ require ( github.com/emicklei/go-restful v2.9.5+incompatible // indirect github.com/emirpasic/gods v1.12.0 // indirect github.com/fatih/color v1.9.0 // indirect + github.com/friendsofgo/errors v0.9.2 // indirect github.com/ghodss/yaml v1.0.0 // indirect github.com/go-logr/logr v0.2.0 // indirect github.com/go-openapi/jsonpointer v0.19.3 // indirect @@ -119,6 +119,8 @@ require ( github.com/jackc/pgtype v1.9.1 // indirect github.com/jackc/puddle v1.2.0 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/jinzhu/now v1.1.4 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/joho/godotenv v1.3.0 // indirect github.com/json-iterator/go v1.1.11 // indirect @@ -126,6 +128,7 @@ require ( github.com/kr/pretty v0.2.1 // indirect github.com/kr/text v0.1.0 // indirect github.com/labstack/gommon v0.3.1 // indirect + github.com/lib/pq v1.10.3 // indirect github.com/mailru/easyjson v0.7.0 // indirect github.com/mattn/go-colorable v0.1.11 // indirect github.com/mattn/go-isatty v0.0.14 // indirect @@ -148,7 +151,10 @@ require ( github.com/valyala/fasttemplate v1.2.1 // indirect github.com/vbauerster/mpb/v5 v5.0.3 // indirect github.com/volatiletech/inflect v0.0.1 // indirect + github.com/volatiletech/null/v8 v8.1.2 // indirect github.com/volatiletech/randomize v0.0.1 // indirect + github.com/volatiletech/sqlboiler/v4 v4.8.3 // indirect + github.com/volatiletech/strmangle v0.0.1 // indirect github.com/xanzy/ssh-agent v0.2.1 // indirect github.com/zealic/xignore v0.3.3 // indirect go.etcd.io/etcd v0.5.0-alpha.5.0.20200910180754-dd1b699fc489 // indirect @@ -157,7 +163,7 @@ require ( go.uber.org/multierr v1.6.0 // indirect go.uber.org/zap v1.17.0 // indirect gocloud.dev v0.18.0 // indirect - golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect + golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect golang.org/x/sys v0.0.0-20211103235746-7861aae1554b // indirect diff --git a/go.sum b/go.sum index b5d03650..2e5baaa6 100644 --- a/go.sum +++ b/go.sum @@ -48,6 +48,7 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 contrib.go.opencensus.io/exporter/aws v0.0.0-20181029163544-2befc13012d0/go.mod h1:uu1P0UCM/6RbsMrgPa98ll8ZcHM858i/AD06a9aLRCA= contrib.go.opencensus.io/exporter/ocagent v0.5.0/go.mod h1:ImxhfLRpxoYiSq891pBrLVhN+qmP8BTVvdH2YLs7Gl0= contrib.go.opencensus.io/exporter/stackdriver v0.12.1/go.mod h1:iwB6wGarfphGGe/e5CWqyUk/cLzKnWsOKPVW3no6OTw= +contrib.go.opencensus.io/integrations/ocsql v0.1.4 h1:kfg5Yyy1nYUrqzyfW5XX+dzMASky8IJXhtHe0KTYNS4= contrib.go.opencensus.io/integrations/ocsql v0.1.4/go.mod h1:8DsSdjz3F+APR+0z0WkU1aRorQCFfRxvqjUUPMbF3fE= contrib.go.opencensus.io/resource v0.1.1/go.mod h1:F361eGI91LCmW1I/Saf+rX0+OFcigGlFvXwEGEnkRLA= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= @@ -591,6 +592,10 @@ github.com/jackc/puddle v1.2.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dv github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/now v1.1.4 h1:tHnRBy1i5F2Dh8BAFxqFzxKqqvezXrL2OW1TnX+Mlas= +github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= @@ -1013,6 +1018,8 @@ golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -1479,6 +1486,10 @@ gopkg.in/yaml.v3 v3.0.0-20190924164351-c8b7dadae555/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/driver/postgres v1.3.1 h1:Pyv+gg1Gq1IgsLYytj/S2k7ebII3CzEdpqQkPOdH24g= +gorm.io/driver/postgres v1.3.1/go.mod h1:WwvWOuR9unCLpGWCL6Y3JOeBWvbKi6JLhayiVclSZZU= +gorm.io/gorm v1.23.2 h1:xmq9QRMWL8HTJyhAUBXy8FqIIQCYESeKfJL4DoGKiWQ= +gorm.io/gorm v1.23.2/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= gotest.tools/v3 v3.0.0/go.mod h1:TUP+/YtXl/dp++T+SZ5v2zUmLVBHmptSb/ajDLCJ+3c=