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