github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/models/cron_job__generated.go (about) 1 // This is a generated source file. DO NOT EDIT 2 // Source: models/cron_job__generated.go 3 4 package models 5 6 import ( 7 "fmt" 8 "time" 9 10 "github.com/machinefi/w3bstream/pkg/depends/base/types" 11 "github.com/machinefi/w3bstream/pkg/depends/kit/sqlx" 12 "github.com/machinefi/w3bstream/pkg/depends/kit/sqlx/builder" 13 ) 14 15 var CronJobTable *builder.Table 16 17 func init() { 18 CronJobTable = DB.Register(&CronJob{}) 19 } 20 21 type CronJobIterator struct { 22 } 23 24 func (*CronJobIterator) New() interface{} { 25 return &CronJob{} 26 } 27 28 func (*CronJobIterator) Resolve(v interface{}) *CronJob { 29 return v.(*CronJob) 30 } 31 32 func (*CronJob) TableName() string { 33 return "t_cron_job" 34 } 35 36 func (*CronJob) TableDesc() []string { 37 return []string{ 38 "CronJob schema for cron job information", 39 } 40 } 41 42 func (*CronJob) Comments() map[string]string { 43 return map[string]string{} 44 } 45 46 func (*CronJob) ColDesc() map[string][]string { 47 return map[string][]string{} 48 } 49 50 func (*CronJob) ColRel() map[string][]string { 51 return map[string][]string{} 52 } 53 54 func (*CronJob) PrimaryKey() []string { 55 return []string{ 56 "ID", 57 } 58 } 59 60 func (m *CronJob) IndexFieldNames() []string { 61 return []string{ 62 "CronExpressions", 63 "CronJobID", 64 "EventType", 65 "ID", 66 "ProjectID", 67 } 68 } 69 70 func (*CronJob) UniqueIndexes() builder.Indexes { 71 return builder.Indexes{ 72 "ui_cron": []string{ 73 "ProjectID", 74 "CronExpressions", 75 "EventType", 76 "DeletedAt", 77 }, 78 "ui_cron_job_id": []string{ 79 "CronJobID", 80 "DeletedAt", 81 }, 82 } 83 } 84 85 func (*CronJob) UniqueIndexUICron() string { 86 return "ui_cron" 87 } 88 89 func (*CronJob) UniqueIndexUICronJobID() string { 90 return "ui_cron_job_id" 91 } 92 93 func (m *CronJob) ColID() *builder.Column { 94 return CronJobTable.ColByFieldName(m.FieldID()) 95 } 96 97 func (*CronJob) FieldID() string { 98 return "ID" 99 } 100 101 func (m *CronJob) ColCronJobID() *builder.Column { 102 return CronJobTable.ColByFieldName(m.FieldCronJobID()) 103 } 104 105 func (*CronJob) FieldCronJobID() string { 106 return "CronJobID" 107 } 108 109 func (m *CronJob) ColProjectID() *builder.Column { 110 return CronJobTable.ColByFieldName(m.FieldProjectID()) 111 } 112 113 func (*CronJob) FieldProjectID() string { 114 return "ProjectID" 115 } 116 117 func (m *CronJob) ColCronExpressions() *builder.Column { 118 return CronJobTable.ColByFieldName(m.FieldCronExpressions()) 119 } 120 121 func (*CronJob) FieldCronExpressions() string { 122 return "CronExpressions" 123 } 124 125 func (m *CronJob) ColEventType() *builder.Column { 126 return CronJobTable.ColByFieldName(m.FieldEventType()) 127 } 128 129 func (*CronJob) FieldEventType() string { 130 return "EventType" 131 } 132 133 func (m *CronJob) ColCreatedAt() *builder.Column { 134 return CronJobTable.ColByFieldName(m.FieldCreatedAt()) 135 } 136 137 func (*CronJob) FieldCreatedAt() string { 138 return "CreatedAt" 139 } 140 141 func (m *CronJob) ColUpdatedAt() *builder.Column { 142 return CronJobTable.ColByFieldName(m.FieldUpdatedAt()) 143 } 144 145 func (*CronJob) FieldUpdatedAt() string { 146 return "UpdatedAt" 147 } 148 149 func (m *CronJob) ColDeletedAt() *builder.Column { 150 return CronJobTable.ColByFieldName(m.FieldDeletedAt()) 151 } 152 153 func (*CronJob) FieldDeletedAt() string { 154 return "DeletedAt" 155 } 156 157 func (m *CronJob) CondByValue(db sqlx.DBExecutor) builder.SqlCondition { 158 var ( 159 tbl = db.T(m) 160 fvs = builder.FieldValueFromStructByNoneZero(m) 161 cond = []builder.SqlCondition{tbl.ColByFieldName("DeletedAt").Eq(0)} 162 ) 163 164 for _, fn := range m.IndexFieldNames() { 165 if v, ok := fvs[fn]; ok { 166 cond = append(cond, tbl.ColByFieldName(fn).Eq(v)) 167 delete(fvs, fn) 168 } 169 } 170 if len(cond) == 0 { 171 panic(fmt.Errorf("no field for indexes has value")) 172 } 173 for fn, v := range fvs { 174 cond = append(cond, tbl.ColByFieldName(fn).Eq(v)) 175 } 176 return builder.And(cond...) 177 } 178 179 func (m *CronJob) Create(db sqlx.DBExecutor) error { 180 181 if m.CreatedAt.IsZero() { 182 m.CreatedAt.Set(time.Now()) 183 } 184 185 if m.UpdatedAt.IsZero() { 186 m.UpdatedAt.Set(time.Now()) 187 } 188 189 _, err := db.Exec(sqlx.InsertToDB(db, m, nil)) 190 return err 191 } 192 193 func (m *CronJob) List(db sqlx.DBExecutor, cond builder.SqlCondition, adds ...builder.Addition) ([]CronJob, error) { 194 var ( 195 tbl = db.T(m) 196 lst = make([]CronJob, 0) 197 ) 198 cond = builder.And(tbl.ColByFieldName("DeletedAt").Eq(0), cond) 199 adds = append([]builder.Addition{builder.Where(cond), builder.Comment("CronJob.List")}, adds...) 200 err := db.QueryAndScan(builder.Select(nil).From(tbl, adds...), &lst) 201 return lst, err 202 } 203 204 func (m *CronJob) Count(db sqlx.DBExecutor, cond builder.SqlCondition, adds ...builder.Addition) (cnt int64, err error) { 205 tbl := db.T(m) 206 cond = builder.And(tbl.ColByFieldName("DeletedAt").Eq(0), cond) 207 adds = append([]builder.Addition{builder.Where(cond), builder.Comment("CronJob.List")}, adds...) 208 err = db.QueryAndScan(builder.Select(builder.Count()).From(tbl, adds...), &cnt) 209 return 210 } 211 212 func (m *CronJob) FetchByID(db sqlx.DBExecutor) error { 213 tbl := db.T(m) 214 err := db.QueryAndScan( 215 builder.Select(nil). 216 From( 217 tbl, 218 builder.Where( 219 builder.And( 220 tbl.ColByFieldName("ID").Eq(m.ID), 221 tbl.ColByFieldName("DeletedAt").Eq(m.DeletedAt), 222 ), 223 ), 224 builder.Comment("CronJob.FetchByID"), 225 ), 226 m, 227 ) 228 return err 229 } 230 231 func (m *CronJob) FetchByProjectIDAndCronExpressionsAndEventType(db sqlx.DBExecutor) error { 232 tbl := db.T(m) 233 err := db.QueryAndScan( 234 builder.Select(nil). 235 From( 236 tbl, 237 builder.Where( 238 builder.And( 239 tbl.ColByFieldName("ProjectID").Eq(m.ProjectID), 240 tbl.ColByFieldName("CronExpressions").Eq(m.CronExpressions), 241 tbl.ColByFieldName("EventType").Eq(m.EventType), 242 tbl.ColByFieldName("DeletedAt").Eq(m.DeletedAt), 243 ), 244 ), 245 builder.Comment("CronJob.FetchByProjectIDAndCronExpressionsAndEventType"), 246 ), 247 m, 248 ) 249 return err 250 } 251 252 func (m *CronJob) FetchByCronJobID(db sqlx.DBExecutor) error { 253 tbl := db.T(m) 254 err := db.QueryAndScan( 255 builder.Select(nil). 256 From( 257 tbl, 258 builder.Where( 259 builder.And( 260 tbl.ColByFieldName("CronJobID").Eq(m.CronJobID), 261 tbl.ColByFieldName("DeletedAt").Eq(m.DeletedAt), 262 ), 263 ), 264 builder.Comment("CronJob.FetchByCronJobID"), 265 ), 266 m, 267 ) 268 return err 269 } 270 271 func (m *CronJob) UpdateByIDWithFVs(db sqlx.DBExecutor, fvs builder.FieldValues) error { 272 273 if _, ok := fvs["UpdatedAt"]; !ok { 274 fvs["UpdatedAt"] = types.Timestamp{Time: time.Now()} 275 } 276 tbl := db.T(m) 277 res, err := db.Exec( 278 builder.Update(tbl). 279 Where( 280 builder.And( 281 tbl.ColByFieldName("ID").Eq(m.ID), 282 tbl.ColByFieldName("DeletedAt").Eq(m.DeletedAt), 283 ), 284 builder.Comment("CronJob.UpdateByIDWithFVs"), 285 ). 286 Set(tbl.AssignmentsByFieldValues(fvs)...), 287 ) 288 if err != nil { 289 return err 290 } 291 if affected, _ := res.RowsAffected(); affected == 0 { 292 return m.FetchByID(db) 293 } 294 return nil 295 } 296 297 func (m *CronJob) UpdateByID(db sqlx.DBExecutor, zeros ...string) error { 298 fvs := builder.FieldValueFromStructByNoneZero(m, zeros...) 299 return m.UpdateByIDWithFVs(db, fvs) 300 } 301 302 func (m *CronJob) UpdateByProjectIDAndCronExpressionsAndEventTypeWithFVs(db sqlx.DBExecutor, fvs builder.FieldValues) error { 303 304 if _, ok := fvs["UpdatedAt"]; !ok { 305 fvs["UpdatedAt"] = types.Timestamp{Time: time.Now()} 306 } 307 tbl := db.T(m) 308 res, err := db.Exec( 309 builder.Update(tbl). 310 Where( 311 builder.And( 312 tbl.ColByFieldName("ProjectID").Eq(m.ProjectID), 313 tbl.ColByFieldName("CronExpressions").Eq(m.CronExpressions), 314 tbl.ColByFieldName("EventType").Eq(m.EventType), 315 tbl.ColByFieldName("DeletedAt").Eq(m.DeletedAt), 316 ), 317 builder.Comment("CronJob.UpdateByProjectIDAndCronExpressionsAndEventTypeWithFVs"), 318 ). 319 Set(tbl.AssignmentsByFieldValues(fvs)...), 320 ) 321 if err != nil { 322 return err 323 } 324 if affected, _ := res.RowsAffected(); affected == 0 { 325 return m.FetchByProjectIDAndCronExpressionsAndEventType(db) 326 } 327 return nil 328 } 329 330 func (m *CronJob) UpdateByProjectIDAndCronExpressionsAndEventType(db sqlx.DBExecutor, zeros ...string) error { 331 fvs := builder.FieldValueFromStructByNoneZero(m, zeros...) 332 return m.UpdateByProjectIDAndCronExpressionsAndEventTypeWithFVs(db, fvs) 333 } 334 335 func (m *CronJob) UpdateByCronJobIDWithFVs(db sqlx.DBExecutor, fvs builder.FieldValues) error { 336 337 if _, ok := fvs["UpdatedAt"]; !ok { 338 fvs["UpdatedAt"] = types.Timestamp{Time: time.Now()} 339 } 340 tbl := db.T(m) 341 res, err := db.Exec( 342 builder.Update(tbl). 343 Where( 344 builder.And( 345 tbl.ColByFieldName("CronJobID").Eq(m.CronJobID), 346 tbl.ColByFieldName("DeletedAt").Eq(m.DeletedAt), 347 ), 348 builder.Comment("CronJob.UpdateByCronJobIDWithFVs"), 349 ). 350 Set(tbl.AssignmentsByFieldValues(fvs)...), 351 ) 352 if err != nil { 353 return err 354 } 355 if affected, _ := res.RowsAffected(); affected == 0 { 356 return m.FetchByCronJobID(db) 357 } 358 return nil 359 } 360 361 func (m *CronJob) UpdateByCronJobID(db sqlx.DBExecutor, zeros ...string) error { 362 fvs := builder.FieldValueFromStructByNoneZero(m, zeros...) 363 return m.UpdateByCronJobIDWithFVs(db, fvs) 364 } 365 366 func (m *CronJob) Delete(db sqlx.DBExecutor) error { 367 _, err := db.Exec( 368 builder.Delete(). 369 From( 370 db.T(m), 371 builder.Where(m.CondByValue(db)), 372 builder.Comment("CronJob.Delete"), 373 ), 374 ) 375 return err 376 } 377 378 func (m *CronJob) DeleteByID(db sqlx.DBExecutor) error { 379 tbl := db.T(m) 380 _, err := db.Exec( 381 builder.Delete(). 382 From( 383 tbl, 384 builder.Where( 385 builder.And( 386 tbl.ColByFieldName("ID").Eq(m.ID), 387 tbl.ColByFieldName("DeletedAt").Eq(m.DeletedAt), 388 ), 389 ), 390 builder.Comment("CronJob.DeleteByID"), 391 ), 392 ) 393 return err 394 } 395 396 func (m *CronJob) SoftDeleteByID(db sqlx.DBExecutor) error { 397 tbl := db.T(m) 398 fvs := builder.FieldValues{} 399 400 if _, ok := fvs["DeletedAt"]; !ok { 401 fvs["DeletedAt"] = types.Timestamp{Time: time.Now()} 402 } 403 404 if _, ok := fvs["UpdatedAt"]; !ok { 405 fvs["UpdatedAt"] = types.Timestamp{Time: time.Now()} 406 } 407 _, err := db.Exec( 408 builder.Update(db.T(m)). 409 Where( 410 builder.And( 411 tbl.ColByFieldName("ID").Eq(m.ID), 412 tbl.ColByFieldName("DeletedAt").Eq(m.DeletedAt), 413 ), 414 builder.Comment("CronJob.SoftDeleteByID"), 415 ). 416 Set(tbl.AssignmentsByFieldValues(fvs)...), 417 ) 418 return err 419 } 420 421 func (m *CronJob) DeleteByProjectIDAndCronExpressionsAndEventType(db sqlx.DBExecutor) error { 422 tbl := db.T(m) 423 _, err := db.Exec( 424 builder.Delete(). 425 From( 426 tbl, 427 builder.Where( 428 builder.And( 429 tbl.ColByFieldName("ProjectID").Eq(m.ProjectID), 430 tbl.ColByFieldName("CronExpressions").Eq(m.CronExpressions), 431 tbl.ColByFieldName("EventType").Eq(m.EventType), 432 tbl.ColByFieldName("DeletedAt").Eq(m.DeletedAt), 433 ), 434 ), 435 builder.Comment("CronJob.DeleteByProjectIDAndCronExpressionsAndEventType"), 436 ), 437 ) 438 return err 439 } 440 441 func (m *CronJob) SoftDeleteByProjectIDAndCronExpressionsAndEventType(db sqlx.DBExecutor) error { 442 tbl := db.T(m) 443 fvs := builder.FieldValues{} 444 445 if _, ok := fvs["DeletedAt"]; !ok { 446 fvs["DeletedAt"] = types.Timestamp{Time: time.Now()} 447 } 448 449 if _, ok := fvs["UpdatedAt"]; !ok { 450 fvs["UpdatedAt"] = types.Timestamp{Time: time.Now()} 451 } 452 _, err := db.Exec( 453 builder.Update(db.T(m)). 454 Where( 455 builder.And( 456 tbl.ColByFieldName("ProjectID").Eq(m.ProjectID), 457 tbl.ColByFieldName("CronExpressions").Eq(m.CronExpressions), 458 tbl.ColByFieldName("EventType").Eq(m.EventType), 459 tbl.ColByFieldName("DeletedAt").Eq(m.DeletedAt), 460 ), 461 builder.Comment("CronJob.SoftDeleteByProjectIDAndCronExpressionsAndEventType"), 462 ). 463 Set(tbl.AssignmentsByFieldValues(fvs)...), 464 ) 465 return err 466 } 467 468 func (m *CronJob) DeleteByCronJobID(db sqlx.DBExecutor) error { 469 tbl := db.T(m) 470 _, err := db.Exec( 471 builder.Delete(). 472 From( 473 tbl, 474 builder.Where( 475 builder.And( 476 tbl.ColByFieldName("CronJobID").Eq(m.CronJobID), 477 tbl.ColByFieldName("DeletedAt").Eq(m.DeletedAt), 478 ), 479 ), 480 builder.Comment("CronJob.DeleteByCronJobID"), 481 ), 482 ) 483 return err 484 } 485 486 func (m *CronJob) SoftDeleteByCronJobID(db sqlx.DBExecutor) error { 487 tbl := db.T(m) 488 fvs := builder.FieldValues{} 489 490 if _, ok := fvs["DeletedAt"]; !ok { 491 fvs["DeletedAt"] = types.Timestamp{Time: time.Now()} 492 } 493 494 if _, ok := fvs["UpdatedAt"]; !ok { 495 fvs["UpdatedAt"] = types.Timestamp{Time: time.Now()} 496 } 497 _, err := db.Exec( 498 builder.Update(db.T(m)). 499 Where( 500 builder.And( 501 tbl.ColByFieldName("CronJobID").Eq(m.CronJobID), 502 tbl.ColByFieldName("DeletedAt").Eq(m.DeletedAt), 503 ), 504 builder.Comment("CronJob.SoftDeleteByCronJobID"), 505 ). 506 Set(tbl.AssignmentsByFieldValues(fvs)...), 507 ) 508 return err 509 }