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