github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/models/event__generated.go (about) 1 // This is a generated source file. DO NOT EDIT 2 // Source: models/event__generated.go 3 4 package models 5 6 import ( 7 "fmt" 8 9 "github.com/machinefi/w3bstream/pkg/depends/kit/sqlx" 10 "github.com/machinefi/w3bstream/pkg/depends/kit/sqlx/builder" 11 ) 12 13 var EventTable *builder.Table 14 15 func init() { 16 EventTable = DB.Register(&Event{}) 17 } 18 19 type EventIterator struct { 20 } 21 22 func (*EventIterator) New() interface{} { 23 return &Event{} 24 } 25 26 func (*EventIterator) Resolve(v interface{}) *Event { 27 return v.(*Event) 28 } 29 30 func (*Event) TableName() string { 31 return "t_event" 32 } 33 34 func (*Event) TableDesc() []string { 35 return []string{ 36 "EventLog database model for event context", 37 } 38 } 39 40 func (*Event) Comments() map[string]string { 41 return map[string]string{ 42 "AccountID": "AccountID account ID", 43 "AutoCollect": "AutoCollect if do geo collection", 44 "CompletedAt": "CompletedAt event completed timestamp(epoch milliseconds)", 45 "Error": "Error wasm handle error message", 46 "EventID": "EventID event ID", 47 "EventType": "EventType event type", 48 "From": "From channel type: MQTT HTTP", 49 "HandledAt": "HandledAt event handled timestamp(epoch milliseconds)", 50 "Handler": "Handler wasm exported handling func", 51 "Index": "Index strategy index for different handler", 52 "Input": "Input event payload", 53 "InstanceID": "InstanceID instance ID", 54 "ProjectID": "ProjectID project ID", 55 "ProjectName": "ProjectName project name", 56 "PublishedAt": "PublishedAt event published timestamp(epoch milliseconds) from request", 57 "PublisherID": "PublisherID publisher ID", 58 "PublisherKey": "PublisherKey publisher key", 59 "ReceivedAt": "ReceivedAt event received timestamp(epoch milliseconds)", 60 "ResultCode": "ResultCode wasm handle result code", 61 "Stage": "Stage event handle stage: RECEIVED, HANDLED and COMPLETED", 62 "Total": "Total strategy total", 63 } 64 } 65 66 func (*Event) ColDesc() map[string][]string { 67 return map[string][]string{ 68 "AccountID": []string{ 69 "AccountID account ID", 70 }, 71 "AutoCollect": []string{ 72 "AutoCollect if do geo collection", 73 }, 74 "CompletedAt": []string{ 75 "CompletedAt event completed timestamp(epoch milliseconds)", 76 }, 77 "Error": []string{ 78 "Error wasm handle error message", 79 }, 80 "EventID": []string{ 81 "EventID event ID", 82 }, 83 "EventType": []string{ 84 "EventType event type", 85 }, 86 "From": []string{ 87 "From channel type: MQTT HTTP", 88 }, 89 "HandledAt": []string{ 90 "HandledAt event handled timestamp(epoch milliseconds)", 91 }, 92 "Handler": []string{ 93 "Handler wasm exported handling func", 94 }, 95 "Index": []string{ 96 "Index strategy index for different handler", 97 }, 98 "Input": []string{ 99 "Input event payload", 100 }, 101 "InstanceID": []string{ 102 "InstanceID instance ID", 103 }, 104 "ProjectID": []string{ 105 "ProjectID project ID", 106 }, 107 "ProjectName": []string{ 108 "ProjectName project name", 109 }, 110 "PublishedAt": []string{ 111 "PublishedAt event published timestamp(epoch milliseconds) from request", 112 }, 113 "PublisherID": []string{ 114 "PublisherID publisher ID", 115 }, 116 "PublisherKey": []string{ 117 "PublisherKey publisher key", 118 }, 119 "ReceivedAt": []string{ 120 "ReceivedAt event received timestamp(epoch milliseconds)", 121 }, 122 "ResultCode": []string{ 123 "ResultCode wasm handle result code", 124 }, 125 "Stage": []string{ 126 "Stage event handle stage: RECEIVED, HANDLED and COMPLETED", 127 }, 128 "Total": []string{ 129 "Total strategy total", 130 }, 131 } 132 } 133 134 func (*Event) ColRel() map[string][]string { 135 return map[string][]string{} 136 } 137 138 func (*Event) PrimaryKey() []string { 139 return []string{ 140 "ID", 141 } 142 } 143 144 func (*Event) Indexes() builder.Indexes { 145 return builder.Indexes{ 146 "i_completed_at": []string{ 147 "CompletedAt", 148 }, 149 "i_event_id": []string{ 150 "EventID", 151 }, 152 "i_event_type": []string{ 153 "EventType", 154 }, 155 "i_handled_at": []string{ 156 "HandledAt", 157 }, 158 "i_handler": []string{ 159 "Handler", 160 }, 161 "i_instance_id": []string{ 162 "InstanceID", 163 }, 164 "i_project_id": []string{ 165 "ProjectID", 166 }, 167 "i_published_at": []string{ 168 "PublishedAt", 169 }, 170 "i_publisher_id": []string{ 171 "PublisherID", 172 }, 173 "i_received_at": []string{ 174 "ReceivedAt", 175 }, 176 "i_result_code": []string{ 177 "ResultCode", 178 }, 179 "i_stage": []string{ 180 "Stage", 181 }, 182 } 183 } 184 185 func (m *Event) IndexFieldNames() []string { 186 return []string{ 187 "CompletedAt", 188 "EventID", 189 "EventType", 190 "HandledAt", 191 "Handler", 192 "ID", 193 "InstanceID", 194 "ProjectID", 195 "PublishedAt", 196 "PublisherID", 197 "ReceivedAt", 198 "ResultCode", 199 "Stage", 200 } 201 } 202 203 func (m *Event) ColID() *builder.Column { 204 return EventTable.ColByFieldName(m.FieldID()) 205 } 206 207 func (*Event) FieldID() string { 208 return "ID" 209 } 210 211 func (m *Event) ColStage() *builder.Column { 212 return EventTable.ColByFieldName(m.FieldStage()) 213 } 214 215 func (*Event) FieldStage() string { 216 return "Stage" 217 } 218 219 func (m *Event) ColFrom() *builder.Column { 220 return EventTable.ColByFieldName(m.FieldFrom()) 221 } 222 223 func (*Event) FieldFrom() string { 224 return "From" 225 } 226 227 func (m *Event) ColAccountID() *builder.Column { 228 return EventTable.ColByFieldName(m.FieldAccountID()) 229 } 230 231 func (*Event) FieldAccountID() string { 232 return "AccountID" 233 } 234 235 func (m *Event) ColProjectID() *builder.Column { 236 return EventTable.ColByFieldName(m.FieldProjectID()) 237 } 238 239 func (*Event) FieldProjectID() string { 240 return "ProjectID" 241 } 242 243 func (m *Event) ColProjectName() *builder.Column { 244 return EventTable.ColByFieldName(m.FieldProjectName()) 245 } 246 247 func (*Event) FieldProjectName() string { 248 return "ProjectName" 249 } 250 251 func (m *Event) ColPublisherID() *builder.Column { 252 return EventTable.ColByFieldName(m.FieldPublisherID()) 253 } 254 255 func (*Event) FieldPublisherID() string { 256 return "PublisherID" 257 } 258 259 func (m *Event) ColPublisherKey() *builder.Column { 260 return EventTable.ColByFieldName(m.FieldPublisherKey()) 261 } 262 263 func (*Event) FieldPublisherKey() string { 264 return "PublisherKey" 265 } 266 267 func (m *Event) ColEventID() *builder.Column { 268 return EventTable.ColByFieldName(m.FieldEventID()) 269 } 270 271 func (*Event) FieldEventID() string { 272 return "EventID" 273 } 274 275 func (m *Event) ColIndex() *builder.Column { 276 return EventTable.ColByFieldName(m.FieldIndex()) 277 } 278 279 func (*Event) FieldIndex() string { 280 return "Index" 281 } 282 283 func (m *Event) ColTotal() *builder.Column { 284 return EventTable.ColByFieldName(m.FieldTotal()) 285 } 286 287 func (*Event) FieldTotal() string { 288 return "Total" 289 } 290 291 func (m *Event) ColEventType() *builder.Column { 292 return EventTable.ColByFieldName(m.FieldEventType()) 293 } 294 295 func (*Event) FieldEventType() string { 296 return "EventType" 297 } 298 299 func (m *Event) ColInstanceID() *builder.Column { 300 return EventTable.ColByFieldName(m.FieldInstanceID()) 301 } 302 303 func (*Event) FieldInstanceID() string { 304 return "InstanceID" 305 } 306 307 func (m *Event) ColHandler() *builder.Column { 308 return EventTable.ColByFieldName(m.FieldHandler()) 309 } 310 311 func (*Event) FieldHandler() string { 312 return "Handler" 313 } 314 315 func (m *Event) ColInput() *builder.Column { 316 return EventTable.ColByFieldName(m.FieldInput()) 317 } 318 319 func (*Event) FieldInput() string { 320 return "Input" 321 } 322 323 func (m *Event) ColResultCode() *builder.Column { 324 return EventTable.ColByFieldName(m.FieldResultCode()) 325 } 326 327 func (*Event) FieldResultCode() string { 328 return "ResultCode" 329 } 330 331 func (m *Event) ColError() *builder.Column { 332 return EventTable.ColByFieldName(m.FieldError()) 333 } 334 335 func (*Event) FieldError() string { 336 return "Error" 337 } 338 339 func (m *Event) ColPublishedAt() *builder.Column { 340 return EventTable.ColByFieldName(m.FieldPublishedAt()) 341 } 342 343 func (*Event) FieldPublishedAt() string { 344 return "PublishedAt" 345 } 346 347 func (m *Event) ColReceivedAt() *builder.Column { 348 return EventTable.ColByFieldName(m.FieldReceivedAt()) 349 } 350 351 func (*Event) FieldReceivedAt() string { 352 return "ReceivedAt" 353 } 354 355 func (m *Event) ColHandledAt() *builder.Column { 356 return EventTable.ColByFieldName(m.FieldHandledAt()) 357 } 358 359 func (*Event) FieldHandledAt() string { 360 return "HandledAt" 361 } 362 363 func (m *Event) ColCompletedAt() *builder.Column { 364 return EventTable.ColByFieldName(m.FieldCompletedAt()) 365 } 366 367 func (*Event) FieldCompletedAt() string { 368 return "CompletedAt" 369 } 370 371 func (m *Event) ColAutoCollect() *builder.Column { 372 return EventTable.ColByFieldName(m.FieldAutoCollect()) 373 } 374 375 func (*Event) FieldAutoCollect() string { 376 return "AutoCollect" 377 } 378 379 func (m *Event) CondByValue(db sqlx.DBExecutor) builder.SqlCondition { 380 var ( 381 tbl = db.T(m) 382 fvs = builder.FieldValueFromStructByNoneZero(m) 383 cond = make([]builder.SqlCondition, 0) 384 ) 385 386 for _, fn := range m.IndexFieldNames() { 387 if v, ok := fvs[fn]; ok { 388 cond = append(cond, tbl.ColByFieldName(fn).Eq(v)) 389 delete(fvs, fn) 390 } 391 } 392 if len(cond) == 0 { 393 panic(fmt.Errorf("no field for indexes has value")) 394 } 395 for fn, v := range fvs { 396 cond = append(cond, tbl.ColByFieldName(fn).Eq(v)) 397 } 398 return builder.And(cond...) 399 } 400 401 func (m *Event) Create(db sqlx.DBExecutor) error { 402 403 _, err := db.Exec(sqlx.InsertToDB(db, m, nil)) 404 return err 405 } 406 407 func (m *Event) List(db sqlx.DBExecutor, cond builder.SqlCondition, adds ...builder.Addition) ([]Event, error) { 408 var ( 409 tbl = db.T(m) 410 lst = make([]Event, 0) 411 ) 412 adds = append([]builder.Addition{builder.Where(cond), builder.Comment("Event.List")}, adds...) 413 err := db.QueryAndScan(builder.Select(nil).From(tbl, adds...), &lst) 414 return lst, err 415 } 416 417 func (m *Event) Count(db sqlx.DBExecutor, cond builder.SqlCondition, adds ...builder.Addition) (cnt int64, err error) { 418 tbl := db.T(m) 419 adds = append([]builder.Addition{builder.Where(cond), builder.Comment("Event.List")}, adds...) 420 err = db.QueryAndScan(builder.Select(builder.Count()).From(tbl, adds...), &cnt) 421 return 422 } 423 424 func (m *Event) FetchByID(db sqlx.DBExecutor) error { 425 tbl := db.T(m) 426 err := db.QueryAndScan( 427 builder.Select(nil). 428 From( 429 tbl, 430 builder.Where( 431 builder.And( 432 tbl.ColByFieldName("ID").Eq(m.ID), 433 ), 434 ), 435 builder.Comment("Event.FetchByID"), 436 ), 437 m, 438 ) 439 return err 440 } 441 442 func (m *Event) UpdateByIDWithFVs(db sqlx.DBExecutor, fvs builder.FieldValues) error { 443 tbl := db.T(m) 444 res, err := db.Exec( 445 builder.Update(tbl). 446 Where( 447 builder.And( 448 tbl.ColByFieldName("ID").Eq(m.ID), 449 ), 450 builder.Comment("Event.UpdateByIDWithFVs"), 451 ). 452 Set(tbl.AssignmentsByFieldValues(fvs)...), 453 ) 454 if err != nil { 455 return err 456 } 457 if affected, _ := res.RowsAffected(); affected == 0 { 458 return m.FetchByID(db) 459 } 460 return nil 461 } 462 463 func (m *Event) UpdateByID(db sqlx.DBExecutor, zeros ...string) error { 464 fvs := builder.FieldValueFromStructByNoneZero(m, zeros...) 465 return m.UpdateByIDWithFVs(db, fvs) 466 } 467 468 func (m *Event) Delete(db sqlx.DBExecutor) error { 469 _, err := db.Exec( 470 builder.Delete(). 471 From( 472 db.T(m), 473 builder.Where(m.CondByValue(db)), 474 builder.Comment("Event.Delete"), 475 ), 476 ) 477 return err 478 } 479 480 func (m *Event) DeleteByID(db sqlx.DBExecutor) error { 481 tbl := db.T(m) 482 _, err := db.Exec( 483 builder.Delete(). 484 From( 485 tbl, 486 builder.Where( 487 builder.And( 488 tbl.ColByFieldName("ID").Eq(m.ID), 489 ), 490 ), 491 builder.Comment("Event.DeleteByID"), 492 ), 493 ) 494 return err 495 }