github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/models/chain_tx__generated.go (about) 1 // This is a generated source file. DO NOT EDIT 2 // Source: models/chain_tx__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 ChainTxTable *builder.Table 16 17 func init() { 18 ChainTxTable = MonitorDB.Register(&ChainTx{}) 19 } 20 21 type ChainTxIterator struct { 22 } 23 24 func (*ChainTxIterator) New() interface{} { 25 return &ChainTx{} 26 } 27 28 func (*ChainTxIterator) Resolve(v interface{}) *ChainTx { 29 return v.(*ChainTx) 30 } 31 32 func (*ChainTx) TableName() string { 33 return "t_chain_tx" 34 } 35 36 func (*ChainTx) TableDesc() []string { 37 return []string{ 38 "ChainTx database model chain tx", 39 } 40 } 41 42 func (*ChainTx) Comments() map[string]string { 43 return map[string]string{} 44 } 45 46 func (*ChainTx) ColDesc() map[string][]string { 47 return map[string][]string{} 48 } 49 50 func (*ChainTx) ColRel() map[string][]string { 51 return map[string][]string{} 52 } 53 54 func (*ChainTx) PrimaryKey() []string { 55 return []string{ 56 "ID", 57 } 58 } 59 60 func (m *ChainTx) IndexFieldNames() []string { 61 return []string{ 62 "ChainID", 63 "ChainTxID", 64 "EventType", 65 "ID", 66 "ProjectName", 67 "TxAddress", 68 "Uniq", 69 } 70 } 71 72 func (*ChainTx) UniqueIndexes() builder.Indexes { 73 return builder.Indexes{ 74 "ui_chain_tx_id": []string{ 75 "ChainTxID", 76 }, 77 "ui_chain_tx_uniq": []string{ 78 "ProjectName", 79 "EventType", 80 "ChainID", 81 "TxAddress", 82 "Uniq", 83 }, 84 } 85 } 86 87 func (*ChainTx) UniqueIndexUIChainTxID() string { 88 return "ui_chain_tx_id" 89 } 90 91 func (*ChainTx) UniqueIndexUIChainTxUniq() string { 92 return "ui_chain_tx_uniq" 93 } 94 95 func (m *ChainTx) ColID() *builder.Column { 96 return ChainTxTable.ColByFieldName(m.FieldID()) 97 } 98 99 func (*ChainTx) FieldID() string { 100 return "ID" 101 } 102 103 func (m *ChainTx) ColChainTxID() *builder.Column { 104 return ChainTxTable.ColByFieldName(m.FieldChainTxID()) 105 } 106 107 func (*ChainTx) FieldChainTxID() string { 108 return "ChainTxID" 109 } 110 111 func (m *ChainTx) ColProjectName() *builder.Column { 112 return ChainTxTable.ColByFieldName(m.FieldProjectName()) 113 } 114 115 func (*ChainTx) FieldProjectName() string { 116 return "ProjectName" 117 } 118 119 func (m *ChainTx) ColFinished() *builder.Column { 120 return ChainTxTable.ColByFieldName(m.FieldFinished()) 121 } 122 123 func (*ChainTx) FieldFinished() string { 124 return "Finished" 125 } 126 127 func (m *ChainTx) ColUniq() *builder.Column { 128 return ChainTxTable.ColByFieldName(m.FieldUniq()) 129 } 130 131 func (*ChainTx) FieldUniq() string { 132 return "Uniq" 133 } 134 135 func (m *ChainTx) ColEventType() *builder.Column { 136 return ChainTxTable.ColByFieldName(m.FieldEventType()) 137 } 138 139 func (*ChainTx) FieldEventType() string { 140 return "EventType" 141 } 142 143 func (m *ChainTx) ColChainID() *builder.Column { 144 return ChainTxTable.ColByFieldName(m.FieldChainID()) 145 } 146 147 func (*ChainTx) FieldChainID() string { 148 return "ChainID" 149 } 150 151 func (m *ChainTx) ColTxAddress() *builder.Column { 152 return ChainTxTable.ColByFieldName(m.FieldTxAddress()) 153 } 154 155 func (*ChainTx) FieldTxAddress() string { 156 return "TxAddress" 157 } 158 159 func (m *ChainTx) ColPaused() *builder.Column { 160 return ChainTxTable.ColByFieldName(m.FieldPaused()) 161 } 162 163 func (*ChainTx) FieldPaused() string { 164 return "Paused" 165 } 166 167 func (m *ChainTx) ColCreatedAt() *builder.Column { 168 return ChainTxTable.ColByFieldName(m.FieldCreatedAt()) 169 } 170 171 func (*ChainTx) FieldCreatedAt() string { 172 return "CreatedAt" 173 } 174 175 func (m *ChainTx) ColUpdatedAt() *builder.Column { 176 return ChainTxTable.ColByFieldName(m.FieldUpdatedAt()) 177 } 178 179 func (*ChainTx) FieldUpdatedAt() string { 180 return "UpdatedAt" 181 } 182 183 func (m *ChainTx) CondByValue(db sqlx.DBExecutor) builder.SqlCondition { 184 var ( 185 tbl = db.T(m) 186 fvs = builder.FieldValueFromStructByNoneZero(m) 187 cond = make([]builder.SqlCondition, 0) 188 ) 189 190 for _, fn := range m.IndexFieldNames() { 191 if v, ok := fvs[fn]; ok { 192 cond = append(cond, tbl.ColByFieldName(fn).Eq(v)) 193 delete(fvs, fn) 194 } 195 } 196 if len(cond) == 0 { 197 panic(fmt.Errorf("no field for indexes has value")) 198 } 199 for fn, v := range fvs { 200 cond = append(cond, tbl.ColByFieldName(fn).Eq(v)) 201 } 202 return builder.And(cond...) 203 } 204 205 func (m *ChainTx) Create(db sqlx.DBExecutor) error { 206 207 if m.CreatedAt.IsZero() { 208 m.CreatedAt.Set(time.Now()) 209 } 210 211 if m.UpdatedAt.IsZero() { 212 m.UpdatedAt.Set(time.Now()) 213 } 214 215 _, err := db.Exec(sqlx.InsertToDB(db, m, nil)) 216 return err 217 } 218 219 func (m *ChainTx) List(db sqlx.DBExecutor, cond builder.SqlCondition, adds ...builder.Addition) ([]ChainTx, error) { 220 var ( 221 tbl = db.T(m) 222 lst = make([]ChainTx, 0) 223 ) 224 adds = append([]builder.Addition{builder.Where(cond), builder.Comment("ChainTx.List")}, adds...) 225 err := db.QueryAndScan(builder.Select(nil).From(tbl, adds...), &lst) 226 return lst, err 227 } 228 229 func (m *ChainTx) Count(db sqlx.DBExecutor, cond builder.SqlCondition, adds ...builder.Addition) (cnt int64, err error) { 230 tbl := db.T(m) 231 adds = append([]builder.Addition{builder.Where(cond), builder.Comment("ChainTx.List")}, adds...) 232 err = db.QueryAndScan(builder.Select(builder.Count()).From(tbl, adds...), &cnt) 233 return 234 } 235 236 func (m *ChainTx) FetchByID(db sqlx.DBExecutor) error { 237 tbl := db.T(m) 238 err := db.QueryAndScan( 239 builder.Select(nil). 240 From( 241 tbl, 242 builder.Where( 243 builder.And( 244 tbl.ColByFieldName("ID").Eq(m.ID), 245 ), 246 ), 247 builder.Comment("ChainTx.FetchByID"), 248 ), 249 m, 250 ) 251 return err 252 } 253 254 func (m *ChainTx) FetchByChainTxID(db sqlx.DBExecutor) error { 255 tbl := db.T(m) 256 err := db.QueryAndScan( 257 builder.Select(nil). 258 From( 259 tbl, 260 builder.Where( 261 builder.And( 262 tbl.ColByFieldName("ChainTxID").Eq(m.ChainTxID), 263 ), 264 ), 265 builder.Comment("ChainTx.FetchByChainTxID"), 266 ), 267 m, 268 ) 269 return err 270 } 271 272 func (m *ChainTx) FetchByProjectNameAndEventTypeAndChainIDAndTxAddressAndUniq(db sqlx.DBExecutor) error { 273 tbl := db.T(m) 274 err := db.QueryAndScan( 275 builder.Select(nil). 276 From( 277 tbl, 278 builder.Where( 279 builder.And( 280 tbl.ColByFieldName("ProjectName").Eq(m.ProjectName), 281 tbl.ColByFieldName("EventType").Eq(m.EventType), 282 tbl.ColByFieldName("ChainID").Eq(m.ChainID), 283 tbl.ColByFieldName("TxAddress").Eq(m.TxAddress), 284 tbl.ColByFieldName("Uniq").Eq(m.Uniq), 285 ), 286 ), 287 builder.Comment("ChainTx.FetchByProjectNameAndEventTypeAndChainIDAndTxAddressAndUniq"), 288 ), 289 m, 290 ) 291 return err 292 } 293 294 func (m *ChainTx) UpdateByIDWithFVs(db sqlx.DBExecutor, fvs builder.FieldValues) error { 295 296 if _, ok := fvs["UpdatedAt"]; !ok { 297 fvs["UpdatedAt"] = types.Timestamp{Time: time.Now()} 298 } 299 tbl := db.T(m) 300 res, err := db.Exec( 301 builder.Update(tbl). 302 Where( 303 builder.And( 304 tbl.ColByFieldName("ID").Eq(m.ID), 305 ), 306 builder.Comment("ChainTx.UpdateByIDWithFVs"), 307 ). 308 Set(tbl.AssignmentsByFieldValues(fvs)...), 309 ) 310 if err != nil { 311 return err 312 } 313 if affected, _ := res.RowsAffected(); affected == 0 { 314 return m.FetchByID(db) 315 } 316 return nil 317 } 318 319 func (m *ChainTx) UpdateByID(db sqlx.DBExecutor, zeros ...string) error { 320 fvs := builder.FieldValueFromStructByNoneZero(m, zeros...) 321 return m.UpdateByIDWithFVs(db, fvs) 322 } 323 324 func (m *ChainTx) UpdateByChainTxIDWithFVs(db sqlx.DBExecutor, fvs builder.FieldValues) error { 325 326 if _, ok := fvs["UpdatedAt"]; !ok { 327 fvs["UpdatedAt"] = types.Timestamp{Time: time.Now()} 328 } 329 tbl := db.T(m) 330 res, err := db.Exec( 331 builder.Update(tbl). 332 Where( 333 builder.And( 334 tbl.ColByFieldName("ChainTxID").Eq(m.ChainTxID), 335 ), 336 builder.Comment("ChainTx.UpdateByChainTxIDWithFVs"), 337 ). 338 Set(tbl.AssignmentsByFieldValues(fvs)...), 339 ) 340 if err != nil { 341 return err 342 } 343 if affected, _ := res.RowsAffected(); affected == 0 { 344 return m.FetchByChainTxID(db) 345 } 346 return nil 347 } 348 349 func (m *ChainTx) UpdateByChainTxID(db sqlx.DBExecutor, zeros ...string) error { 350 fvs := builder.FieldValueFromStructByNoneZero(m, zeros...) 351 return m.UpdateByChainTxIDWithFVs(db, fvs) 352 } 353 354 func (m *ChainTx) UpdateByProjectNameAndEventTypeAndChainIDAndTxAddressAndUniqWithFVs(db sqlx.DBExecutor, fvs builder.FieldValues) error { 355 356 if _, ok := fvs["UpdatedAt"]; !ok { 357 fvs["UpdatedAt"] = types.Timestamp{Time: time.Now()} 358 } 359 tbl := db.T(m) 360 res, err := db.Exec( 361 builder.Update(tbl). 362 Where( 363 builder.And( 364 tbl.ColByFieldName("ProjectName").Eq(m.ProjectName), 365 tbl.ColByFieldName("EventType").Eq(m.EventType), 366 tbl.ColByFieldName("ChainID").Eq(m.ChainID), 367 tbl.ColByFieldName("TxAddress").Eq(m.TxAddress), 368 tbl.ColByFieldName("Uniq").Eq(m.Uniq), 369 ), 370 builder.Comment("ChainTx.UpdateByProjectNameAndEventTypeAndChainIDAndTxAddressAndUniqWithFVs"), 371 ). 372 Set(tbl.AssignmentsByFieldValues(fvs)...), 373 ) 374 if err != nil { 375 return err 376 } 377 if affected, _ := res.RowsAffected(); affected == 0 { 378 return m.FetchByProjectNameAndEventTypeAndChainIDAndTxAddressAndUniq(db) 379 } 380 return nil 381 } 382 383 func (m *ChainTx) UpdateByProjectNameAndEventTypeAndChainIDAndTxAddressAndUniq(db sqlx.DBExecutor, zeros ...string) error { 384 fvs := builder.FieldValueFromStructByNoneZero(m, zeros...) 385 return m.UpdateByProjectNameAndEventTypeAndChainIDAndTxAddressAndUniqWithFVs(db, fvs) 386 } 387 388 func (m *ChainTx) Delete(db sqlx.DBExecutor) error { 389 _, err := db.Exec( 390 builder.Delete(). 391 From( 392 db.T(m), 393 builder.Where(m.CondByValue(db)), 394 builder.Comment("ChainTx.Delete"), 395 ), 396 ) 397 return err 398 } 399 400 func (m *ChainTx) DeleteByID(db sqlx.DBExecutor) error { 401 tbl := db.T(m) 402 _, err := db.Exec( 403 builder.Delete(). 404 From( 405 tbl, 406 builder.Where( 407 builder.And( 408 tbl.ColByFieldName("ID").Eq(m.ID), 409 ), 410 ), 411 builder.Comment("ChainTx.DeleteByID"), 412 ), 413 ) 414 return err 415 } 416 417 func (m *ChainTx) DeleteByChainTxID(db sqlx.DBExecutor) error { 418 tbl := db.T(m) 419 _, err := db.Exec( 420 builder.Delete(). 421 From( 422 tbl, 423 builder.Where( 424 builder.And( 425 tbl.ColByFieldName("ChainTxID").Eq(m.ChainTxID), 426 ), 427 ), 428 builder.Comment("ChainTx.DeleteByChainTxID"), 429 ), 430 ) 431 return err 432 } 433 434 func (m *ChainTx) DeleteByProjectNameAndEventTypeAndChainIDAndTxAddressAndUniq(db sqlx.DBExecutor) error { 435 tbl := db.T(m) 436 _, err := db.Exec( 437 builder.Delete(). 438 From( 439 tbl, 440 builder.Where( 441 builder.And( 442 tbl.ColByFieldName("ProjectName").Eq(m.ProjectName), 443 tbl.ColByFieldName("EventType").Eq(m.EventType), 444 tbl.ColByFieldName("ChainID").Eq(m.ChainID), 445 tbl.ColByFieldName("TxAddress").Eq(m.TxAddress), 446 tbl.ColByFieldName("Uniq").Eq(m.Uniq), 447 ), 448 ), 449 builder.Comment("ChainTx.DeleteByProjectNameAndEventTypeAndChainIDAndTxAddressAndUniq"), 450 ), 451 ) 452 return err 453 }