diff --git a/internal/activities/healthcheck.go b/internal/activities/healthcheck.go index e97c119..d3a17df 100644 --- a/internal/activities/healthcheck.go +++ b/internal/activities/healthcheck.go @@ -2,55 +2,45 @@ package activities import ( "context" - "log" "net/http" + + "code.tjo.space/mentos1386/zdravko/pkg/k6" + "go.k6.io/k6/cmd/state" ) -type HealtcheckHttpParam struct { - Url string - Method string +type HealtcheckParam struct { + Script string } -type HealthcheckHttpResult struct { +type HealthcheckResult struct { StatusCode int } -func HealthcheckHttp(ctx context.Context, param HealtcheckHttpParam) (*HealthcheckHttpResult, error) { - if param.Method == "" { - param.Method = "GET" - } +func Healthcheck(ctx context.Context, param HealtcheckParam) (*HealthcheckResult, error) { - var ( - response *http.Response - err error - ) + statusCode := http.StatusOK // FIXME - switch param.Method { - case "GET": - response, err = http.Get(param.Url) - case "POST": - response, err = http.Post(param.Url, "application/json", nil) - } + state := state.NewGlobalState(ctx) + execution := k6.NewExecution(state, param.Script) + err := execution.Start(ctx) if err != nil { return nil, err } - log.Printf("HealthcheckHttpActivityDefinition produced statuscode %d for url %s", response.StatusCode, param.Url) - - return &HealthcheckHttpResult{StatusCode: response.StatusCode}, nil + return &HealthcheckResult{StatusCode: statusCode}, nil } -type HealtcheckHttpAddToHistoryParam struct { +type HealtcheckAddToHistoryParam struct { Id string Success bool StatusCode int } -type HealthcheckHttpAddToHistoryResult struct { +type HealthcheckAddToHistoryResult struct { } -func HealthcheckHttpAddToHistory(ctx context.Context, param HealtcheckHttpAddToHistoryParam) (*HealthcheckHttpAddToHistoryResult, error) { +func HealthcheckAddToHistory(ctx context.Context, param HealtcheckAddToHistoryParam) (*HealthcheckAddToHistoryResult, error) { - return &HealthcheckHttpAddToHistoryResult{}, nil + return &HealthcheckAddToHistoryResult{}, nil } diff --git a/internal/database.go b/internal/database.go index f85976a..15f15b3 100644 --- a/internal/database.go +++ b/internal/database.go @@ -16,10 +16,8 @@ func ConnectToDatabase(path string) (*gorm.DB, *query.Query, error) { err = db.AutoMigrate( models.Worker{}, - models.HealthcheckHttp{}, - models.HealthcheckHttpHistory{}, - models.HealthcheckTcp{}, - models.HealthcheckTcpHistory{}, + models.Healthcheck{}, + models.HealthcheckHistory{}, models.Cronjob{}, models.CronjobHistory{}, models.OAuth2State{}, diff --git a/internal/handlers/api.go b/internal/handlers/api.go index 607c81f..ca6cd2b 100644 --- a/internal/handlers/api.go +++ b/internal/handlers/api.go @@ -35,13 +35,13 @@ func (h *BaseHandler) ApiV1HealthchecksHistoryPOST(c echo.Context) error { slug := c.Param("slug") - healthcheck, err := services.GetHealthcheckHttp(ctx, h.query, slug) + healthcheck, err := services.GetHealthcheck(ctx, h.query, slug) if err != nil { return err } - err = h.query.HealthcheckHttp.History.Model(healthcheck).Append( - &models.HealthcheckHttpHistory{ + err = h.query.Healthcheck.History.Model(healthcheck).Append( + &models.HealthcheckHistory{ Status: "UP", }) if err != nil { diff --git a/internal/handlers/settingshealthchecks.go b/internal/handlers/settingshealthchecks.go index 6e5da81..6093336 100644 --- a/internal/handlers/settingshealthchecks.go +++ b/internal/handlers/settingshealthchecks.go @@ -16,19 +16,19 @@ import ( type SettingsHealthchecks struct { *Settings - Healthchecks []*models.HealthcheckHttp + Healthchecks []*models.Healthcheck HealthchecksLength int } type SettingsHealthcheck struct { *Settings - Healthcheck *models.HealthcheckHttp + Healthcheck *models.Healthcheck } func (h *BaseHandler) SettingsHealthchecksGET(c echo.Context) error { cc := c.(AuthenticatedContext) - healthchecks, err := h.query.HealthcheckHttp.WithContext(context.Background()).Find() + healthchecks, err := h.query.Healthcheck.WithContext(context.Background()).Find() if err != nil { return err } @@ -49,7 +49,7 @@ func (h *BaseHandler) SettingsHealthchecksDescribeGET(c echo.Context) error { slug := c.Param("slug") - healthcheck, err := services.GetHealthcheckHttp(context.Background(), h.query, slug) + healthcheck, err := services.GetHealthcheck(context.Background(), h.query, slug) if err != nil { return err } @@ -86,15 +86,12 @@ func (h *BaseHandler) SettingsHealthchecksCreateGET(c echo.Context) error { func (h *BaseHandler) SettingsHealthchecksCreatePOST(c echo.Context) error { ctx := context.Background() - healthcheckHttp := &models.HealthcheckHttp{ - Healthcheck: models.Healthcheck{ - Name: c.FormValue("name"), - Slug: slug.Make(c.FormValue("name")), - Schedule: c.FormValue("schedule"), - WorkerGroups: strings.Split(c.FormValue("workergroups"), ","), - }, - Url: c.FormValue("url"), - Method: c.FormValue("method"), + healthcheckHttp := &models.Healthcheck{ + Name: c.FormValue("name"), + Slug: slug.Make(c.FormValue("name")), + Schedule: c.FormValue("schedule"), + WorkerGroups: strings.Split(c.FormValue("workergroups"), ","), + Script: c.FormValue("script"), } err := validator.New(validator.WithRequiredStructEnabled()).Struct(healthcheckHttp) @@ -102,7 +99,7 @@ func (h *BaseHandler) SettingsHealthchecksCreatePOST(c echo.Context) error { return err } - err = services.CreateHealthcheckHttp( + err = services.CreateHealthcheck( ctx, h.db, healthcheckHttp, @@ -111,7 +108,7 @@ func (h *BaseHandler) SettingsHealthchecksCreatePOST(c echo.Context) error { return err } - err = services.StartHealthcheckHttp(ctx, h.temporal, healthcheckHttp) + err = services.StartHealthcheck(ctx, h.temporal, healthcheckHttp) if err != nil { return err } diff --git a/internal/models/models.go b/internal/models/models.go index db11c0d..a6b3ad4 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -22,28 +22,15 @@ type Worker struct { type Healthcheck struct { gorm.Model - Slug string `gorm:"unique"` - Name string `gorm:"unique" validate:"required"` - Status string // UP, DOWN - UptimePercentage float64 - Schedule string `validate:"required,cron"` - WorkerGroups pq.StringArray `gorm:"type:text[]"` -} + Slug string `gorm:"unique"` + Name string `gorm:"unique" validate:"required"` -type HealthcheckHttp struct { - gorm.Model - Healthcheck - Url string `validate:"required,url"` - Method string `validate:"required,oneof=GET POST"` + Schedule string `validate:"required,cron"` + WorkerGroups pq.StringArray `gorm:"type:text[]"` - History []HealthcheckHttpHistory `gorm:"foreignKey:ID"` -} + Script string `validate:"required"` -type HealthcheckTcp struct { - gorm.Model - Healthcheck - Hostname string `validate:"required,hostname"` - Port int `validate:"required,gte=1,lte=65535"` + History []HealthcheckHistory `gorm:"foreignKey:ID"` } type Cronjob struct { @@ -54,16 +41,10 @@ type Cronjob struct { Buffer int } -type HealthcheckHttpHistory struct { +type HealthcheckHistory struct { gorm.Model - HealthcheckHTTP HealthcheckHttp `gorm:"foreignkey:ID"` - Status string -} - -type HealthcheckTcpHistory struct { - gorm.Model - HealthcheckTCP HealthcheckTcp `gorm:"foreignkey:ID"` - Status string + Healthcheck Healthcheck `gorm:"foreignkey:ID"` + Status string } type CronjobHistory struct { diff --git a/internal/models/query/gen.go b/internal/models/query/gen.go index dc34a8b..884b246 100644 --- a/internal/models/query/gen.go +++ b/internal/models/query/gen.go @@ -16,69 +16,59 @@ import ( ) var ( - Q = new(Query) - Cronjob *cronjob - CronjobHistory *cronjobHistory - HealthcheckHttp *healthcheckHttp - HealthcheckHttpHistory *healthcheckHttpHistory - HealthcheckTcp *healthcheckTcp - HealthcheckTcpHistory *healthcheckTcpHistory - OAuth2State *oAuth2State - Worker *worker + Q = new(Query) + Cronjob *cronjob + CronjobHistory *cronjobHistory + Healthcheck *healthcheck + HealthcheckHistory *healthcheckHistory + OAuth2State *oAuth2State + Worker *worker ) func SetDefault(db *gorm.DB, opts ...gen.DOOption) { *Q = *Use(db, opts...) Cronjob = &Q.Cronjob CronjobHistory = &Q.CronjobHistory - HealthcheckHttp = &Q.HealthcheckHttp - HealthcheckHttpHistory = &Q.HealthcheckHttpHistory - HealthcheckTcp = &Q.HealthcheckTcp - HealthcheckTcpHistory = &Q.HealthcheckTcpHistory + Healthcheck = &Q.Healthcheck + HealthcheckHistory = &Q.HealthcheckHistory OAuth2State = &Q.OAuth2State Worker = &Q.Worker } func Use(db *gorm.DB, opts ...gen.DOOption) *Query { return &Query{ - db: db, - Cronjob: newCronjob(db, opts...), - CronjobHistory: newCronjobHistory(db, opts...), - HealthcheckHttp: newHealthcheckHttp(db, opts...), - HealthcheckHttpHistory: newHealthcheckHttpHistory(db, opts...), - HealthcheckTcp: newHealthcheckTcp(db, opts...), - HealthcheckTcpHistory: newHealthcheckTcpHistory(db, opts...), - OAuth2State: newOAuth2State(db, opts...), - Worker: newWorker(db, opts...), + db: db, + Cronjob: newCronjob(db, opts...), + CronjobHistory: newCronjobHistory(db, opts...), + Healthcheck: newHealthcheck(db, opts...), + HealthcheckHistory: newHealthcheckHistory(db, opts...), + OAuth2State: newOAuth2State(db, opts...), + Worker: newWorker(db, opts...), } } type Query struct { db *gorm.DB - Cronjob cronjob - CronjobHistory cronjobHistory - HealthcheckHttp healthcheckHttp - HealthcheckHttpHistory healthcheckHttpHistory - HealthcheckTcp healthcheckTcp - HealthcheckTcpHistory healthcheckTcpHistory - OAuth2State oAuth2State - Worker worker + Cronjob cronjob + CronjobHistory cronjobHistory + Healthcheck healthcheck + HealthcheckHistory healthcheckHistory + OAuth2State oAuth2State + Worker worker } func (q *Query) Available() bool { return q.db != nil } func (q *Query) clone(db *gorm.DB) *Query { return &Query{ - db: db, - Cronjob: q.Cronjob.clone(db), - CronjobHistory: q.CronjobHistory.clone(db), - HealthcheckHttp: q.HealthcheckHttp.clone(db), - HealthcheckHttpHistory: q.HealthcheckHttpHistory.clone(db), - HealthcheckTcp: q.HealthcheckTcp.clone(db), - HealthcheckTcpHistory: q.HealthcheckTcpHistory.clone(db), - OAuth2State: q.OAuth2State.clone(db), - Worker: q.Worker.clone(db), + db: db, + Cronjob: q.Cronjob.clone(db), + CronjobHistory: q.CronjobHistory.clone(db), + Healthcheck: q.Healthcheck.clone(db), + HealthcheckHistory: q.HealthcheckHistory.clone(db), + OAuth2State: q.OAuth2State.clone(db), + Worker: q.Worker.clone(db), } } @@ -92,39 +82,33 @@ func (q *Query) WriteDB() *Query { func (q *Query) ReplaceDB(db *gorm.DB) *Query { return &Query{ - db: db, - Cronjob: q.Cronjob.replaceDB(db), - CronjobHistory: q.CronjobHistory.replaceDB(db), - HealthcheckHttp: q.HealthcheckHttp.replaceDB(db), - HealthcheckHttpHistory: q.HealthcheckHttpHistory.replaceDB(db), - HealthcheckTcp: q.HealthcheckTcp.replaceDB(db), - HealthcheckTcpHistory: q.HealthcheckTcpHistory.replaceDB(db), - OAuth2State: q.OAuth2State.replaceDB(db), - Worker: q.Worker.replaceDB(db), + db: db, + Cronjob: q.Cronjob.replaceDB(db), + CronjobHistory: q.CronjobHistory.replaceDB(db), + Healthcheck: q.Healthcheck.replaceDB(db), + HealthcheckHistory: q.HealthcheckHistory.replaceDB(db), + OAuth2State: q.OAuth2State.replaceDB(db), + Worker: q.Worker.replaceDB(db), } } type queryCtx struct { - Cronjob ICronjobDo - CronjobHistory ICronjobHistoryDo - HealthcheckHttp IHealthcheckHttpDo - HealthcheckHttpHistory IHealthcheckHttpHistoryDo - HealthcheckTcp IHealthcheckTcpDo - HealthcheckTcpHistory IHealthcheckTcpHistoryDo - OAuth2State IOAuth2StateDo - Worker IWorkerDo + Cronjob ICronjobDo + CronjobHistory ICronjobHistoryDo + Healthcheck IHealthcheckDo + HealthcheckHistory IHealthcheckHistoryDo + OAuth2State IOAuth2StateDo + Worker IWorkerDo } func (q *Query) WithContext(ctx context.Context) *queryCtx { return &queryCtx{ - Cronjob: q.Cronjob.WithContext(ctx), - CronjobHistory: q.CronjobHistory.WithContext(ctx), - HealthcheckHttp: q.HealthcheckHttp.WithContext(ctx), - HealthcheckHttpHistory: q.HealthcheckHttpHistory.WithContext(ctx), - HealthcheckTcp: q.HealthcheckTcp.WithContext(ctx), - HealthcheckTcpHistory: q.HealthcheckTcpHistory.WithContext(ctx), - OAuth2State: q.OAuth2State.WithContext(ctx), - Worker: q.Worker.WithContext(ctx), + Cronjob: q.Cronjob.WithContext(ctx), + CronjobHistory: q.CronjobHistory.WithContext(ctx), + Healthcheck: q.Healthcheck.WithContext(ctx), + HealthcheckHistory: q.HealthcheckHistory.WithContext(ctx), + OAuth2State: q.OAuth2State.WithContext(ctx), + Worker: q.Worker.WithContext(ctx), } } diff --git a/internal/models/query/healthcheck_histories.gen.go b/internal/models/query/healthcheck_histories.gen.go new file mode 100644 index 0000000..cfdeb19 --- /dev/null +++ b/internal/models/query/healthcheck_histories.gen.go @@ -0,0 +1,506 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package query + +import ( + "context" + + "gorm.io/gorm" + "gorm.io/gorm/clause" + "gorm.io/gorm/schema" + + "gorm.io/gen" + "gorm.io/gen/field" + + "gorm.io/plugin/dbresolver" + + "code.tjo.space/mentos1386/zdravko/internal/models" +) + +func newHealthcheckHistory(db *gorm.DB, opts ...gen.DOOption) healthcheckHistory { + _healthcheckHistory := healthcheckHistory{} + + _healthcheckHistory.healthcheckHistoryDo.UseDB(db, opts...) + _healthcheckHistory.healthcheckHistoryDo.UseModel(&models.HealthcheckHistory{}) + + tableName := _healthcheckHistory.healthcheckHistoryDo.TableName() + _healthcheckHistory.ALL = field.NewAsterisk(tableName) + _healthcheckHistory.ID = field.NewUint(tableName, "id") + _healthcheckHistory.CreatedAt = field.NewTime(tableName, "created_at") + _healthcheckHistory.UpdatedAt = field.NewTime(tableName, "updated_at") + _healthcheckHistory.DeletedAt = field.NewField(tableName, "deleted_at") + _healthcheckHistory.Status = field.NewString(tableName, "status") + _healthcheckHistory.Healthcheck = healthcheckHistoryHasOneHealthcheck{ + db: db.Session(&gorm.Session{}), + + RelationField: field.NewRelation("Healthcheck", "models.Healthcheck"), + History: struct { + field.RelationField + Healthcheck struct { + field.RelationField + } + }{ + RelationField: field.NewRelation("Healthcheck.History", "models.HealthcheckHistory"), + Healthcheck: struct { + field.RelationField + }{ + RelationField: field.NewRelation("Healthcheck.History.Healthcheck", "models.Healthcheck"), + }, + }, + } + + _healthcheckHistory.fillFieldMap() + + return _healthcheckHistory +} + +type healthcheckHistory struct { + healthcheckHistoryDo healthcheckHistoryDo + + ALL field.Asterisk + ID field.Uint + CreatedAt field.Time + UpdatedAt field.Time + DeletedAt field.Field + Status field.String + Healthcheck healthcheckHistoryHasOneHealthcheck + + fieldMap map[string]field.Expr +} + +func (h healthcheckHistory) Table(newTableName string) *healthcheckHistory { + h.healthcheckHistoryDo.UseTable(newTableName) + return h.updateTableName(newTableName) +} + +func (h healthcheckHistory) As(alias string) *healthcheckHistory { + h.healthcheckHistoryDo.DO = *(h.healthcheckHistoryDo.As(alias).(*gen.DO)) + return h.updateTableName(alias) +} + +func (h *healthcheckHistory) updateTableName(table string) *healthcheckHistory { + h.ALL = field.NewAsterisk(table) + h.ID = field.NewUint(table, "id") + h.CreatedAt = field.NewTime(table, "created_at") + h.UpdatedAt = field.NewTime(table, "updated_at") + h.DeletedAt = field.NewField(table, "deleted_at") + h.Status = field.NewString(table, "status") + + h.fillFieldMap() + + return h +} + +func (h *healthcheckHistory) WithContext(ctx context.Context) IHealthcheckHistoryDo { + return h.healthcheckHistoryDo.WithContext(ctx) +} + +func (h healthcheckHistory) TableName() string { return h.healthcheckHistoryDo.TableName() } + +func (h healthcheckHistory) Alias() string { return h.healthcheckHistoryDo.Alias() } + +func (h healthcheckHistory) Columns(cols ...field.Expr) gen.Columns { + return h.healthcheckHistoryDo.Columns(cols...) +} + +func (h *healthcheckHistory) GetFieldByName(fieldName string) (field.OrderExpr, bool) { + _f, ok := h.fieldMap[fieldName] + if !ok || _f == nil { + return nil, false + } + _oe, ok := _f.(field.OrderExpr) + return _oe, ok +} + +func (h *healthcheckHistory) fillFieldMap() { + h.fieldMap = make(map[string]field.Expr, 6) + h.fieldMap["id"] = h.ID + h.fieldMap["created_at"] = h.CreatedAt + h.fieldMap["updated_at"] = h.UpdatedAt + h.fieldMap["deleted_at"] = h.DeletedAt + h.fieldMap["status"] = h.Status + +} + +func (h healthcheckHistory) clone(db *gorm.DB) healthcheckHistory { + h.healthcheckHistoryDo.ReplaceConnPool(db.Statement.ConnPool) + return h +} + +func (h healthcheckHistory) replaceDB(db *gorm.DB) healthcheckHistory { + h.healthcheckHistoryDo.ReplaceDB(db) + return h +} + +type healthcheckHistoryHasOneHealthcheck struct { + db *gorm.DB + + field.RelationField + + History struct { + field.RelationField + Healthcheck struct { + field.RelationField + } + } +} + +func (a healthcheckHistoryHasOneHealthcheck) Where(conds ...field.Expr) *healthcheckHistoryHasOneHealthcheck { + if len(conds) == 0 { + return &a + } + + exprs := make([]clause.Expression, 0, len(conds)) + for _, cond := range conds { + exprs = append(exprs, cond.BeCond().(clause.Expression)) + } + a.db = a.db.Clauses(clause.Where{Exprs: exprs}) + return &a +} + +func (a healthcheckHistoryHasOneHealthcheck) WithContext(ctx context.Context) *healthcheckHistoryHasOneHealthcheck { + a.db = a.db.WithContext(ctx) + return &a +} + +func (a healthcheckHistoryHasOneHealthcheck) Session(session *gorm.Session) *healthcheckHistoryHasOneHealthcheck { + a.db = a.db.Session(session) + return &a +} + +func (a healthcheckHistoryHasOneHealthcheck) Model(m *models.HealthcheckHistory) *healthcheckHistoryHasOneHealthcheckTx { + return &healthcheckHistoryHasOneHealthcheckTx{a.db.Model(m).Association(a.Name())} +} + +type healthcheckHistoryHasOneHealthcheckTx struct{ tx *gorm.Association } + +func (a healthcheckHistoryHasOneHealthcheckTx) Find() (result *models.Healthcheck, err error) { + return result, a.tx.Find(&result) +} + +func (a healthcheckHistoryHasOneHealthcheckTx) Append(values ...*models.Healthcheck) (err error) { + targetValues := make([]interface{}, len(values)) + for i, v := range values { + targetValues[i] = v + } + return a.tx.Append(targetValues...) +} + +func (a healthcheckHistoryHasOneHealthcheckTx) Replace(values ...*models.Healthcheck) (err error) { + targetValues := make([]interface{}, len(values)) + for i, v := range values { + targetValues[i] = v + } + return a.tx.Replace(targetValues...) +} + +func (a healthcheckHistoryHasOneHealthcheckTx) Delete(values ...*models.Healthcheck) (err error) { + targetValues := make([]interface{}, len(values)) + for i, v := range values { + targetValues[i] = v + } + return a.tx.Delete(targetValues...) +} + +func (a healthcheckHistoryHasOneHealthcheckTx) Clear() error { + return a.tx.Clear() +} + +func (a healthcheckHistoryHasOneHealthcheckTx) Count() int64 { + return a.tx.Count() +} + +type healthcheckHistoryDo struct{ gen.DO } + +type IHealthcheckHistoryDo interface { + gen.SubQuery + Debug() IHealthcheckHistoryDo + WithContext(ctx context.Context) IHealthcheckHistoryDo + WithResult(fc func(tx gen.Dao)) gen.ResultInfo + ReplaceDB(db *gorm.DB) + ReadDB() IHealthcheckHistoryDo + WriteDB() IHealthcheckHistoryDo + As(alias string) gen.Dao + Session(config *gorm.Session) IHealthcheckHistoryDo + Columns(cols ...field.Expr) gen.Columns + Clauses(conds ...clause.Expression) IHealthcheckHistoryDo + Not(conds ...gen.Condition) IHealthcheckHistoryDo + Or(conds ...gen.Condition) IHealthcheckHistoryDo + Select(conds ...field.Expr) IHealthcheckHistoryDo + Where(conds ...gen.Condition) IHealthcheckHistoryDo + Order(conds ...field.Expr) IHealthcheckHistoryDo + Distinct(cols ...field.Expr) IHealthcheckHistoryDo + Omit(cols ...field.Expr) IHealthcheckHistoryDo + Join(table schema.Tabler, on ...field.Expr) IHealthcheckHistoryDo + LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHistoryDo + RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHistoryDo + Group(cols ...field.Expr) IHealthcheckHistoryDo + Having(conds ...gen.Condition) IHealthcheckHistoryDo + Limit(limit int) IHealthcheckHistoryDo + Offset(offset int) IHealthcheckHistoryDo + Count() (count int64, err error) + Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckHistoryDo + Unscoped() IHealthcheckHistoryDo + Create(values ...*models.HealthcheckHistory) error + CreateInBatches(values []*models.HealthcheckHistory, batchSize int) error + Save(values ...*models.HealthcheckHistory) error + First() (*models.HealthcheckHistory, error) + Take() (*models.HealthcheckHistory, error) + Last() (*models.HealthcheckHistory, error) + Find() ([]*models.HealthcheckHistory, error) + FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckHistory, err error) + FindInBatches(result *[]*models.HealthcheckHistory, batchSize int, fc func(tx gen.Dao, batch int) error) error + Pluck(column field.Expr, dest interface{}) error + Delete(...*models.HealthcheckHistory) (info gen.ResultInfo, err error) + Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error) + UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) + Updates(value interface{}) (info gen.ResultInfo, err error) + UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error) + UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) + UpdateColumns(value interface{}) (info gen.ResultInfo, err error) + UpdateFrom(q gen.SubQuery) gen.Dao + Attrs(attrs ...field.AssignExpr) IHealthcheckHistoryDo + Assign(attrs ...field.AssignExpr) IHealthcheckHistoryDo + Joins(fields ...field.RelationField) IHealthcheckHistoryDo + Preload(fields ...field.RelationField) IHealthcheckHistoryDo + FirstOrInit() (*models.HealthcheckHistory, error) + FirstOrCreate() (*models.HealthcheckHistory, error) + FindByPage(offset int, limit int) (result []*models.HealthcheckHistory, count int64, err error) + ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Scan(result interface{}) (err error) + Returning(value interface{}, columns ...string) IHealthcheckHistoryDo + UnderlyingDB() *gorm.DB + schema.Tabler +} + +func (h healthcheckHistoryDo) Debug() IHealthcheckHistoryDo { + return h.withDO(h.DO.Debug()) +} + +func (h healthcheckHistoryDo) WithContext(ctx context.Context) IHealthcheckHistoryDo { + return h.withDO(h.DO.WithContext(ctx)) +} + +func (h healthcheckHistoryDo) ReadDB() IHealthcheckHistoryDo { + return h.Clauses(dbresolver.Read) +} + +func (h healthcheckHistoryDo) WriteDB() IHealthcheckHistoryDo { + return h.Clauses(dbresolver.Write) +} + +func (h healthcheckHistoryDo) Session(config *gorm.Session) IHealthcheckHistoryDo { + return h.withDO(h.DO.Session(config)) +} + +func (h healthcheckHistoryDo) Clauses(conds ...clause.Expression) IHealthcheckHistoryDo { + return h.withDO(h.DO.Clauses(conds...)) +} + +func (h healthcheckHistoryDo) Returning(value interface{}, columns ...string) IHealthcheckHistoryDo { + return h.withDO(h.DO.Returning(value, columns...)) +} + +func (h healthcheckHistoryDo) Not(conds ...gen.Condition) IHealthcheckHistoryDo { + return h.withDO(h.DO.Not(conds...)) +} + +func (h healthcheckHistoryDo) Or(conds ...gen.Condition) IHealthcheckHistoryDo { + return h.withDO(h.DO.Or(conds...)) +} + +func (h healthcheckHistoryDo) Select(conds ...field.Expr) IHealthcheckHistoryDo { + return h.withDO(h.DO.Select(conds...)) +} + +func (h healthcheckHistoryDo) Where(conds ...gen.Condition) IHealthcheckHistoryDo { + return h.withDO(h.DO.Where(conds...)) +} + +func (h healthcheckHistoryDo) Order(conds ...field.Expr) IHealthcheckHistoryDo { + return h.withDO(h.DO.Order(conds...)) +} + +func (h healthcheckHistoryDo) Distinct(cols ...field.Expr) IHealthcheckHistoryDo { + return h.withDO(h.DO.Distinct(cols...)) +} + +func (h healthcheckHistoryDo) Omit(cols ...field.Expr) IHealthcheckHistoryDo { + return h.withDO(h.DO.Omit(cols...)) +} + +func (h healthcheckHistoryDo) Join(table schema.Tabler, on ...field.Expr) IHealthcheckHistoryDo { + return h.withDO(h.DO.Join(table, on...)) +} + +func (h healthcheckHistoryDo) LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHistoryDo { + return h.withDO(h.DO.LeftJoin(table, on...)) +} + +func (h healthcheckHistoryDo) RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHistoryDo { + return h.withDO(h.DO.RightJoin(table, on...)) +} + +func (h healthcheckHistoryDo) Group(cols ...field.Expr) IHealthcheckHistoryDo { + return h.withDO(h.DO.Group(cols...)) +} + +func (h healthcheckHistoryDo) Having(conds ...gen.Condition) IHealthcheckHistoryDo { + return h.withDO(h.DO.Having(conds...)) +} + +func (h healthcheckHistoryDo) Limit(limit int) IHealthcheckHistoryDo { + return h.withDO(h.DO.Limit(limit)) +} + +func (h healthcheckHistoryDo) Offset(offset int) IHealthcheckHistoryDo { + return h.withDO(h.DO.Offset(offset)) +} + +func (h healthcheckHistoryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckHistoryDo { + return h.withDO(h.DO.Scopes(funcs...)) +} + +func (h healthcheckHistoryDo) Unscoped() IHealthcheckHistoryDo { + return h.withDO(h.DO.Unscoped()) +} + +func (h healthcheckHistoryDo) Create(values ...*models.HealthcheckHistory) error { + if len(values) == 0 { + return nil + } + return h.DO.Create(values) +} + +func (h healthcheckHistoryDo) CreateInBatches(values []*models.HealthcheckHistory, batchSize int) error { + return h.DO.CreateInBatches(values, batchSize) +} + +// Save : !!! underlying implementation is different with GORM +// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values) +func (h healthcheckHistoryDo) Save(values ...*models.HealthcheckHistory) error { + if len(values) == 0 { + return nil + } + return h.DO.Save(values) +} + +func (h healthcheckHistoryDo) First() (*models.HealthcheckHistory, error) { + if result, err := h.DO.First(); err != nil { + return nil, err + } else { + return result.(*models.HealthcheckHistory), nil + } +} + +func (h healthcheckHistoryDo) Take() (*models.HealthcheckHistory, error) { + if result, err := h.DO.Take(); err != nil { + return nil, err + } else { + return result.(*models.HealthcheckHistory), nil + } +} + +func (h healthcheckHistoryDo) Last() (*models.HealthcheckHistory, error) { + if result, err := h.DO.Last(); err != nil { + return nil, err + } else { + return result.(*models.HealthcheckHistory), nil + } +} + +func (h healthcheckHistoryDo) Find() ([]*models.HealthcheckHistory, error) { + result, err := h.DO.Find() + return result.([]*models.HealthcheckHistory), err +} + +func (h healthcheckHistoryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckHistory, err error) { + buf := make([]*models.HealthcheckHistory, 0, batchSize) + err = h.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error { + defer func() { results = append(results, buf...) }() + return fc(tx, batch) + }) + return results, err +} + +func (h healthcheckHistoryDo) FindInBatches(result *[]*models.HealthcheckHistory, batchSize int, fc func(tx gen.Dao, batch int) error) error { + return h.DO.FindInBatches(result, batchSize, fc) +} + +func (h healthcheckHistoryDo) Attrs(attrs ...field.AssignExpr) IHealthcheckHistoryDo { + return h.withDO(h.DO.Attrs(attrs...)) +} + +func (h healthcheckHistoryDo) Assign(attrs ...field.AssignExpr) IHealthcheckHistoryDo { + return h.withDO(h.DO.Assign(attrs...)) +} + +func (h healthcheckHistoryDo) Joins(fields ...field.RelationField) IHealthcheckHistoryDo { + for _, _f := range fields { + h = *h.withDO(h.DO.Joins(_f)) + } + return &h +} + +func (h healthcheckHistoryDo) Preload(fields ...field.RelationField) IHealthcheckHistoryDo { + for _, _f := range fields { + h = *h.withDO(h.DO.Preload(_f)) + } + return &h +} + +func (h healthcheckHistoryDo) FirstOrInit() (*models.HealthcheckHistory, error) { + if result, err := h.DO.FirstOrInit(); err != nil { + return nil, err + } else { + return result.(*models.HealthcheckHistory), nil + } +} + +func (h healthcheckHistoryDo) FirstOrCreate() (*models.HealthcheckHistory, error) { + if result, err := h.DO.FirstOrCreate(); err != nil { + return nil, err + } else { + return result.(*models.HealthcheckHistory), nil + } +} + +func (h healthcheckHistoryDo) FindByPage(offset int, limit int) (result []*models.HealthcheckHistory, count int64, err error) { + result, err = h.Offset(offset).Limit(limit).Find() + if err != nil { + return + } + + if size := len(result); 0 < limit && 0 < size && size < limit { + count = int64(size + offset) + return + } + + count, err = h.Offset(-1).Limit(-1).Count() + return +} + +func (h healthcheckHistoryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { + count, err = h.Count() + if err != nil { + return + } + + err = h.Offset(offset).Limit(limit).Scan(result) + return +} + +func (h healthcheckHistoryDo) Scan(result interface{}) (err error) { + return h.DO.Scan(result) +} + +func (h healthcheckHistoryDo) Delete(models ...*models.HealthcheckHistory) (result gen.ResultInfo, err error) { + return h.DO.Delete(models) +} + +func (h *healthcheckHistoryDo) withDO(do gen.Dao) *healthcheckHistoryDo { + h.DO = *do.(*gen.DO) + return h +} diff --git a/internal/models/query/healthcheck_http_histories.gen.go b/internal/models/query/healthcheck_http_histories.gen.go deleted file mode 100644 index ce7dadb..0000000 --- a/internal/models/query/healthcheck_http_histories.gen.go +++ /dev/null @@ -1,506 +0,0 @@ -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. - -package query - -import ( - "context" - - "gorm.io/gorm" - "gorm.io/gorm/clause" - "gorm.io/gorm/schema" - - "gorm.io/gen" - "gorm.io/gen/field" - - "gorm.io/plugin/dbresolver" - - "code.tjo.space/mentos1386/zdravko/internal/models" -) - -func newHealthcheckHttpHistory(db *gorm.DB, opts ...gen.DOOption) healthcheckHttpHistory { - _healthcheckHttpHistory := healthcheckHttpHistory{} - - _healthcheckHttpHistory.healthcheckHttpHistoryDo.UseDB(db, opts...) - _healthcheckHttpHistory.healthcheckHttpHistoryDo.UseModel(&models.HealthcheckHttpHistory{}) - - tableName := _healthcheckHttpHistory.healthcheckHttpHistoryDo.TableName() - _healthcheckHttpHistory.ALL = field.NewAsterisk(tableName) - _healthcheckHttpHistory.ID = field.NewUint(tableName, "id") - _healthcheckHttpHistory.CreatedAt = field.NewTime(tableName, "created_at") - _healthcheckHttpHistory.UpdatedAt = field.NewTime(tableName, "updated_at") - _healthcheckHttpHistory.DeletedAt = field.NewField(tableName, "deleted_at") - _healthcheckHttpHistory.Status = field.NewString(tableName, "status") - _healthcheckHttpHistory.HealthcheckHTTP = healthcheckHttpHistoryHasOneHealthcheckHTTP{ - db: db.Session(&gorm.Session{}), - - RelationField: field.NewRelation("HealthcheckHTTP", "models.HealthcheckHttp"), - History: struct { - field.RelationField - HealthcheckHTTP struct { - field.RelationField - } - }{ - RelationField: field.NewRelation("HealthcheckHTTP.History", "models.HealthcheckHttpHistory"), - HealthcheckHTTP: struct { - field.RelationField - }{ - RelationField: field.NewRelation("HealthcheckHTTP.History.HealthcheckHTTP", "models.HealthcheckHttp"), - }, - }, - } - - _healthcheckHttpHistory.fillFieldMap() - - return _healthcheckHttpHistory -} - -type healthcheckHttpHistory struct { - healthcheckHttpHistoryDo healthcheckHttpHistoryDo - - ALL field.Asterisk - ID field.Uint - CreatedAt field.Time - UpdatedAt field.Time - DeletedAt field.Field - Status field.String - HealthcheckHTTP healthcheckHttpHistoryHasOneHealthcheckHTTP - - fieldMap map[string]field.Expr -} - -func (h healthcheckHttpHistory) Table(newTableName string) *healthcheckHttpHistory { - h.healthcheckHttpHistoryDo.UseTable(newTableName) - return h.updateTableName(newTableName) -} - -func (h healthcheckHttpHistory) As(alias string) *healthcheckHttpHistory { - h.healthcheckHttpHistoryDo.DO = *(h.healthcheckHttpHistoryDo.As(alias).(*gen.DO)) - return h.updateTableName(alias) -} - -func (h *healthcheckHttpHistory) updateTableName(table string) *healthcheckHttpHistory { - h.ALL = field.NewAsterisk(table) - h.ID = field.NewUint(table, "id") - h.CreatedAt = field.NewTime(table, "created_at") - h.UpdatedAt = field.NewTime(table, "updated_at") - h.DeletedAt = field.NewField(table, "deleted_at") - h.Status = field.NewString(table, "status") - - h.fillFieldMap() - - return h -} - -func (h *healthcheckHttpHistory) WithContext(ctx context.Context) IHealthcheckHttpHistoryDo { - return h.healthcheckHttpHistoryDo.WithContext(ctx) -} - -func (h healthcheckHttpHistory) TableName() string { return h.healthcheckHttpHistoryDo.TableName() } - -func (h healthcheckHttpHistory) Alias() string { return h.healthcheckHttpHistoryDo.Alias() } - -func (h healthcheckHttpHistory) Columns(cols ...field.Expr) gen.Columns { - return h.healthcheckHttpHistoryDo.Columns(cols...) -} - -func (h *healthcheckHttpHistory) GetFieldByName(fieldName string) (field.OrderExpr, bool) { - _f, ok := h.fieldMap[fieldName] - if !ok || _f == nil { - return nil, false - } - _oe, ok := _f.(field.OrderExpr) - return _oe, ok -} - -func (h *healthcheckHttpHistory) fillFieldMap() { - h.fieldMap = make(map[string]field.Expr, 6) - h.fieldMap["id"] = h.ID - h.fieldMap["created_at"] = h.CreatedAt - h.fieldMap["updated_at"] = h.UpdatedAt - h.fieldMap["deleted_at"] = h.DeletedAt - h.fieldMap["status"] = h.Status - -} - -func (h healthcheckHttpHistory) clone(db *gorm.DB) healthcheckHttpHistory { - h.healthcheckHttpHistoryDo.ReplaceConnPool(db.Statement.ConnPool) - return h -} - -func (h healthcheckHttpHistory) replaceDB(db *gorm.DB) healthcheckHttpHistory { - h.healthcheckHttpHistoryDo.ReplaceDB(db) - return h -} - -type healthcheckHttpHistoryHasOneHealthcheckHTTP struct { - db *gorm.DB - - field.RelationField - - History struct { - field.RelationField - HealthcheckHTTP struct { - field.RelationField - } - } -} - -func (a healthcheckHttpHistoryHasOneHealthcheckHTTP) Where(conds ...field.Expr) *healthcheckHttpHistoryHasOneHealthcheckHTTP { - if len(conds) == 0 { - return &a - } - - exprs := make([]clause.Expression, 0, len(conds)) - for _, cond := range conds { - exprs = append(exprs, cond.BeCond().(clause.Expression)) - } - a.db = a.db.Clauses(clause.Where{Exprs: exprs}) - return &a -} - -func (a healthcheckHttpHistoryHasOneHealthcheckHTTP) WithContext(ctx context.Context) *healthcheckHttpHistoryHasOneHealthcheckHTTP { - a.db = a.db.WithContext(ctx) - return &a -} - -func (a healthcheckHttpHistoryHasOneHealthcheckHTTP) Session(session *gorm.Session) *healthcheckHttpHistoryHasOneHealthcheckHTTP { - a.db = a.db.Session(session) - return &a -} - -func (a healthcheckHttpHistoryHasOneHealthcheckHTTP) Model(m *models.HealthcheckHttpHistory) *healthcheckHttpHistoryHasOneHealthcheckHTTPTx { - return &healthcheckHttpHistoryHasOneHealthcheckHTTPTx{a.db.Model(m).Association(a.Name())} -} - -type healthcheckHttpHistoryHasOneHealthcheckHTTPTx struct{ tx *gorm.Association } - -func (a healthcheckHttpHistoryHasOneHealthcheckHTTPTx) Find() (result *models.HealthcheckHttp, err error) { - return result, a.tx.Find(&result) -} - -func (a healthcheckHttpHistoryHasOneHealthcheckHTTPTx) Append(values ...*models.HealthcheckHttp) (err error) { - targetValues := make([]interface{}, len(values)) - for i, v := range values { - targetValues[i] = v - } - return a.tx.Append(targetValues...) -} - -func (a healthcheckHttpHistoryHasOneHealthcheckHTTPTx) Replace(values ...*models.HealthcheckHttp) (err error) { - targetValues := make([]interface{}, len(values)) - for i, v := range values { - targetValues[i] = v - } - return a.tx.Replace(targetValues...) -} - -func (a healthcheckHttpHistoryHasOneHealthcheckHTTPTx) Delete(values ...*models.HealthcheckHttp) (err error) { - targetValues := make([]interface{}, len(values)) - for i, v := range values { - targetValues[i] = v - } - return a.tx.Delete(targetValues...) -} - -func (a healthcheckHttpHistoryHasOneHealthcheckHTTPTx) Clear() error { - return a.tx.Clear() -} - -func (a healthcheckHttpHistoryHasOneHealthcheckHTTPTx) Count() int64 { - return a.tx.Count() -} - -type healthcheckHttpHistoryDo struct{ gen.DO } - -type IHealthcheckHttpHistoryDo interface { - gen.SubQuery - Debug() IHealthcheckHttpHistoryDo - WithContext(ctx context.Context) IHealthcheckHttpHistoryDo - WithResult(fc func(tx gen.Dao)) gen.ResultInfo - ReplaceDB(db *gorm.DB) - ReadDB() IHealthcheckHttpHistoryDo - WriteDB() IHealthcheckHttpHistoryDo - As(alias string) gen.Dao - Session(config *gorm.Session) IHealthcheckHttpHistoryDo - Columns(cols ...field.Expr) gen.Columns - Clauses(conds ...clause.Expression) IHealthcheckHttpHistoryDo - Not(conds ...gen.Condition) IHealthcheckHttpHistoryDo - Or(conds ...gen.Condition) IHealthcheckHttpHistoryDo - Select(conds ...field.Expr) IHealthcheckHttpHistoryDo - Where(conds ...gen.Condition) IHealthcheckHttpHistoryDo - Order(conds ...field.Expr) IHealthcheckHttpHistoryDo - Distinct(cols ...field.Expr) IHealthcheckHttpHistoryDo - Omit(cols ...field.Expr) IHealthcheckHttpHistoryDo - Join(table schema.Tabler, on ...field.Expr) IHealthcheckHttpHistoryDo - LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHttpHistoryDo - RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHttpHistoryDo - Group(cols ...field.Expr) IHealthcheckHttpHistoryDo - Having(conds ...gen.Condition) IHealthcheckHttpHistoryDo - Limit(limit int) IHealthcheckHttpHistoryDo - Offset(offset int) IHealthcheckHttpHistoryDo - Count() (count int64, err error) - Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckHttpHistoryDo - Unscoped() IHealthcheckHttpHistoryDo - Create(values ...*models.HealthcheckHttpHistory) error - CreateInBatches(values []*models.HealthcheckHttpHistory, batchSize int) error - Save(values ...*models.HealthcheckHttpHistory) error - First() (*models.HealthcheckHttpHistory, error) - Take() (*models.HealthcheckHttpHistory, error) - Last() (*models.HealthcheckHttpHistory, error) - Find() ([]*models.HealthcheckHttpHistory, error) - FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckHttpHistory, err error) - FindInBatches(result *[]*models.HealthcheckHttpHistory, batchSize int, fc func(tx gen.Dao, batch int) error) error - Pluck(column field.Expr, dest interface{}) error - Delete(...*models.HealthcheckHttpHistory) (info gen.ResultInfo, err error) - Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error) - UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) - Updates(value interface{}) (info gen.ResultInfo, err error) - UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error) - UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) - UpdateColumns(value interface{}) (info gen.ResultInfo, err error) - UpdateFrom(q gen.SubQuery) gen.Dao - Attrs(attrs ...field.AssignExpr) IHealthcheckHttpHistoryDo - Assign(attrs ...field.AssignExpr) IHealthcheckHttpHistoryDo - Joins(fields ...field.RelationField) IHealthcheckHttpHistoryDo - Preload(fields ...field.RelationField) IHealthcheckHttpHistoryDo - FirstOrInit() (*models.HealthcheckHttpHistory, error) - FirstOrCreate() (*models.HealthcheckHttpHistory, error) - FindByPage(offset int, limit int) (result []*models.HealthcheckHttpHistory, count int64, err error) - ScanByPage(result interface{}, offset int, limit int) (count int64, err error) - Scan(result interface{}) (err error) - Returning(value interface{}, columns ...string) IHealthcheckHttpHistoryDo - UnderlyingDB() *gorm.DB - schema.Tabler -} - -func (h healthcheckHttpHistoryDo) Debug() IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.Debug()) -} - -func (h healthcheckHttpHistoryDo) WithContext(ctx context.Context) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.WithContext(ctx)) -} - -func (h healthcheckHttpHistoryDo) ReadDB() IHealthcheckHttpHistoryDo { - return h.Clauses(dbresolver.Read) -} - -func (h healthcheckHttpHistoryDo) WriteDB() IHealthcheckHttpHistoryDo { - return h.Clauses(dbresolver.Write) -} - -func (h healthcheckHttpHistoryDo) Session(config *gorm.Session) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.Session(config)) -} - -func (h healthcheckHttpHistoryDo) Clauses(conds ...clause.Expression) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.Clauses(conds...)) -} - -func (h healthcheckHttpHistoryDo) Returning(value interface{}, columns ...string) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.Returning(value, columns...)) -} - -func (h healthcheckHttpHistoryDo) Not(conds ...gen.Condition) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.Not(conds...)) -} - -func (h healthcheckHttpHistoryDo) Or(conds ...gen.Condition) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.Or(conds...)) -} - -func (h healthcheckHttpHistoryDo) Select(conds ...field.Expr) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.Select(conds...)) -} - -func (h healthcheckHttpHistoryDo) Where(conds ...gen.Condition) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.Where(conds...)) -} - -func (h healthcheckHttpHistoryDo) Order(conds ...field.Expr) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.Order(conds...)) -} - -func (h healthcheckHttpHistoryDo) Distinct(cols ...field.Expr) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.Distinct(cols...)) -} - -func (h healthcheckHttpHistoryDo) Omit(cols ...field.Expr) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.Omit(cols...)) -} - -func (h healthcheckHttpHistoryDo) Join(table schema.Tabler, on ...field.Expr) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.Join(table, on...)) -} - -func (h healthcheckHttpHistoryDo) LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.LeftJoin(table, on...)) -} - -func (h healthcheckHttpHistoryDo) RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.RightJoin(table, on...)) -} - -func (h healthcheckHttpHistoryDo) Group(cols ...field.Expr) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.Group(cols...)) -} - -func (h healthcheckHttpHistoryDo) Having(conds ...gen.Condition) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.Having(conds...)) -} - -func (h healthcheckHttpHistoryDo) Limit(limit int) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.Limit(limit)) -} - -func (h healthcheckHttpHistoryDo) Offset(offset int) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.Offset(offset)) -} - -func (h healthcheckHttpHistoryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.Scopes(funcs...)) -} - -func (h healthcheckHttpHistoryDo) Unscoped() IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.Unscoped()) -} - -func (h healthcheckHttpHistoryDo) Create(values ...*models.HealthcheckHttpHistory) error { - if len(values) == 0 { - return nil - } - return h.DO.Create(values) -} - -func (h healthcheckHttpHistoryDo) CreateInBatches(values []*models.HealthcheckHttpHistory, batchSize int) error { - return h.DO.CreateInBatches(values, batchSize) -} - -// Save : !!! underlying implementation is different with GORM -// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values) -func (h healthcheckHttpHistoryDo) Save(values ...*models.HealthcheckHttpHistory) error { - if len(values) == 0 { - return nil - } - return h.DO.Save(values) -} - -func (h healthcheckHttpHistoryDo) First() (*models.HealthcheckHttpHistory, error) { - if result, err := h.DO.First(); err != nil { - return nil, err - } else { - return result.(*models.HealthcheckHttpHistory), nil - } -} - -func (h healthcheckHttpHistoryDo) Take() (*models.HealthcheckHttpHistory, error) { - if result, err := h.DO.Take(); err != nil { - return nil, err - } else { - return result.(*models.HealthcheckHttpHistory), nil - } -} - -func (h healthcheckHttpHistoryDo) Last() (*models.HealthcheckHttpHistory, error) { - if result, err := h.DO.Last(); err != nil { - return nil, err - } else { - return result.(*models.HealthcheckHttpHistory), nil - } -} - -func (h healthcheckHttpHistoryDo) Find() ([]*models.HealthcheckHttpHistory, error) { - result, err := h.DO.Find() - return result.([]*models.HealthcheckHttpHistory), err -} - -func (h healthcheckHttpHistoryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckHttpHistory, err error) { - buf := make([]*models.HealthcheckHttpHistory, 0, batchSize) - err = h.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error { - defer func() { results = append(results, buf...) }() - return fc(tx, batch) - }) - return results, err -} - -func (h healthcheckHttpHistoryDo) FindInBatches(result *[]*models.HealthcheckHttpHistory, batchSize int, fc func(tx gen.Dao, batch int) error) error { - return h.DO.FindInBatches(result, batchSize, fc) -} - -func (h healthcheckHttpHistoryDo) Attrs(attrs ...field.AssignExpr) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.Attrs(attrs...)) -} - -func (h healthcheckHttpHistoryDo) Assign(attrs ...field.AssignExpr) IHealthcheckHttpHistoryDo { - return h.withDO(h.DO.Assign(attrs...)) -} - -func (h healthcheckHttpHistoryDo) Joins(fields ...field.RelationField) IHealthcheckHttpHistoryDo { - for _, _f := range fields { - h = *h.withDO(h.DO.Joins(_f)) - } - return &h -} - -func (h healthcheckHttpHistoryDo) Preload(fields ...field.RelationField) IHealthcheckHttpHistoryDo { - for _, _f := range fields { - h = *h.withDO(h.DO.Preload(_f)) - } - return &h -} - -func (h healthcheckHttpHistoryDo) FirstOrInit() (*models.HealthcheckHttpHistory, error) { - if result, err := h.DO.FirstOrInit(); err != nil { - return nil, err - } else { - return result.(*models.HealthcheckHttpHistory), nil - } -} - -func (h healthcheckHttpHistoryDo) FirstOrCreate() (*models.HealthcheckHttpHistory, error) { - if result, err := h.DO.FirstOrCreate(); err != nil { - return nil, err - } else { - return result.(*models.HealthcheckHttpHistory), nil - } -} - -func (h healthcheckHttpHistoryDo) FindByPage(offset int, limit int) (result []*models.HealthcheckHttpHistory, count int64, err error) { - result, err = h.Offset(offset).Limit(limit).Find() - if err != nil { - return - } - - if size := len(result); 0 < limit && 0 < size && size < limit { - count = int64(size + offset) - return - } - - count, err = h.Offset(-1).Limit(-1).Count() - return -} - -func (h healthcheckHttpHistoryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { - count, err = h.Count() - if err != nil { - return - } - - err = h.Offset(offset).Limit(limit).Scan(result) - return -} - -func (h healthcheckHttpHistoryDo) Scan(result interface{}) (err error) { - return h.DO.Scan(result) -} - -func (h healthcheckHttpHistoryDo) Delete(models ...*models.HealthcheckHttpHistory) (result gen.ResultInfo, err error) { - return h.DO.Delete(models) -} - -func (h *healthcheckHttpHistoryDo) withDO(do gen.Dao) *healthcheckHttpHistoryDo { - h.DO = *do.(*gen.DO) - return h -} diff --git a/internal/models/query/healthcheck_https.gen.go b/internal/models/query/healthcheck_https.gen.go deleted file mode 100644 index 04b42fd..0000000 --- a/internal/models/query/healthcheck_https.gen.go +++ /dev/null @@ -1,534 +0,0 @@ -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. - -package query - -import ( - "context" - - "gorm.io/gorm" - "gorm.io/gorm/clause" - "gorm.io/gorm/schema" - - "gorm.io/gen" - "gorm.io/gen/field" - - "gorm.io/plugin/dbresolver" - - "code.tjo.space/mentos1386/zdravko/internal/models" -) - -func newHealthcheckHttp(db *gorm.DB, opts ...gen.DOOption) healthcheckHttp { - _healthcheckHttp := healthcheckHttp{} - - _healthcheckHttp.healthcheckHttpDo.UseDB(db, opts...) - _healthcheckHttp.healthcheckHttpDo.UseModel(&models.HealthcheckHttp{}) - - tableName := _healthcheckHttp.healthcheckHttpDo.TableName() - _healthcheckHttp.ALL = field.NewAsterisk(tableName) - _healthcheckHttp.ID = field.NewUint(tableName, "id") - _healthcheckHttp.CreatedAt = field.NewTime(tableName, "created_at") - _healthcheckHttp.UpdatedAt = field.NewTime(tableName, "updated_at") - _healthcheckHttp.DeletedAt = field.NewField(tableName, "deleted_at") - _healthcheckHttp.Slug = field.NewString(tableName, "slug") - _healthcheckHttp.Name = field.NewString(tableName, "name") - _healthcheckHttp.Status = field.NewString(tableName, "status") - _healthcheckHttp.UptimePercentage = field.NewFloat64(tableName, "uptime_percentage") - _healthcheckHttp.Schedule = field.NewString(tableName, "schedule") - _healthcheckHttp.WorkerGroups = field.NewField(tableName, "worker_groups") - _healthcheckHttp.Url = field.NewString(tableName, "url") - _healthcheckHttp.Method = field.NewString(tableName, "method") - _healthcheckHttp.History = healthcheckHttpHasManyHistory{ - db: db.Session(&gorm.Session{}), - - RelationField: field.NewRelation("History", "models.HealthcheckHttpHistory"), - HealthcheckHTTP: struct { - field.RelationField - History struct { - field.RelationField - } - }{ - RelationField: field.NewRelation("History.HealthcheckHTTP", "models.HealthcheckHttp"), - History: struct { - field.RelationField - }{ - RelationField: field.NewRelation("History.HealthcheckHTTP.History", "models.HealthcheckHttpHistory"), - }, - }, - } - - _healthcheckHttp.fillFieldMap() - - return _healthcheckHttp -} - -type healthcheckHttp struct { - healthcheckHttpDo healthcheckHttpDo - - ALL field.Asterisk - ID field.Uint - CreatedAt field.Time - UpdatedAt field.Time - DeletedAt field.Field - Slug field.String - Name field.String - Status field.String - UptimePercentage field.Float64 - Schedule field.String - WorkerGroups field.Field - Url field.String - Method field.String - History healthcheckHttpHasManyHistory - - fieldMap map[string]field.Expr -} - -func (h healthcheckHttp) Table(newTableName string) *healthcheckHttp { - h.healthcheckHttpDo.UseTable(newTableName) - return h.updateTableName(newTableName) -} - -func (h healthcheckHttp) As(alias string) *healthcheckHttp { - h.healthcheckHttpDo.DO = *(h.healthcheckHttpDo.As(alias).(*gen.DO)) - return h.updateTableName(alias) -} - -func (h *healthcheckHttp) updateTableName(table string) *healthcheckHttp { - h.ALL = field.NewAsterisk(table) - h.ID = field.NewUint(table, "id") - h.CreatedAt = field.NewTime(table, "created_at") - h.UpdatedAt = field.NewTime(table, "updated_at") - h.DeletedAt = field.NewField(table, "deleted_at") - h.Slug = field.NewString(table, "slug") - h.Name = field.NewString(table, "name") - h.Status = field.NewString(table, "status") - h.UptimePercentage = field.NewFloat64(table, "uptime_percentage") - h.Schedule = field.NewString(table, "schedule") - h.WorkerGroups = field.NewField(table, "worker_groups") - h.Url = field.NewString(table, "url") - h.Method = field.NewString(table, "method") - - h.fillFieldMap() - - return h -} - -func (h *healthcheckHttp) WithContext(ctx context.Context) IHealthcheckHttpDo { - return h.healthcheckHttpDo.WithContext(ctx) -} - -func (h healthcheckHttp) TableName() string { return h.healthcheckHttpDo.TableName() } - -func (h healthcheckHttp) Alias() string { return h.healthcheckHttpDo.Alias() } - -func (h healthcheckHttp) Columns(cols ...field.Expr) gen.Columns { - return h.healthcheckHttpDo.Columns(cols...) -} - -func (h *healthcheckHttp) GetFieldByName(fieldName string) (field.OrderExpr, bool) { - _f, ok := h.fieldMap[fieldName] - if !ok || _f == nil { - return nil, false - } - _oe, ok := _f.(field.OrderExpr) - return _oe, ok -} - -func (h *healthcheckHttp) fillFieldMap() { - h.fieldMap = make(map[string]field.Expr, 13) - h.fieldMap["id"] = h.ID - h.fieldMap["created_at"] = h.CreatedAt - h.fieldMap["updated_at"] = h.UpdatedAt - h.fieldMap["deleted_at"] = h.DeletedAt - h.fieldMap["slug"] = h.Slug - h.fieldMap["name"] = h.Name - h.fieldMap["status"] = h.Status - h.fieldMap["uptime_percentage"] = h.UptimePercentage - h.fieldMap["schedule"] = h.Schedule - h.fieldMap["worker_groups"] = h.WorkerGroups - h.fieldMap["url"] = h.Url - h.fieldMap["method"] = h.Method - -} - -func (h healthcheckHttp) clone(db *gorm.DB) healthcheckHttp { - h.healthcheckHttpDo.ReplaceConnPool(db.Statement.ConnPool) - return h -} - -func (h healthcheckHttp) replaceDB(db *gorm.DB) healthcheckHttp { - h.healthcheckHttpDo.ReplaceDB(db) - return h -} - -type healthcheckHttpHasManyHistory struct { - db *gorm.DB - - field.RelationField - - HealthcheckHTTP struct { - field.RelationField - History struct { - field.RelationField - } - } -} - -func (a healthcheckHttpHasManyHistory) Where(conds ...field.Expr) *healthcheckHttpHasManyHistory { - if len(conds) == 0 { - return &a - } - - exprs := make([]clause.Expression, 0, len(conds)) - for _, cond := range conds { - exprs = append(exprs, cond.BeCond().(clause.Expression)) - } - a.db = a.db.Clauses(clause.Where{Exprs: exprs}) - return &a -} - -func (a healthcheckHttpHasManyHistory) WithContext(ctx context.Context) *healthcheckHttpHasManyHistory { - a.db = a.db.WithContext(ctx) - return &a -} - -func (a healthcheckHttpHasManyHistory) Session(session *gorm.Session) *healthcheckHttpHasManyHistory { - a.db = a.db.Session(session) - return &a -} - -func (a healthcheckHttpHasManyHistory) Model(m *models.HealthcheckHttp) *healthcheckHttpHasManyHistoryTx { - return &healthcheckHttpHasManyHistoryTx{a.db.Model(m).Association(a.Name())} -} - -type healthcheckHttpHasManyHistoryTx struct{ tx *gorm.Association } - -func (a healthcheckHttpHasManyHistoryTx) Find() (result []*models.HealthcheckHttpHistory, err error) { - return result, a.tx.Find(&result) -} - -func (a healthcheckHttpHasManyHistoryTx) Append(values ...*models.HealthcheckHttpHistory) (err error) { - targetValues := make([]interface{}, len(values)) - for i, v := range values { - targetValues[i] = v - } - return a.tx.Append(targetValues...) -} - -func (a healthcheckHttpHasManyHistoryTx) Replace(values ...*models.HealthcheckHttpHistory) (err error) { - targetValues := make([]interface{}, len(values)) - for i, v := range values { - targetValues[i] = v - } - return a.tx.Replace(targetValues...) -} - -func (a healthcheckHttpHasManyHistoryTx) Delete(values ...*models.HealthcheckHttpHistory) (err error) { - targetValues := make([]interface{}, len(values)) - for i, v := range values { - targetValues[i] = v - } - return a.tx.Delete(targetValues...) -} - -func (a healthcheckHttpHasManyHistoryTx) Clear() error { - return a.tx.Clear() -} - -func (a healthcheckHttpHasManyHistoryTx) Count() int64 { - return a.tx.Count() -} - -type healthcheckHttpDo struct{ gen.DO } - -type IHealthcheckHttpDo interface { - gen.SubQuery - Debug() IHealthcheckHttpDo - WithContext(ctx context.Context) IHealthcheckHttpDo - WithResult(fc func(tx gen.Dao)) gen.ResultInfo - ReplaceDB(db *gorm.DB) - ReadDB() IHealthcheckHttpDo - WriteDB() IHealthcheckHttpDo - As(alias string) gen.Dao - Session(config *gorm.Session) IHealthcheckHttpDo - Columns(cols ...field.Expr) gen.Columns - Clauses(conds ...clause.Expression) IHealthcheckHttpDo - Not(conds ...gen.Condition) IHealthcheckHttpDo - Or(conds ...gen.Condition) IHealthcheckHttpDo - Select(conds ...field.Expr) IHealthcheckHttpDo - Where(conds ...gen.Condition) IHealthcheckHttpDo - Order(conds ...field.Expr) IHealthcheckHttpDo - Distinct(cols ...field.Expr) IHealthcheckHttpDo - Omit(cols ...field.Expr) IHealthcheckHttpDo - Join(table schema.Tabler, on ...field.Expr) IHealthcheckHttpDo - LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHttpDo - RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHttpDo - Group(cols ...field.Expr) IHealthcheckHttpDo - Having(conds ...gen.Condition) IHealthcheckHttpDo - Limit(limit int) IHealthcheckHttpDo - Offset(offset int) IHealthcheckHttpDo - Count() (count int64, err error) - Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckHttpDo - Unscoped() IHealthcheckHttpDo - Create(values ...*models.HealthcheckHttp) error - CreateInBatches(values []*models.HealthcheckHttp, batchSize int) error - Save(values ...*models.HealthcheckHttp) error - First() (*models.HealthcheckHttp, error) - Take() (*models.HealthcheckHttp, error) - Last() (*models.HealthcheckHttp, error) - Find() ([]*models.HealthcheckHttp, error) - FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckHttp, err error) - FindInBatches(result *[]*models.HealthcheckHttp, batchSize int, fc func(tx gen.Dao, batch int) error) error - Pluck(column field.Expr, dest interface{}) error - Delete(...*models.HealthcheckHttp) (info gen.ResultInfo, err error) - Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error) - UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) - Updates(value interface{}) (info gen.ResultInfo, err error) - UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error) - UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) - UpdateColumns(value interface{}) (info gen.ResultInfo, err error) - UpdateFrom(q gen.SubQuery) gen.Dao - Attrs(attrs ...field.AssignExpr) IHealthcheckHttpDo - Assign(attrs ...field.AssignExpr) IHealthcheckHttpDo - Joins(fields ...field.RelationField) IHealthcheckHttpDo - Preload(fields ...field.RelationField) IHealthcheckHttpDo - FirstOrInit() (*models.HealthcheckHttp, error) - FirstOrCreate() (*models.HealthcheckHttp, error) - FindByPage(offset int, limit int) (result []*models.HealthcheckHttp, count int64, err error) - ScanByPage(result interface{}, offset int, limit int) (count int64, err error) - Scan(result interface{}) (err error) - Returning(value interface{}, columns ...string) IHealthcheckHttpDo - UnderlyingDB() *gorm.DB - schema.Tabler -} - -func (h healthcheckHttpDo) Debug() IHealthcheckHttpDo { - return h.withDO(h.DO.Debug()) -} - -func (h healthcheckHttpDo) WithContext(ctx context.Context) IHealthcheckHttpDo { - return h.withDO(h.DO.WithContext(ctx)) -} - -func (h healthcheckHttpDo) ReadDB() IHealthcheckHttpDo { - return h.Clauses(dbresolver.Read) -} - -func (h healthcheckHttpDo) WriteDB() IHealthcheckHttpDo { - return h.Clauses(dbresolver.Write) -} - -func (h healthcheckHttpDo) Session(config *gorm.Session) IHealthcheckHttpDo { - return h.withDO(h.DO.Session(config)) -} - -func (h healthcheckHttpDo) Clauses(conds ...clause.Expression) IHealthcheckHttpDo { - return h.withDO(h.DO.Clauses(conds...)) -} - -func (h healthcheckHttpDo) Returning(value interface{}, columns ...string) IHealthcheckHttpDo { - return h.withDO(h.DO.Returning(value, columns...)) -} - -func (h healthcheckHttpDo) Not(conds ...gen.Condition) IHealthcheckHttpDo { - return h.withDO(h.DO.Not(conds...)) -} - -func (h healthcheckHttpDo) Or(conds ...gen.Condition) IHealthcheckHttpDo { - return h.withDO(h.DO.Or(conds...)) -} - -func (h healthcheckHttpDo) Select(conds ...field.Expr) IHealthcheckHttpDo { - return h.withDO(h.DO.Select(conds...)) -} - -func (h healthcheckHttpDo) Where(conds ...gen.Condition) IHealthcheckHttpDo { - return h.withDO(h.DO.Where(conds...)) -} - -func (h healthcheckHttpDo) Order(conds ...field.Expr) IHealthcheckHttpDo { - return h.withDO(h.DO.Order(conds...)) -} - -func (h healthcheckHttpDo) Distinct(cols ...field.Expr) IHealthcheckHttpDo { - return h.withDO(h.DO.Distinct(cols...)) -} - -func (h healthcheckHttpDo) Omit(cols ...field.Expr) IHealthcheckHttpDo { - return h.withDO(h.DO.Omit(cols...)) -} - -func (h healthcheckHttpDo) Join(table schema.Tabler, on ...field.Expr) IHealthcheckHttpDo { - return h.withDO(h.DO.Join(table, on...)) -} - -func (h healthcheckHttpDo) LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHttpDo { - return h.withDO(h.DO.LeftJoin(table, on...)) -} - -func (h healthcheckHttpDo) RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHttpDo { - return h.withDO(h.DO.RightJoin(table, on...)) -} - -func (h healthcheckHttpDo) Group(cols ...field.Expr) IHealthcheckHttpDo { - return h.withDO(h.DO.Group(cols...)) -} - -func (h healthcheckHttpDo) Having(conds ...gen.Condition) IHealthcheckHttpDo { - return h.withDO(h.DO.Having(conds...)) -} - -func (h healthcheckHttpDo) Limit(limit int) IHealthcheckHttpDo { - return h.withDO(h.DO.Limit(limit)) -} - -func (h healthcheckHttpDo) Offset(offset int) IHealthcheckHttpDo { - return h.withDO(h.DO.Offset(offset)) -} - -func (h healthcheckHttpDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckHttpDo { - return h.withDO(h.DO.Scopes(funcs...)) -} - -func (h healthcheckHttpDo) Unscoped() IHealthcheckHttpDo { - return h.withDO(h.DO.Unscoped()) -} - -func (h healthcheckHttpDo) Create(values ...*models.HealthcheckHttp) error { - if len(values) == 0 { - return nil - } - return h.DO.Create(values) -} - -func (h healthcheckHttpDo) CreateInBatches(values []*models.HealthcheckHttp, batchSize int) error { - return h.DO.CreateInBatches(values, batchSize) -} - -// Save : !!! underlying implementation is different with GORM -// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values) -func (h healthcheckHttpDo) Save(values ...*models.HealthcheckHttp) error { - if len(values) == 0 { - return nil - } - return h.DO.Save(values) -} - -func (h healthcheckHttpDo) First() (*models.HealthcheckHttp, error) { - if result, err := h.DO.First(); err != nil { - return nil, err - } else { - return result.(*models.HealthcheckHttp), nil - } -} - -func (h healthcheckHttpDo) Take() (*models.HealthcheckHttp, error) { - if result, err := h.DO.Take(); err != nil { - return nil, err - } else { - return result.(*models.HealthcheckHttp), nil - } -} - -func (h healthcheckHttpDo) Last() (*models.HealthcheckHttp, error) { - if result, err := h.DO.Last(); err != nil { - return nil, err - } else { - return result.(*models.HealthcheckHttp), nil - } -} - -func (h healthcheckHttpDo) Find() ([]*models.HealthcheckHttp, error) { - result, err := h.DO.Find() - return result.([]*models.HealthcheckHttp), err -} - -func (h healthcheckHttpDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckHttp, err error) { - buf := make([]*models.HealthcheckHttp, 0, batchSize) - err = h.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error { - defer func() { results = append(results, buf...) }() - return fc(tx, batch) - }) - return results, err -} - -func (h healthcheckHttpDo) FindInBatches(result *[]*models.HealthcheckHttp, batchSize int, fc func(tx gen.Dao, batch int) error) error { - return h.DO.FindInBatches(result, batchSize, fc) -} - -func (h healthcheckHttpDo) Attrs(attrs ...field.AssignExpr) IHealthcheckHttpDo { - return h.withDO(h.DO.Attrs(attrs...)) -} - -func (h healthcheckHttpDo) Assign(attrs ...field.AssignExpr) IHealthcheckHttpDo { - return h.withDO(h.DO.Assign(attrs...)) -} - -func (h healthcheckHttpDo) Joins(fields ...field.RelationField) IHealthcheckHttpDo { - for _, _f := range fields { - h = *h.withDO(h.DO.Joins(_f)) - } - return &h -} - -func (h healthcheckHttpDo) Preload(fields ...field.RelationField) IHealthcheckHttpDo { - for _, _f := range fields { - h = *h.withDO(h.DO.Preload(_f)) - } - return &h -} - -func (h healthcheckHttpDo) FirstOrInit() (*models.HealthcheckHttp, error) { - if result, err := h.DO.FirstOrInit(); err != nil { - return nil, err - } else { - return result.(*models.HealthcheckHttp), nil - } -} - -func (h healthcheckHttpDo) FirstOrCreate() (*models.HealthcheckHttp, error) { - if result, err := h.DO.FirstOrCreate(); err != nil { - return nil, err - } else { - return result.(*models.HealthcheckHttp), nil - } -} - -func (h healthcheckHttpDo) FindByPage(offset int, limit int) (result []*models.HealthcheckHttp, count int64, err error) { - result, err = h.Offset(offset).Limit(limit).Find() - if err != nil { - return - } - - if size := len(result); 0 < limit && 0 < size && size < limit { - count = int64(size + offset) - return - } - - count, err = h.Offset(-1).Limit(-1).Count() - return -} - -func (h healthcheckHttpDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { - count, err = h.Count() - if err != nil { - return - } - - err = h.Offset(offset).Limit(limit).Scan(result) - return -} - -func (h healthcheckHttpDo) Scan(result interface{}) (err error) { - return h.DO.Scan(result) -} - -func (h healthcheckHttpDo) Delete(models ...*models.HealthcheckHttp) (result gen.ResultInfo, err error) { - return h.DO.Delete(models) -} - -func (h *healthcheckHttpDo) withDO(do gen.Dao) *healthcheckHttpDo { - h.DO = *do.(*gen.DO) - return h -} diff --git a/internal/models/query/healthcheck_tcp_histories.gen.go b/internal/models/query/healthcheck_tcp_histories.gen.go deleted file mode 100644 index 3d96861..0000000 --- a/internal/models/query/healthcheck_tcp_histories.gen.go +++ /dev/null @@ -1,486 +0,0 @@ -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. - -package query - -import ( - "context" - - "gorm.io/gorm" - "gorm.io/gorm/clause" - "gorm.io/gorm/schema" - - "gorm.io/gen" - "gorm.io/gen/field" - - "gorm.io/plugin/dbresolver" - - "code.tjo.space/mentos1386/zdravko/internal/models" -) - -func newHealthcheckTcpHistory(db *gorm.DB, opts ...gen.DOOption) healthcheckTcpHistory { - _healthcheckTcpHistory := healthcheckTcpHistory{} - - _healthcheckTcpHistory.healthcheckTcpHistoryDo.UseDB(db, opts...) - _healthcheckTcpHistory.healthcheckTcpHistoryDo.UseModel(&models.HealthcheckTcpHistory{}) - - tableName := _healthcheckTcpHistory.healthcheckTcpHistoryDo.TableName() - _healthcheckTcpHistory.ALL = field.NewAsterisk(tableName) - _healthcheckTcpHistory.ID = field.NewUint(tableName, "id") - _healthcheckTcpHistory.CreatedAt = field.NewTime(tableName, "created_at") - _healthcheckTcpHistory.UpdatedAt = field.NewTime(tableName, "updated_at") - _healthcheckTcpHistory.DeletedAt = field.NewField(tableName, "deleted_at") - _healthcheckTcpHistory.Status = field.NewString(tableName, "status") - _healthcheckTcpHistory.HealthcheckTCP = healthcheckTcpHistoryHasOneHealthcheckTCP{ - db: db.Session(&gorm.Session{}), - - RelationField: field.NewRelation("HealthcheckTCP", "models.HealthcheckTcp"), - } - - _healthcheckTcpHistory.fillFieldMap() - - return _healthcheckTcpHistory -} - -type healthcheckTcpHistory struct { - healthcheckTcpHistoryDo healthcheckTcpHistoryDo - - ALL field.Asterisk - ID field.Uint - CreatedAt field.Time - UpdatedAt field.Time - DeletedAt field.Field - Status field.String - HealthcheckTCP healthcheckTcpHistoryHasOneHealthcheckTCP - - fieldMap map[string]field.Expr -} - -func (h healthcheckTcpHistory) Table(newTableName string) *healthcheckTcpHistory { - h.healthcheckTcpHistoryDo.UseTable(newTableName) - return h.updateTableName(newTableName) -} - -func (h healthcheckTcpHistory) As(alias string) *healthcheckTcpHistory { - h.healthcheckTcpHistoryDo.DO = *(h.healthcheckTcpHistoryDo.As(alias).(*gen.DO)) - return h.updateTableName(alias) -} - -func (h *healthcheckTcpHistory) updateTableName(table string) *healthcheckTcpHistory { - h.ALL = field.NewAsterisk(table) - h.ID = field.NewUint(table, "id") - h.CreatedAt = field.NewTime(table, "created_at") - h.UpdatedAt = field.NewTime(table, "updated_at") - h.DeletedAt = field.NewField(table, "deleted_at") - h.Status = field.NewString(table, "status") - - h.fillFieldMap() - - return h -} - -func (h *healthcheckTcpHistory) WithContext(ctx context.Context) IHealthcheckTcpHistoryDo { - return h.healthcheckTcpHistoryDo.WithContext(ctx) -} - -func (h healthcheckTcpHistory) TableName() string { return h.healthcheckTcpHistoryDo.TableName() } - -func (h healthcheckTcpHistory) Alias() string { return h.healthcheckTcpHistoryDo.Alias() } - -func (h healthcheckTcpHistory) Columns(cols ...field.Expr) gen.Columns { - return h.healthcheckTcpHistoryDo.Columns(cols...) -} - -func (h *healthcheckTcpHistory) GetFieldByName(fieldName string) (field.OrderExpr, bool) { - _f, ok := h.fieldMap[fieldName] - if !ok || _f == nil { - return nil, false - } - _oe, ok := _f.(field.OrderExpr) - return _oe, ok -} - -func (h *healthcheckTcpHistory) fillFieldMap() { - h.fieldMap = make(map[string]field.Expr, 6) - h.fieldMap["id"] = h.ID - h.fieldMap["created_at"] = h.CreatedAt - h.fieldMap["updated_at"] = h.UpdatedAt - h.fieldMap["deleted_at"] = h.DeletedAt - h.fieldMap["status"] = h.Status - -} - -func (h healthcheckTcpHistory) clone(db *gorm.DB) healthcheckTcpHistory { - h.healthcheckTcpHistoryDo.ReplaceConnPool(db.Statement.ConnPool) - return h -} - -func (h healthcheckTcpHistory) replaceDB(db *gorm.DB) healthcheckTcpHistory { - h.healthcheckTcpHistoryDo.ReplaceDB(db) - return h -} - -type healthcheckTcpHistoryHasOneHealthcheckTCP struct { - db *gorm.DB - - field.RelationField -} - -func (a healthcheckTcpHistoryHasOneHealthcheckTCP) Where(conds ...field.Expr) *healthcheckTcpHistoryHasOneHealthcheckTCP { - if len(conds) == 0 { - return &a - } - - exprs := make([]clause.Expression, 0, len(conds)) - for _, cond := range conds { - exprs = append(exprs, cond.BeCond().(clause.Expression)) - } - a.db = a.db.Clauses(clause.Where{Exprs: exprs}) - return &a -} - -func (a healthcheckTcpHistoryHasOneHealthcheckTCP) WithContext(ctx context.Context) *healthcheckTcpHistoryHasOneHealthcheckTCP { - a.db = a.db.WithContext(ctx) - return &a -} - -func (a healthcheckTcpHistoryHasOneHealthcheckTCP) Session(session *gorm.Session) *healthcheckTcpHistoryHasOneHealthcheckTCP { - a.db = a.db.Session(session) - return &a -} - -func (a healthcheckTcpHistoryHasOneHealthcheckTCP) Model(m *models.HealthcheckTcpHistory) *healthcheckTcpHistoryHasOneHealthcheckTCPTx { - return &healthcheckTcpHistoryHasOneHealthcheckTCPTx{a.db.Model(m).Association(a.Name())} -} - -type healthcheckTcpHistoryHasOneHealthcheckTCPTx struct{ tx *gorm.Association } - -func (a healthcheckTcpHistoryHasOneHealthcheckTCPTx) Find() (result *models.HealthcheckTcp, err error) { - return result, a.tx.Find(&result) -} - -func (a healthcheckTcpHistoryHasOneHealthcheckTCPTx) Append(values ...*models.HealthcheckTcp) (err error) { - targetValues := make([]interface{}, len(values)) - for i, v := range values { - targetValues[i] = v - } - return a.tx.Append(targetValues...) -} - -func (a healthcheckTcpHistoryHasOneHealthcheckTCPTx) Replace(values ...*models.HealthcheckTcp) (err error) { - targetValues := make([]interface{}, len(values)) - for i, v := range values { - targetValues[i] = v - } - return a.tx.Replace(targetValues...) -} - -func (a healthcheckTcpHistoryHasOneHealthcheckTCPTx) Delete(values ...*models.HealthcheckTcp) (err error) { - targetValues := make([]interface{}, len(values)) - for i, v := range values { - targetValues[i] = v - } - return a.tx.Delete(targetValues...) -} - -func (a healthcheckTcpHistoryHasOneHealthcheckTCPTx) Clear() error { - return a.tx.Clear() -} - -func (a healthcheckTcpHistoryHasOneHealthcheckTCPTx) Count() int64 { - return a.tx.Count() -} - -type healthcheckTcpHistoryDo struct{ gen.DO } - -type IHealthcheckTcpHistoryDo interface { - gen.SubQuery - Debug() IHealthcheckTcpHistoryDo - WithContext(ctx context.Context) IHealthcheckTcpHistoryDo - WithResult(fc func(tx gen.Dao)) gen.ResultInfo - ReplaceDB(db *gorm.DB) - ReadDB() IHealthcheckTcpHistoryDo - WriteDB() IHealthcheckTcpHistoryDo - As(alias string) gen.Dao - Session(config *gorm.Session) IHealthcheckTcpHistoryDo - Columns(cols ...field.Expr) gen.Columns - Clauses(conds ...clause.Expression) IHealthcheckTcpHistoryDo - Not(conds ...gen.Condition) IHealthcheckTcpHistoryDo - Or(conds ...gen.Condition) IHealthcheckTcpHistoryDo - Select(conds ...field.Expr) IHealthcheckTcpHistoryDo - Where(conds ...gen.Condition) IHealthcheckTcpHistoryDo - Order(conds ...field.Expr) IHealthcheckTcpHistoryDo - Distinct(cols ...field.Expr) IHealthcheckTcpHistoryDo - Omit(cols ...field.Expr) IHealthcheckTcpHistoryDo - Join(table schema.Tabler, on ...field.Expr) IHealthcheckTcpHistoryDo - LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckTcpHistoryDo - RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckTcpHistoryDo - Group(cols ...field.Expr) IHealthcheckTcpHistoryDo - Having(conds ...gen.Condition) IHealthcheckTcpHistoryDo - Limit(limit int) IHealthcheckTcpHistoryDo - Offset(offset int) IHealthcheckTcpHistoryDo - Count() (count int64, err error) - Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckTcpHistoryDo - Unscoped() IHealthcheckTcpHistoryDo - Create(values ...*models.HealthcheckTcpHistory) error - CreateInBatches(values []*models.HealthcheckTcpHistory, batchSize int) error - Save(values ...*models.HealthcheckTcpHistory) error - First() (*models.HealthcheckTcpHistory, error) - Take() (*models.HealthcheckTcpHistory, error) - Last() (*models.HealthcheckTcpHistory, error) - Find() ([]*models.HealthcheckTcpHistory, error) - FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckTcpHistory, err error) - FindInBatches(result *[]*models.HealthcheckTcpHistory, batchSize int, fc func(tx gen.Dao, batch int) error) error - Pluck(column field.Expr, dest interface{}) error - Delete(...*models.HealthcheckTcpHistory) (info gen.ResultInfo, err error) - Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error) - UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) - Updates(value interface{}) (info gen.ResultInfo, err error) - UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error) - UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) - UpdateColumns(value interface{}) (info gen.ResultInfo, err error) - UpdateFrom(q gen.SubQuery) gen.Dao - Attrs(attrs ...field.AssignExpr) IHealthcheckTcpHistoryDo - Assign(attrs ...field.AssignExpr) IHealthcheckTcpHistoryDo - Joins(fields ...field.RelationField) IHealthcheckTcpHistoryDo - Preload(fields ...field.RelationField) IHealthcheckTcpHistoryDo - FirstOrInit() (*models.HealthcheckTcpHistory, error) - FirstOrCreate() (*models.HealthcheckTcpHistory, error) - FindByPage(offset int, limit int) (result []*models.HealthcheckTcpHistory, count int64, err error) - ScanByPage(result interface{}, offset int, limit int) (count int64, err error) - Scan(result interface{}) (err error) - Returning(value interface{}, columns ...string) IHealthcheckTcpHistoryDo - UnderlyingDB() *gorm.DB - schema.Tabler -} - -func (h healthcheckTcpHistoryDo) Debug() IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.Debug()) -} - -func (h healthcheckTcpHistoryDo) WithContext(ctx context.Context) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.WithContext(ctx)) -} - -func (h healthcheckTcpHistoryDo) ReadDB() IHealthcheckTcpHistoryDo { - return h.Clauses(dbresolver.Read) -} - -func (h healthcheckTcpHistoryDo) WriteDB() IHealthcheckTcpHistoryDo { - return h.Clauses(dbresolver.Write) -} - -func (h healthcheckTcpHistoryDo) Session(config *gorm.Session) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.Session(config)) -} - -func (h healthcheckTcpHistoryDo) Clauses(conds ...clause.Expression) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.Clauses(conds...)) -} - -func (h healthcheckTcpHistoryDo) Returning(value interface{}, columns ...string) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.Returning(value, columns...)) -} - -func (h healthcheckTcpHistoryDo) Not(conds ...gen.Condition) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.Not(conds...)) -} - -func (h healthcheckTcpHistoryDo) Or(conds ...gen.Condition) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.Or(conds...)) -} - -func (h healthcheckTcpHistoryDo) Select(conds ...field.Expr) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.Select(conds...)) -} - -func (h healthcheckTcpHistoryDo) Where(conds ...gen.Condition) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.Where(conds...)) -} - -func (h healthcheckTcpHistoryDo) Order(conds ...field.Expr) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.Order(conds...)) -} - -func (h healthcheckTcpHistoryDo) Distinct(cols ...field.Expr) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.Distinct(cols...)) -} - -func (h healthcheckTcpHistoryDo) Omit(cols ...field.Expr) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.Omit(cols...)) -} - -func (h healthcheckTcpHistoryDo) Join(table schema.Tabler, on ...field.Expr) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.Join(table, on...)) -} - -func (h healthcheckTcpHistoryDo) LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.LeftJoin(table, on...)) -} - -func (h healthcheckTcpHistoryDo) RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.RightJoin(table, on...)) -} - -func (h healthcheckTcpHistoryDo) Group(cols ...field.Expr) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.Group(cols...)) -} - -func (h healthcheckTcpHistoryDo) Having(conds ...gen.Condition) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.Having(conds...)) -} - -func (h healthcheckTcpHistoryDo) Limit(limit int) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.Limit(limit)) -} - -func (h healthcheckTcpHistoryDo) Offset(offset int) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.Offset(offset)) -} - -func (h healthcheckTcpHistoryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.Scopes(funcs...)) -} - -func (h healthcheckTcpHistoryDo) Unscoped() IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.Unscoped()) -} - -func (h healthcheckTcpHistoryDo) Create(values ...*models.HealthcheckTcpHistory) error { - if len(values) == 0 { - return nil - } - return h.DO.Create(values) -} - -func (h healthcheckTcpHistoryDo) CreateInBatches(values []*models.HealthcheckTcpHistory, batchSize int) error { - return h.DO.CreateInBatches(values, batchSize) -} - -// Save : !!! underlying implementation is different with GORM -// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values) -func (h healthcheckTcpHistoryDo) Save(values ...*models.HealthcheckTcpHistory) error { - if len(values) == 0 { - return nil - } - return h.DO.Save(values) -} - -func (h healthcheckTcpHistoryDo) First() (*models.HealthcheckTcpHistory, error) { - if result, err := h.DO.First(); err != nil { - return nil, err - } else { - return result.(*models.HealthcheckTcpHistory), nil - } -} - -func (h healthcheckTcpHistoryDo) Take() (*models.HealthcheckTcpHistory, error) { - if result, err := h.DO.Take(); err != nil { - return nil, err - } else { - return result.(*models.HealthcheckTcpHistory), nil - } -} - -func (h healthcheckTcpHistoryDo) Last() (*models.HealthcheckTcpHistory, error) { - if result, err := h.DO.Last(); err != nil { - return nil, err - } else { - return result.(*models.HealthcheckTcpHistory), nil - } -} - -func (h healthcheckTcpHistoryDo) Find() ([]*models.HealthcheckTcpHistory, error) { - result, err := h.DO.Find() - return result.([]*models.HealthcheckTcpHistory), err -} - -func (h healthcheckTcpHistoryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckTcpHistory, err error) { - buf := make([]*models.HealthcheckTcpHistory, 0, batchSize) - err = h.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error { - defer func() { results = append(results, buf...) }() - return fc(tx, batch) - }) - return results, err -} - -func (h healthcheckTcpHistoryDo) FindInBatches(result *[]*models.HealthcheckTcpHistory, batchSize int, fc func(tx gen.Dao, batch int) error) error { - return h.DO.FindInBatches(result, batchSize, fc) -} - -func (h healthcheckTcpHistoryDo) Attrs(attrs ...field.AssignExpr) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.Attrs(attrs...)) -} - -func (h healthcheckTcpHistoryDo) Assign(attrs ...field.AssignExpr) IHealthcheckTcpHistoryDo { - return h.withDO(h.DO.Assign(attrs...)) -} - -func (h healthcheckTcpHistoryDo) Joins(fields ...field.RelationField) IHealthcheckTcpHistoryDo { - for _, _f := range fields { - h = *h.withDO(h.DO.Joins(_f)) - } - return &h -} - -func (h healthcheckTcpHistoryDo) Preload(fields ...field.RelationField) IHealthcheckTcpHistoryDo { - for _, _f := range fields { - h = *h.withDO(h.DO.Preload(_f)) - } - return &h -} - -func (h healthcheckTcpHistoryDo) FirstOrInit() (*models.HealthcheckTcpHistory, error) { - if result, err := h.DO.FirstOrInit(); err != nil { - return nil, err - } else { - return result.(*models.HealthcheckTcpHistory), nil - } -} - -func (h healthcheckTcpHistoryDo) FirstOrCreate() (*models.HealthcheckTcpHistory, error) { - if result, err := h.DO.FirstOrCreate(); err != nil { - return nil, err - } else { - return result.(*models.HealthcheckTcpHistory), nil - } -} - -func (h healthcheckTcpHistoryDo) FindByPage(offset int, limit int) (result []*models.HealthcheckTcpHistory, count int64, err error) { - result, err = h.Offset(offset).Limit(limit).Find() - if err != nil { - return - } - - if size := len(result); 0 < limit && 0 < size && size < limit { - count = int64(size + offset) - return - } - - count, err = h.Offset(-1).Limit(-1).Count() - return -} - -func (h healthcheckTcpHistoryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { - count, err = h.Count() - if err != nil { - return - } - - err = h.Offset(offset).Limit(limit).Scan(result) - return -} - -func (h healthcheckTcpHistoryDo) Scan(result interface{}) (err error) { - return h.DO.Scan(result) -} - -func (h healthcheckTcpHistoryDo) Delete(models ...*models.HealthcheckTcpHistory) (result gen.ResultInfo, err error) { - return h.DO.Delete(models) -} - -func (h *healthcheckTcpHistoryDo) withDO(do gen.Dao) *healthcheckTcpHistoryDo { - h.DO = *do.(*gen.DO) - return h -} diff --git a/internal/models/query/healthcheck_tcps.gen.go b/internal/models/query/healthcheck_tcps.gen.go deleted file mode 100644 index 2c1859a..0000000 --- a/internal/models/query/healthcheck_tcps.gen.go +++ /dev/null @@ -1,436 +0,0 @@ -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. - -package query - -import ( - "context" - - "gorm.io/gorm" - "gorm.io/gorm/clause" - "gorm.io/gorm/schema" - - "gorm.io/gen" - "gorm.io/gen/field" - - "gorm.io/plugin/dbresolver" - - "code.tjo.space/mentos1386/zdravko/internal/models" -) - -func newHealthcheckTcp(db *gorm.DB, opts ...gen.DOOption) healthcheckTcp { - _healthcheckTcp := healthcheckTcp{} - - _healthcheckTcp.healthcheckTcpDo.UseDB(db, opts...) - _healthcheckTcp.healthcheckTcpDo.UseModel(&models.HealthcheckTcp{}) - - tableName := _healthcheckTcp.healthcheckTcpDo.TableName() - _healthcheckTcp.ALL = field.NewAsterisk(tableName) - _healthcheckTcp.ID = field.NewUint(tableName, "id") - _healthcheckTcp.CreatedAt = field.NewTime(tableName, "created_at") - _healthcheckTcp.UpdatedAt = field.NewTime(tableName, "updated_at") - _healthcheckTcp.DeletedAt = field.NewField(tableName, "deleted_at") - _healthcheckTcp.Slug = field.NewString(tableName, "slug") - _healthcheckTcp.Name = field.NewString(tableName, "name") - _healthcheckTcp.Status = field.NewString(tableName, "status") - _healthcheckTcp.UptimePercentage = field.NewFloat64(tableName, "uptime_percentage") - _healthcheckTcp.Schedule = field.NewString(tableName, "schedule") - _healthcheckTcp.WorkerGroups = field.NewField(tableName, "worker_groups") - _healthcheckTcp.Hostname = field.NewString(tableName, "hostname") - _healthcheckTcp.Port = field.NewInt(tableName, "port") - - _healthcheckTcp.fillFieldMap() - - return _healthcheckTcp -} - -type healthcheckTcp struct { - healthcheckTcpDo healthcheckTcpDo - - ALL field.Asterisk - ID field.Uint - CreatedAt field.Time - UpdatedAt field.Time - DeletedAt field.Field - Slug field.String - Name field.String - Status field.String - UptimePercentage field.Float64 - Schedule field.String - WorkerGroups field.Field - Hostname field.String - Port field.Int - - fieldMap map[string]field.Expr -} - -func (h healthcheckTcp) Table(newTableName string) *healthcheckTcp { - h.healthcheckTcpDo.UseTable(newTableName) - return h.updateTableName(newTableName) -} - -func (h healthcheckTcp) As(alias string) *healthcheckTcp { - h.healthcheckTcpDo.DO = *(h.healthcheckTcpDo.As(alias).(*gen.DO)) - return h.updateTableName(alias) -} - -func (h *healthcheckTcp) updateTableName(table string) *healthcheckTcp { - h.ALL = field.NewAsterisk(table) - h.ID = field.NewUint(table, "id") - h.CreatedAt = field.NewTime(table, "created_at") - h.UpdatedAt = field.NewTime(table, "updated_at") - h.DeletedAt = field.NewField(table, "deleted_at") - h.Slug = field.NewString(table, "slug") - h.Name = field.NewString(table, "name") - h.Status = field.NewString(table, "status") - h.UptimePercentage = field.NewFloat64(table, "uptime_percentage") - h.Schedule = field.NewString(table, "schedule") - h.WorkerGroups = field.NewField(table, "worker_groups") - h.Hostname = field.NewString(table, "hostname") - h.Port = field.NewInt(table, "port") - - h.fillFieldMap() - - return h -} - -func (h *healthcheckTcp) WithContext(ctx context.Context) IHealthcheckTcpDo { - return h.healthcheckTcpDo.WithContext(ctx) -} - -func (h healthcheckTcp) TableName() string { return h.healthcheckTcpDo.TableName() } - -func (h healthcheckTcp) Alias() string { return h.healthcheckTcpDo.Alias() } - -func (h healthcheckTcp) Columns(cols ...field.Expr) gen.Columns { - return h.healthcheckTcpDo.Columns(cols...) -} - -func (h *healthcheckTcp) GetFieldByName(fieldName string) (field.OrderExpr, bool) { - _f, ok := h.fieldMap[fieldName] - if !ok || _f == nil { - return nil, false - } - _oe, ok := _f.(field.OrderExpr) - return _oe, ok -} - -func (h *healthcheckTcp) fillFieldMap() { - h.fieldMap = make(map[string]field.Expr, 12) - h.fieldMap["id"] = h.ID - h.fieldMap["created_at"] = h.CreatedAt - h.fieldMap["updated_at"] = h.UpdatedAt - h.fieldMap["deleted_at"] = h.DeletedAt - h.fieldMap["slug"] = h.Slug - h.fieldMap["name"] = h.Name - h.fieldMap["status"] = h.Status - h.fieldMap["uptime_percentage"] = h.UptimePercentage - h.fieldMap["schedule"] = h.Schedule - h.fieldMap["worker_groups"] = h.WorkerGroups - h.fieldMap["hostname"] = h.Hostname - h.fieldMap["port"] = h.Port -} - -func (h healthcheckTcp) clone(db *gorm.DB) healthcheckTcp { - h.healthcheckTcpDo.ReplaceConnPool(db.Statement.ConnPool) - return h -} - -func (h healthcheckTcp) replaceDB(db *gorm.DB) healthcheckTcp { - h.healthcheckTcpDo.ReplaceDB(db) - return h -} - -type healthcheckTcpDo struct{ gen.DO } - -type IHealthcheckTcpDo interface { - gen.SubQuery - Debug() IHealthcheckTcpDo - WithContext(ctx context.Context) IHealthcheckTcpDo - WithResult(fc func(tx gen.Dao)) gen.ResultInfo - ReplaceDB(db *gorm.DB) - ReadDB() IHealthcheckTcpDo - WriteDB() IHealthcheckTcpDo - As(alias string) gen.Dao - Session(config *gorm.Session) IHealthcheckTcpDo - Columns(cols ...field.Expr) gen.Columns - Clauses(conds ...clause.Expression) IHealthcheckTcpDo - Not(conds ...gen.Condition) IHealthcheckTcpDo - Or(conds ...gen.Condition) IHealthcheckTcpDo - Select(conds ...field.Expr) IHealthcheckTcpDo - Where(conds ...gen.Condition) IHealthcheckTcpDo - Order(conds ...field.Expr) IHealthcheckTcpDo - Distinct(cols ...field.Expr) IHealthcheckTcpDo - Omit(cols ...field.Expr) IHealthcheckTcpDo - Join(table schema.Tabler, on ...field.Expr) IHealthcheckTcpDo - LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckTcpDo - RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckTcpDo - Group(cols ...field.Expr) IHealthcheckTcpDo - Having(conds ...gen.Condition) IHealthcheckTcpDo - Limit(limit int) IHealthcheckTcpDo - Offset(offset int) IHealthcheckTcpDo - Count() (count int64, err error) - Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckTcpDo - Unscoped() IHealthcheckTcpDo - Create(values ...*models.HealthcheckTcp) error - CreateInBatches(values []*models.HealthcheckTcp, batchSize int) error - Save(values ...*models.HealthcheckTcp) error - First() (*models.HealthcheckTcp, error) - Take() (*models.HealthcheckTcp, error) - Last() (*models.HealthcheckTcp, error) - Find() ([]*models.HealthcheckTcp, error) - FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckTcp, err error) - FindInBatches(result *[]*models.HealthcheckTcp, batchSize int, fc func(tx gen.Dao, batch int) error) error - Pluck(column field.Expr, dest interface{}) error - Delete(...*models.HealthcheckTcp) (info gen.ResultInfo, err error) - Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error) - UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) - Updates(value interface{}) (info gen.ResultInfo, err error) - UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error) - UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) - UpdateColumns(value interface{}) (info gen.ResultInfo, err error) - UpdateFrom(q gen.SubQuery) gen.Dao - Attrs(attrs ...field.AssignExpr) IHealthcheckTcpDo - Assign(attrs ...field.AssignExpr) IHealthcheckTcpDo - Joins(fields ...field.RelationField) IHealthcheckTcpDo - Preload(fields ...field.RelationField) IHealthcheckTcpDo - FirstOrInit() (*models.HealthcheckTcp, error) - FirstOrCreate() (*models.HealthcheckTcp, error) - FindByPage(offset int, limit int) (result []*models.HealthcheckTcp, count int64, err error) - ScanByPage(result interface{}, offset int, limit int) (count int64, err error) - Scan(result interface{}) (err error) - Returning(value interface{}, columns ...string) IHealthcheckTcpDo - UnderlyingDB() *gorm.DB - schema.Tabler -} - -func (h healthcheckTcpDo) Debug() IHealthcheckTcpDo { - return h.withDO(h.DO.Debug()) -} - -func (h healthcheckTcpDo) WithContext(ctx context.Context) IHealthcheckTcpDo { - return h.withDO(h.DO.WithContext(ctx)) -} - -func (h healthcheckTcpDo) ReadDB() IHealthcheckTcpDo { - return h.Clauses(dbresolver.Read) -} - -func (h healthcheckTcpDo) WriteDB() IHealthcheckTcpDo { - return h.Clauses(dbresolver.Write) -} - -func (h healthcheckTcpDo) Session(config *gorm.Session) IHealthcheckTcpDo { - return h.withDO(h.DO.Session(config)) -} - -func (h healthcheckTcpDo) Clauses(conds ...clause.Expression) IHealthcheckTcpDo { - return h.withDO(h.DO.Clauses(conds...)) -} - -func (h healthcheckTcpDo) Returning(value interface{}, columns ...string) IHealthcheckTcpDo { - return h.withDO(h.DO.Returning(value, columns...)) -} - -func (h healthcheckTcpDo) Not(conds ...gen.Condition) IHealthcheckTcpDo { - return h.withDO(h.DO.Not(conds...)) -} - -func (h healthcheckTcpDo) Or(conds ...gen.Condition) IHealthcheckTcpDo { - return h.withDO(h.DO.Or(conds...)) -} - -func (h healthcheckTcpDo) Select(conds ...field.Expr) IHealthcheckTcpDo { - return h.withDO(h.DO.Select(conds...)) -} - -func (h healthcheckTcpDo) Where(conds ...gen.Condition) IHealthcheckTcpDo { - return h.withDO(h.DO.Where(conds...)) -} - -func (h healthcheckTcpDo) Order(conds ...field.Expr) IHealthcheckTcpDo { - return h.withDO(h.DO.Order(conds...)) -} - -func (h healthcheckTcpDo) Distinct(cols ...field.Expr) IHealthcheckTcpDo { - return h.withDO(h.DO.Distinct(cols...)) -} - -func (h healthcheckTcpDo) Omit(cols ...field.Expr) IHealthcheckTcpDo { - return h.withDO(h.DO.Omit(cols...)) -} - -func (h healthcheckTcpDo) Join(table schema.Tabler, on ...field.Expr) IHealthcheckTcpDo { - return h.withDO(h.DO.Join(table, on...)) -} - -func (h healthcheckTcpDo) LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckTcpDo { - return h.withDO(h.DO.LeftJoin(table, on...)) -} - -func (h healthcheckTcpDo) RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckTcpDo { - return h.withDO(h.DO.RightJoin(table, on...)) -} - -func (h healthcheckTcpDo) Group(cols ...field.Expr) IHealthcheckTcpDo { - return h.withDO(h.DO.Group(cols...)) -} - -func (h healthcheckTcpDo) Having(conds ...gen.Condition) IHealthcheckTcpDo { - return h.withDO(h.DO.Having(conds...)) -} - -func (h healthcheckTcpDo) Limit(limit int) IHealthcheckTcpDo { - return h.withDO(h.DO.Limit(limit)) -} - -func (h healthcheckTcpDo) Offset(offset int) IHealthcheckTcpDo { - return h.withDO(h.DO.Offset(offset)) -} - -func (h healthcheckTcpDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckTcpDo { - return h.withDO(h.DO.Scopes(funcs...)) -} - -func (h healthcheckTcpDo) Unscoped() IHealthcheckTcpDo { - return h.withDO(h.DO.Unscoped()) -} - -func (h healthcheckTcpDo) Create(values ...*models.HealthcheckTcp) error { - if len(values) == 0 { - return nil - } - return h.DO.Create(values) -} - -func (h healthcheckTcpDo) CreateInBatches(values []*models.HealthcheckTcp, batchSize int) error { - return h.DO.CreateInBatches(values, batchSize) -} - -// Save : !!! underlying implementation is different with GORM -// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values) -func (h healthcheckTcpDo) Save(values ...*models.HealthcheckTcp) error { - if len(values) == 0 { - return nil - } - return h.DO.Save(values) -} - -func (h healthcheckTcpDo) First() (*models.HealthcheckTcp, error) { - if result, err := h.DO.First(); err != nil { - return nil, err - } else { - return result.(*models.HealthcheckTcp), nil - } -} - -func (h healthcheckTcpDo) Take() (*models.HealthcheckTcp, error) { - if result, err := h.DO.Take(); err != nil { - return nil, err - } else { - return result.(*models.HealthcheckTcp), nil - } -} - -func (h healthcheckTcpDo) Last() (*models.HealthcheckTcp, error) { - if result, err := h.DO.Last(); err != nil { - return nil, err - } else { - return result.(*models.HealthcheckTcp), nil - } -} - -func (h healthcheckTcpDo) Find() ([]*models.HealthcheckTcp, error) { - result, err := h.DO.Find() - return result.([]*models.HealthcheckTcp), err -} - -func (h healthcheckTcpDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckTcp, err error) { - buf := make([]*models.HealthcheckTcp, 0, batchSize) - err = h.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error { - defer func() { results = append(results, buf...) }() - return fc(tx, batch) - }) - return results, err -} - -func (h healthcheckTcpDo) FindInBatches(result *[]*models.HealthcheckTcp, batchSize int, fc func(tx gen.Dao, batch int) error) error { - return h.DO.FindInBatches(result, batchSize, fc) -} - -func (h healthcheckTcpDo) Attrs(attrs ...field.AssignExpr) IHealthcheckTcpDo { - return h.withDO(h.DO.Attrs(attrs...)) -} - -func (h healthcheckTcpDo) Assign(attrs ...field.AssignExpr) IHealthcheckTcpDo { - return h.withDO(h.DO.Assign(attrs...)) -} - -func (h healthcheckTcpDo) Joins(fields ...field.RelationField) IHealthcheckTcpDo { - for _, _f := range fields { - h = *h.withDO(h.DO.Joins(_f)) - } - return &h -} - -func (h healthcheckTcpDo) Preload(fields ...field.RelationField) IHealthcheckTcpDo { - for _, _f := range fields { - h = *h.withDO(h.DO.Preload(_f)) - } - return &h -} - -func (h healthcheckTcpDo) FirstOrInit() (*models.HealthcheckTcp, error) { - if result, err := h.DO.FirstOrInit(); err != nil { - return nil, err - } else { - return result.(*models.HealthcheckTcp), nil - } -} - -func (h healthcheckTcpDo) FirstOrCreate() (*models.HealthcheckTcp, error) { - if result, err := h.DO.FirstOrCreate(); err != nil { - return nil, err - } else { - return result.(*models.HealthcheckTcp), nil - } -} - -func (h healthcheckTcpDo) FindByPage(offset int, limit int) (result []*models.HealthcheckTcp, count int64, err error) { - result, err = h.Offset(offset).Limit(limit).Find() - if err != nil { - return - } - - if size := len(result); 0 < limit && 0 < size && size < limit { - count = int64(size + offset) - return - } - - count, err = h.Offset(-1).Limit(-1).Count() - return -} - -func (h healthcheckTcpDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { - count, err = h.Count() - if err != nil { - return - } - - err = h.Offset(offset).Limit(limit).Scan(result) - return -} - -func (h healthcheckTcpDo) Scan(result interface{}) (err error) { - return h.DO.Scan(result) -} - -func (h healthcheckTcpDo) Delete(models ...*models.HealthcheckTcp) (result gen.ResultInfo, err error) { - return h.DO.Delete(models) -} - -func (h *healthcheckTcpDo) withDO(do gen.Dao) *healthcheckTcpDo { - h.DO = *do.(*gen.DO) - return h -} diff --git a/internal/models/query/healthchecks.gen.go b/internal/models/query/healthchecks.gen.go new file mode 100644 index 0000000..54002d0 --- /dev/null +++ b/internal/models/query/healthchecks.gen.go @@ -0,0 +1,520 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package query + +import ( + "context" + + "gorm.io/gorm" + "gorm.io/gorm/clause" + "gorm.io/gorm/schema" + + "gorm.io/gen" + "gorm.io/gen/field" + + "gorm.io/plugin/dbresolver" + + "code.tjo.space/mentos1386/zdravko/internal/models" +) + +func newHealthcheck(db *gorm.DB, opts ...gen.DOOption) healthcheck { + _healthcheck := healthcheck{} + + _healthcheck.healthcheckDo.UseDB(db, opts...) + _healthcheck.healthcheckDo.UseModel(&models.Healthcheck{}) + + tableName := _healthcheck.healthcheckDo.TableName() + _healthcheck.ALL = field.NewAsterisk(tableName) + _healthcheck.ID = field.NewUint(tableName, "id") + _healthcheck.CreatedAt = field.NewTime(tableName, "created_at") + _healthcheck.UpdatedAt = field.NewTime(tableName, "updated_at") + _healthcheck.DeletedAt = field.NewField(tableName, "deleted_at") + _healthcheck.Slug = field.NewString(tableName, "slug") + _healthcheck.Name = field.NewString(tableName, "name") + _healthcheck.Schedule = field.NewString(tableName, "schedule") + _healthcheck.WorkerGroups = field.NewField(tableName, "worker_groups") + _healthcheck.Script = field.NewString(tableName, "script") + _healthcheck.History = healthcheckHasManyHistory{ + db: db.Session(&gorm.Session{}), + + RelationField: field.NewRelation("History", "models.HealthcheckHistory"), + Healthcheck: struct { + field.RelationField + History struct { + field.RelationField + } + }{ + RelationField: field.NewRelation("History.Healthcheck", "models.Healthcheck"), + History: struct { + field.RelationField + }{ + RelationField: field.NewRelation("History.Healthcheck.History", "models.HealthcheckHistory"), + }, + }, + } + + _healthcheck.fillFieldMap() + + return _healthcheck +} + +type healthcheck struct { + healthcheckDo healthcheckDo + + ALL field.Asterisk + ID field.Uint + CreatedAt field.Time + UpdatedAt field.Time + DeletedAt field.Field + Slug field.String + Name field.String + Schedule field.String + WorkerGroups field.Field + Script field.String + History healthcheckHasManyHistory + + fieldMap map[string]field.Expr +} + +func (h healthcheck) Table(newTableName string) *healthcheck { + h.healthcheckDo.UseTable(newTableName) + return h.updateTableName(newTableName) +} + +func (h healthcheck) As(alias string) *healthcheck { + h.healthcheckDo.DO = *(h.healthcheckDo.As(alias).(*gen.DO)) + return h.updateTableName(alias) +} + +func (h *healthcheck) updateTableName(table string) *healthcheck { + h.ALL = field.NewAsterisk(table) + h.ID = field.NewUint(table, "id") + h.CreatedAt = field.NewTime(table, "created_at") + h.UpdatedAt = field.NewTime(table, "updated_at") + h.DeletedAt = field.NewField(table, "deleted_at") + h.Slug = field.NewString(table, "slug") + h.Name = field.NewString(table, "name") + h.Schedule = field.NewString(table, "schedule") + h.WorkerGroups = field.NewField(table, "worker_groups") + h.Script = field.NewString(table, "script") + + h.fillFieldMap() + + return h +} + +func (h *healthcheck) WithContext(ctx context.Context) IHealthcheckDo { + return h.healthcheckDo.WithContext(ctx) +} + +func (h healthcheck) TableName() string { return h.healthcheckDo.TableName() } + +func (h healthcheck) Alias() string { return h.healthcheckDo.Alias() } + +func (h healthcheck) Columns(cols ...field.Expr) gen.Columns { return h.healthcheckDo.Columns(cols...) } + +func (h *healthcheck) GetFieldByName(fieldName string) (field.OrderExpr, bool) { + _f, ok := h.fieldMap[fieldName] + if !ok || _f == nil { + return nil, false + } + _oe, ok := _f.(field.OrderExpr) + return _oe, ok +} + +func (h *healthcheck) fillFieldMap() { + h.fieldMap = make(map[string]field.Expr, 10) + h.fieldMap["id"] = h.ID + h.fieldMap["created_at"] = h.CreatedAt + h.fieldMap["updated_at"] = h.UpdatedAt + h.fieldMap["deleted_at"] = h.DeletedAt + h.fieldMap["slug"] = h.Slug + h.fieldMap["name"] = h.Name + h.fieldMap["schedule"] = h.Schedule + h.fieldMap["worker_groups"] = h.WorkerGroups + h.fieldMap["script"] = h.Script + +} + +func (h healthcheck) clone(db *gorm.DB) healthcheck { + h.healthcheckDo.ReplaceConnPool(db.Statement.ConnPool) + return h +} + +func (h healthcheck) replaceDB(db *gorm.DB) healthcheck { + h.healthcheckDo.ReplaceDB(db) + return h +} + +type healthcheckHasManyHistory struct { + db *gorm.DB + + field.RelationField + + Healthcheck struct { + field.RelationField + History struct { + field.RelationField + } + } +} + +func (a healthcheckHasManyHistory) Where(conds ...field.Expr) *healthcheckHasManyHistory { + if len(conds) == 0 { + return &a + } + + exprs := make([]clause.Expression, 0, len(conds)) + for _, cond := range conds { + exprs = append(exprs, cond.BeCond().(clause.Expression)) + } + a.db = a.db.Clauses(clause.Where{Exprs: exprs}) + return &a +} + +func (a healthcheckHasManyHistory) WithContext(ctx context.Context) *healthcheckHasManyHistory { + a.db = a.db.WithContext(ctx) + return &a +} + +func (a healthcheckHasManyHistory) Session(session *gorm.Session) *healthcheckHasManyHistory { + a.db = a.db.Session(session) + return &a +} + +func (a healthcheckHasManyHistory) Model(m *models.Healthcheck) *healthcheckHasManyHistoryTx { + return &healthcheckHasManyHistoryTx{a.db.Model(m).Association(a.Name())} +} + +type healthcheckHasManyHistoryTx struct{ tx *gorm.Association } + +func (a healthcheckHasManyHistoryTx) Find() (result []*models.HealthcheckHistory, err error) { + return result, a.tx.Find(&result) +} + +func (a healthcheckHasManyHistoryTx) Append(values ...*models.HealthcheckHistory) (err error) { + targetValues := make([]interface{}, len(values)) + for i, v := range values { + targetValues[i] = v + } + return a.tx.Append(targetValues...) +} + +func (a healthcheckHasManyHistoryTx) Replace(values ...*models.HealthcheckHistory) (err error) { + targetValues := make([]interface{}, len(values)) + for i, v := range values { + targetValues[i] = v + } + return a.tx.Replace(targetValues...) +} + +func (a healthcheckHasManyHistoryTx) Delete(values ...*models.HealthcheckHistory) (err error) { + targetValues := make([]interface{}, len(values)) + for i, v := range values { + targetValues[i] = v + } + return a.tx.Delete(targetValues...) +} + +func (a healthcheckHasManyHistoryTx) Clear() error { + return a.tx.Clear() +} + +func (a healthcheckHasManyHistoryTx) Count() int64 { + return a.tx.Count() +} + +type healthcheckDo struct{ gen.DO } + +type IHealthcheckDo interface { + gen.SubQuery + Debug() IHealthcheckDo + WithContext(ctx context.Context) IHealthcheckDo + WithResult(fc func(tx gen.Dao)) gen.ResultInfo + ReplaceDB(db *gorm.DB) + ReadDB() IHealthcheckDo + WriteDB() IHealthcheckDo + As(alias string) gen.Dao + Session(config *gorm.Session) IHealthcheckDo + Columns(cols ...field.Expr) gen.Columns + Clauses(conds ...clause.Expression) IHealthcheckDo + Not(conds ...gen.Condition) IHealthcheckDo + Or(conds ...gen.Condition) IHealthcheckDo + Select(conds ...field.Expr) IHealthcheckDo + Where(conds ...gen.Condition) IHealthcheckDo + Order(conds ...field.Expr) IHealthcheckDo + Distinct(cols ...field.Expr) IHealthcheckDo + Omit(cols ...field.Expr) IHealthcheckDo + Join(table schema.Tabler, on ...field.Expr) IHealthcheckDo + LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckDo + RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckDo + Group(cols ...field.Expr) IHealthcheckDo + Having(conds ...gen.Condition) IHealthcheckDo + Limit(limit int) IHealthcheckDo + Offset(offset int) IHealthcheckDo + Count() (count int64, err error) + Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckDo + Unscoped() IHealthcheckDo + Create(values ...*models.Healthcheck) error + CreateInBatches(values []*models.Healthcheck, batchSize int) error + Save(values ...*models.Healthcheck) error + First() (*models.Healthcheck, error) + Take() (*models.Healthcheck, error) + Last() (*models.Healthcheck, error) + Find() ([]*models.Healthcheck, error) + FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Healthcheck, err error) + FindInBatches(result *[]*models.Healthcheck, batchSize int, fc func(tx gen.Dao, batch int) error) error + Pluck(column field.Expr, dest interface{}) error + Delete(...*models.Healthcheck) (info gen.ResultInfo, err error) + Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error) + UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) + Updates(value interface{}) (info gen.ResultInfo, err error) + UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error) + UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) + UpdateColumns(value interface{}) (info gen.ResultInfo, err error) + UpdateFrom(q gen.SubQuery) gen.Dao + Attrs(attrs ...field.AssignExpr) IHealthcheckDo + Assign(attrs ...field.AssignExpr) IHealthcheckDo + Joins(fields ...field.RelationField) IHealthcheckDo + Preload(fields ...field.RelationField) IHealthcheckDo + FirstOrInit() (*models.Healthcheck, error) + FirstOrCreate() (*models.Healthcheck, error) + FindByPage(offset int, limit int) (result []*models.Healthcheck, count int64, err error) + ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Scan(result interface{}) (err error) + Returning(value interface{}, columns ...string) IHealthcheckDo + UnderlyingDB() *gorm.DB + schema.Tabler +} + +func (h healthcheckDo) Debug() IHealthcheckDo { + return h.withDO(h.DO.Debug()) +} + +func (h healthcheckDo) WithContext(ctx context.Context) IHealthcheckDo { + return h.withDO(h.DO.WithContext(ctx)) +} + +func (h healthcheckDo) ReadDB() IHealthcheckDo { + return h.Clauses(dbresolver.Read) +} + +func (h healthcheckDo) WriteDB() IHealthcheckDo { + return h.Clauses(dbresolver.Write) +} + +func (h healthcheckDo) Session(config *gorm.Session) IHealthcheckDo { + return h.withDO(h.DO.Session(config)) +} + +func (h healthcheckDo) Clauses(conds ...clause.Expression) IHealthcheckDo { + return h.withDO(h.DO.Clauses(conds...)) +} + +func (h healthcheckDo) Returning(value interface{}, columns ...string) IHealthcheckDo { + return h.withDO(h.DO.Returning(value, columns...)) +} + +func (h healthcheckDo) Not(conds ...gen.Condition) IHealthcheckDo { + return h.withDO(h.DO.Not(conds...)) +} + +func (h healthcheckDo) Or(conds ...gen.Condition) IHealthcheckDo { + return h.withDO(h.DO.Or(conds...)) +} + +func (h healthcheckDo) Select(conds ...field.Expr) IHealthcheckDo { + return h.withDO(h.DO.Select(conds...)) +} + +func (h healthcheckDo) Where(conds ...gen.Condition) IHealthcheckDo { + return h.withDO(h.DO.Where(conds...)) +} + +func (h healthcheckDo) Order(conds ...field.Expr) IHealthcheckDo { + return h.withDO(h.DO.Order(conds...)) +} + +func (h healthcheckDo) Distinct(cols ...field.Expr) IHealthcheckDo { + return h.withDO(h.DO.Distinct(cols...)) +} + +func (h healthcheckDo) Omit(cols ...field.Expr) IHealthcheckDo { + return h.withDO(h.DO.Omit(cols...)) +} + +func (h healthcheckDo) Join(table schema.Tabler, on ...field.Expr) IHealthcheckDo { + return h.withDO(h.DO.Join(table, on...)) +} + +func (h healthcheckDo) LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckDo { + return h.withDO(h.DO.LeftJoin(table, on...)) +} + +func (h healthcheckDo) RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckDo { + return h.withDO(h.DO.RightJoin(table, on...)) +} + +func (h healthcheckDo) Group(cols ...field.Expr) IHealthcheckDo { + return h.withDO(h.DO.Group(cols...)) +} + +func (h healthcheckDo) Having(conds ...gen.Condition) IHealthcheckDo { + return h.withDO(h.DO.Having(conds...)) +} + +func (h healthcheckDo) Limit(limit int) IHealthcheckDo { + return h.withDO(h.DO.Limit(limit)) +} + +func (h healthcheckDo) Offset(offset int) IHealthcheckDo { + return h.withDO(h.DO.Offset(offset)) +} + +func (h healthcheckDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckDo { + return h.withDO(h.DO.Scopes(funcs...)) +} + +func (h healthcheckDo) Unscoped() IHealthcheckDo { + return h.withDO(h.DO.Unscoped()) +} + +func (h healthcheckDo) Create(values ...*models.Healthcheck) error { + if len(values) == 0 { + return nil + } + return h.DO.Create(values) +} + +func (h healthcheckDo) CreateInBatches(values []*models.Healthcheck, batchSize int) error { + return h.DO.CreateInBatches(values, batchSize) +} + +// Save : !!! underlying implementation is different with GORM +// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values) +func (h healthcheckDo) Save(values ...*models.Healthcheck) error { + if len(values) == 0 { + return nil + } + return h.DO.Save(values) +} + +func (h healthcheckDo) First() (*models.Healthcheck, error) { + if result, err := h.DO.First(); err != nil { + return nil, err + } else { + return result.(*models.Healthcheck), nil + } +} + +func (h healthcheckDo) Take() (*models.Healthcheck, error) { + if result, err := h.DO.Take(); err != nil { + return nil, err + } else { + return result.(*models.Healthcheck), nil + } +} + +func (h healthcheckDo) Last() (*models.Healthcheck, error) { + if result, err := h.DO.Last(); err != nil { + return nil, err + } else { + return result.(*models.Healthcheck), nil + } +} + +func (h healthcheckDo) Find() ([]*models.Healthcheck, error) { + result, err := h.DO.Find() + return result.([]*models.Healthcheck), err +} + +func (h healthcheckDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Healthcheck, err error) { + buf := make([]*models.Healthcheck, 0, batchSize) + err = h.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error { + defer func() { results = append(results, buf...) }() + return fc(tx, batch) + }) + return results, err +} + +func (h healthcheckDo) FindInBatches(result *[]*models.Healthcheck, batchSize int, fc func(tx gen.Dao, batch int) error) error { + return h.DO.FindInBatches(result, batchSize, fc) +} + +func (h healthcheckDo) Attrs(attrs ...field.AssignExpr) IHealthcheckDo { + return h.withDO(h.DO.Attrs(attrs...)) +} + +func (h healthcheckDo) Assign(attrs ...field.AssignExpr) IHealthcheckDo { + return h.withDO(h.DO.Assign(attrs...)) +} + +func (h healthcheckDo) Joins(fields ...field.RelationField) IHealthcheckDo { + for _, _f := range fields { + h = *h.withDO(h.DO.Joins(_f)) + } + return &h +} + +func (h healthcheckDo) Preload(fields ...field.RelationField) IHealthcheckDo { + for _, _f := range fields { + h = *h.withDO(h.DO.Preload(_f)) + } + return &h +} + +func (h healthcheckDo) FirstOrInit() (*models.Healthcheck, error) { + if result, err := h.DO.FirstOrInit(); err != nil { + return nil, err + } else { + return result.(*models.Healthcheck), nil + } +} + +func (h healthcheckDo) FirstOrCreate() (*models.Healthcheck, error) { + if result, err := h.DO.FirstOrCreate(); err != nil { + return nil, err + } else { + return result.(*models.Healthcheck), nil + } +} + +func (h healthcheckDo) FindByPage(offset int, limit int) (result []*models.Healthcheck, count int64, err error) { + result, err = h.Offset(offset).Limit(limit).Find() + if err != nil { + return + } + + if size := len(result); 0 < limit && 0 < size && size < limit { + count = int64(size + offset) + return + } + + count, err = h.Offset(-1).Limit(-1).Count() + return +} + +func (h healthcheckDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { + count, err = h.Count() + if err != nil { + return + } + + err = h.Offset(offset).Limit(limit).Scan(result) + return +} + +func (h healthcheckDo) Scan(result interface{}) (err error) { + return h.DO.Scan(result) +} + +func (h healthcheckDo) Delete(models ...*models.Healthcheck) (result gen.ResultInfo, err error) { + return h.DO.Delete(models) +} + +func (h *healthcheckDo) withDO(do gen.Dao) *healthcheckDo { + h.DO = *do.(*gen.DO) + return h +} diff --git a/internal/services/healthcheck.go b/internal/services/healthcheck.go index 62973c0..9187bbb 100644 --- a/internal/services/healthcheck.go +++ b/internal/services/healthcheck.go @@ -12,34 +12,34 @@ import ( "gorm.io/gorm" ) -func CreateHealthcheckHttp(ctx context.Context, db *gorm.DB, healthcheck *models.HealthcheckHttp) error { +func CreateHealthcheck(ctx context.Context, db *gorm.DB, healthcheck *models.Healthcheck) error { return db.WithContext(ctx).Create(healthcheck).Error } -func GetHealthcheckHttp(ctx context.Context, q *query.Query, slug string) (*models.HealthcheckHttp, error) { - log.Println("GetHealthcheckHttp") - return q.HealthcheckHttp.WithContext(ctx).Where( - q.HealthcheckHttp.Slug.Eq(slug), +func GetHealthcheck(ctx context.Context, q *query.Query, slug string) (*models.Healthcheck, error) { + log.Println("GetHealthcheck") + return q.Healthcheck.WithContext(ctx).Where( + q.Healthcheck.Slug.Eq(slug), ).First() } -func StartHealthcheckHttp(ctx context.Context, t client.Client, healthcheckHttp *models.HealthcheckHttp) error { - log.Println("Starting HealthcheckHttp Workflow") +func StartHealthcheck(ctx context.Context, t client.Client, healthcheck *models.Healthcheck) error { + log.Println("Starting Healthcheck Workflow") args := make([]interface{}, 0) - args = append(args, workflows.HealthcheckHttpWorkflowParam{Url: healthcheckHttp.Url, Method: healthcheckHttp.Method}) + args = append(args, workflows.HealthcheckWorkflowParam{Script: healthcheck.Script}) - id := "healthcheck-http-" + healthcheckHttp.Slug + id := "healthcheck-" + healthcheck.Slug - for _, group := range healthcheckHttp.WorkerGroups { + for _, group := range healthcheck.WorkerGroups { _, err := t.ScheduleClient().Create(ctx, client.ScheduleOptions{ ID: id + "-" + group, Spec: client.ScheduleSpec{ - CronExpressions: []string{healthcheckHttp.Schedule}, + CronExpressions: []string{healthcheck.Schedule}, }, Action: &client.ScheduleWorkflowAction{ ID: id + "-" + group, - Workflow: workflows.HealthcheckHttpWorkflowDefinition, + Workflow: workflows.HealthcheckWorkflowDefinition, Args: args, TaskQueue: group, RetryPolicy: &temporal.RetryPolicy{ @@ -55,6 +55,6 @@ func StartHealthcheckHttp(ctx context.Context, t client.Client, healthcheckHttp return nil } -func CreateHealthcheckHistory(ctx context.Context, db *gorm.DB, healthcheckHistory *models.HealthcheckHttpHistory) error { +func CreateHealthcheckHistory(ctx context.Context, db *gorm.DB, healthcheckHistory *models.HealthcheckHistory) error { return db.WithContext(ctx).Create(healthcheckHistory).Error } diff --git a/internal/workflows/healthcheck.go b/internal/workflows/healthcheck.go index 4aac2c7..5c42a53 100644 --- a/internal/workflows/healthcheck.go +++ b/internal/workflows/healthcheck.go @@ -1,38 +1,31 @@ package workflows import ( - "fmt" "time" "code.tjo.space/mentos1386/zdravko/internal/activities" "go.temporal.io/sdk/workflow" ) -type HealthcheckHttpWorkflowParam struct { - Url string - Method string +type HealthcheckWorkflowParam struct { + Script string } -func HealthcheckHttpWorkflowDefinition(ctx workflow.Context, param HealthcheckHttpWorkflowParam) error { +func HealthcheckWorkflowDefinition(ctx workflow.Context, param HealthcheckWorkflowParam) error { options := workflow.ActivityOptions{ StartToCloseTimeout: 10 * time.Second, } ctx = workflow.WithActivityOptions(ctx, options) - activityParam := activities.HealtcheckHttpParam{ - Url: param.Url, - Method: param.Method, + activityParam := activities.HealtcheckParam{ + Script: param.Script, } - var result *activities.HealthcheckHttpResult - err := workflow.ExecuteActivity(ctx, activities.HealthcheckHttp, activityParam).Get(ctx, &result) + var result *activities.HealthcheckResult + err := workflow.ExecuteActivity(ctx, activities.Healthcheck, activityParam).Get(ctx, &result) if err != nil { return err } - if result.StatusCode != 200 { - return fmt.Errorf("HealthcheckHttpActivityDefinition produced statuscode %d for url %s", result.StatusCode, param.Url) - } - return nil } diff --git a/pkg/k6/k6.go b/pkg/k6/k6.go index e065135..e6b1c10 100644 --- a/pkg/k6/k6.go +++ b/pkg/k6/k6.go @@ -150,7 +150,9 @@ func (lt *loadedTest) consolidateDeriveAndValidateConfig( gs *state.GlobalState, ) (*loadedAndConfiguredTest, error) { gs.Logger.Debug("Consolidating config layers...") + config := lib.Options{} + config.Apply(lt.initRunner.GetOptions()) if config.SystemTags == nil { config.SystemTags = &metrics.DefaultSystemTagSet @@ -252,7 +254,7 @@ func (lct *loadedAndConfiguredTest) buildTestRunState( return &lib.TestRunState{ TestPreInitState: lct.preInitState, Runner: lct.initRunner, - Options: lct.config, // we will always run with the derived options + Options: lct.config, RunTags: lct.preInitState.Registry.RootTagSet().WithTagsFromMap(configToReinject.RunTags), }, nil } diff --git a/pkg/k6/k6_test.go b/pkg/k6/k6_test.go index dffac29..078fc06 100644 --- a/pkg/k6/k6_test.go +++ b/pkg/k6/k6_test.go @@ -22,7 +22,7 @@ export const options = { }; export default function () { - http.get('http://test.k6.io'); + http.get('https://test.k6.io'); sleep(1); } ` diff --git a/pkg/worker/worker.go b/pkg/worker/worker.go index fc9e310..7fa6a08 100644 --- a/pkg/worker/worker.go +++ b/pkg/worker/worker.go @@ -82,10 +82,10 @@ func (w *Worker) Start() error { w.worker = worker.New(temporalClient, config.Group, worker.Options{}) // Register Workflows - w.worker.RegisterWorkflow(workflows.HealthcheckHttpWorkflowDefinition) + w.worker.RegisterWorkflow(workflows.HealthcheckWorkflowDefinition) // Register Activities - w.worker.RegisterActivity(activities.HealthcheckHttp) + w.worker.RegisterActivity(activities.Healthcheck) return w.worker.Run(worker.InterruptCh()) } diff --git a/process-compose.yml b/process-compose.yml index ab5efbf..ef1c4f9 100644 --- a/process-compose.yml +++ b/process-compose.yml @@ -1,11 +1,15 @@ version: "0.5" processes: + server: + command: watchexec -r -e go,tmpl,css just run-server + availability: + restart: "always" + temporal: + command: watchexec -r -e go,tmpl,css just run-temporal + availability: + restart: "always" tailwind: command: watchexec -r -e go,tmpl,css just _tailwindcss-build availability: restart: "always" - zdravko: - command: watchexec -r -e go,tmpl,css just run-server - availability: - restart: "always" diff --git a/tools/generate/main.go b/tools/generate/main.go index 1638058..1ad952c 100644 --- a/tools/generate/main.go +++ b/tools/generate/main.go @@ -30,10 +30,8 @@ func main() { // Generate default DAO interface for those specified structs g.ApplyBasic( models.Worker{}, - models.HealthcheckHttp{}, - models.HealthcheckHttpHistory{}, - models.HealthcheckTcp{}, - models.HealthcheckTcpHistory{}, + models.Healthcheck{}, + models.HealthcheckHistory{}, models.Cronjob{}, models.CronjobHistory{}, models.OAuth2State{}, diff --git a/web/static/css/tailwind.css b/web/static/css/tailwind.css index 9585f29..e2fc23a 100644 --- a/web/static/css/tailwind.css +++ b/web/static/css/tailwind.css @@ -1303,38 +1303,8 @@ video { } @media (prefers-color-scheme: dark) { - .dark\:border-gray-600 { - --tw-border-opacity: 1; - border-color: rgb(75 85 99 / var(--tw-border-opacity)); - } - - .dark\:bg-gray-700 { - --tw-bg-opacity: 1; - background-color: rgb(55 65 81 / var(--tw-bg-opacity)); - } - .dark\:text-white { --tw-text-opacity: 1; color: rgb(255 255 255 / var(--tw-text-opacity)); } - - .dark\:placeholder-gray-400::-moz-placeholder { - --tw-placeholder-opacity: 1; - color: rgb(156 163 175 / var(--tw-placeholder-opacity)); - } - - .dark\:placeholder-gray-400::placeholder { - --tw-placeholder-opacity: 1; - color: rgb(156 163 175 / var(--tw-placeholder-opacity)); - } - - .dark\:focus\:border-blue-500:focus { - --tw-border-opacity: 1; - border-color: rgb(59 130 246 / var(--tw-border-opacity)); - } - - .dark\:focus\:ring-blue-500:focus { - --tw-ring-opacity: 1; - --tw-ring-color: rgb(59 130 246 / var(--tw-ring-opacity)); - } } diff --git a/web/templates/pages/settings_healthchecks_create.tmpl b/web/templates/pages/settings_healthchecks_create.tmpl index d88d4bc..2631e2e 100644 --- a/web/templates/pages/settings_healthchecks_create.tmpl +++ b/web/templates/pages/settings_healthchecks_create.tmpl @@ -17,16 +17,19 @@
+ {{ .Healthcheck.Script }} +{{end}}