github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/pkg/db/ent/exchangerate_create.go (about) 1 // Code generated by ent, DO NOT EDIT. 2 3 package ent 4 5 import ( 6 "context" 7 "errors" 8 "fmt" 9 10 "entgo.io/ent/dialect/sql" 11 "entgo.io/ent/dialect/sql/sqlgraph" 12 "entgo.io/ent/schema/field" 13 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/exchangerate" 14 "github.com/google/uuid" 15 "github.com/shopspring/decimal" 16 ) 17 18 // ExchangeRateCreate is the builder for creating a ExchangeRate entity. 19 type ExchangeRateCreate struct { 20 config 21 mutation *ExchangeRateMutation 22 hooks []Hook 23 conflict []sql.ConflictOption 24 } 25 26 // SetCreatedAt sets the "created_at" field. 27 func (erc *ExchangeRateCreate) SetCreatedAt(u uint32) *ExchangeRateCreate { 28 erc.mutation.SetCreatedAt(u) 29 return erc 30 } 31 32 // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. 33 func (erc *ExchangeRateCreate) SetNillableCreatedAt(u *uint32) *ExchangeRateCreate { 34 if u != nil { 35 erc.SetCreatedAt(*u) 36 } 37 return erc 38 } 39 40 // SetUpdatedAt sets the "updated_at" field. 41 func (erc *ExchangeRateCreate) SetUpdatedAt(u uint32) *ExchangeRateCreate { 42 erc.mutation.SetUpdatedAt(u) 43 return erc 44 } 45 46 // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. 47 func (erc *ExchangeRateCreate) SetNillableUpdatedAt(u *uint32) *ExchangeRateCreate { 48 if u != nil { 49 erc.SetUpdatedAt(*u) 50 } 51 return erc 52 } 53 54 // SetDeletedAt sets the "deleted_at" field. 55 func (erc *ExchangeRateCreate) SetDeletedAt(u uint32) *ExchangeRateCreate { 56 erc.mutation.SetDeletedAt(u) 57 return erc 58 } 59 60 // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. 61 func (erc *ExchangeRateCreate) SetNillableDeletedAt(u *uint32) *ExchangeRateCreate { 62 if u != nil { 63 erc.SetDeletedAt(*u) 64 } 65 return erc 66 } 67 68 // SetEntID sets the "ent_id" field. 69 func (erc *ExchangeRateCreate) SetEntID(u uuid.UUID) *ExchangeRateCreate { 70 erc.mutation.SetEntID(u) 71 return erc 72 } 73 74 // SetNillableEntID sets the "ent_id" field if the given value is not nil. 75 func (erc *ExchangeRateCreate) SetNillableEntID(u *uuid.UUID) *ExchangeRateCreate { 76 if u != nil { 77 erc.SetEntID(*u) 78 } 79 return erc 80 } 81 82 // SetAppID sets the "app_id" field. 83 func (erc *ExchangeRateCreate) SetAppID(u uuid.UUID) *ExchangeRateCreate { 84 erc.mutation.SetAppID(u) 85 return erc 86 } 87 88 // SetNillableAppID sets the "app_id" field if the given value is not nil. 89 func (erc *ExchangeRateCreate) SetNillableAppID(u *uuid.UUID) *ExchangeRateCreate { 90 if u != nil { 91 erc.SetAppID(*u) 92 } 93 return erc 94 } 95 96 // SetCoinTypeID sets the "coin_type_id" field. 97 func (erc *ExchangeRateCreate) SetCoinTypeID(u uuid.UUID) *ExchangeRateCreate { 98 erc.mutation.SetCoinTypeID(u) 99 return erc 100 } 101 102 // SetNillableCoinTypeID sets the "coin_type_id" field if the given value is not nil. 103 func (erc *ExchangeRateCreate) SetNillableCoinTypeID(u *uuid.UUID) *ExchangeRateCreate { 104 if u != nil { 105 erc.SetCoinTypeID(*u) 106 } 107 return erc 108 } 109 110 // SetMarketValue sets the "market_value" field. 111 func (erc *ExchangeRateCreate) SetMarketValue(d decimal.Decimal) *ExchangeRateCreate { 112 erc.mutation.SetMarketValue(d) 113 return erc 114 } 115 116 // SetNillableMarketValue sets the "market_value" field if the given value is not nil. 117 func (erc *ExchangeRateCreate) SetNillableMarketValue(d *decimal.Decimal) *ExchangeRateCreate { 118 if d != nil { 119 erc.SetMarketValue(*d) 120 } 121 return erc 122 } 123 124 // SetSettleValue sets the "settle_value" field. 125 func (erc *ExchangeRateCreate) SetSettleValue(d decimal.Decimal) *ExchangeRateCreate { 126 erc.mutation.SetSettleValue(d) 127 return erc 128 } 129 130 // SetNillableSettleValue sets the "settle_value" field if the given value is not nil. 131 func (erc *ExchangeRateCreate) SetNillableSettleValue(d *decimal.Decimal) *ExchangeRateCreate { 132 if d != nil { 133 erc.SetSettleValue(*d) 134 } 135 return erc 136 } 137 138 // SetSettlePercent sets the "settle_percent" field. 139 func (erc *ExchangeRateCreate) SetSettlePercent(u uint32) *ExchangeRateCreate { 140 erc.mutation.SetSettlePercent(u) 141 return erc 142 } 143 144 // SetNillableSettlePercent sets the "settle_percent" field if the given value is not nil. 145 func (erc *ExchangeRateCreate) SetNillableSettlePercent(u *uint32) *ExchangeRateCreate { 146 if u != nil { 147 erc.SetSettlePercent(*u) 148 } 149 return erc 150 } 151 152 // SetSettleTips sets the "settle_tips" field. 153 func (erc *ExchangeRateCreate) SetSettleTips(s []string) *ExchangeRateCreate { 154 erc.mutation.SetSettleTips(s) 155 return erc 156 } 157 158 // SetSetter sets the "setter" field. 159 func (erc *ExchangeRateCreate) SetSetter(u uuid.UUID) *ExchangeRateCreate { 160 erc.mutation.SetSetter(u) 161 return erc 162 } 163 164 // SetNillableSetter sets the "setter" field if the given value is not nil. 165 func (erc *ExchangeRateCreate) SetNillableSetter(u *uuid.UUID) *ExchangeRateCreate { 166 if u != nil { 167 erc.SetSetter(*u) 168 } 169 return erc 170 } 171 172 // SetID sets the "id" field. 173 func (erc *ExchangeRateCreate) SetID(u uint32) *ExchangeRateCreate { 174 erc.mutation.SetID(u) 175 return erc 176 } 177 178 // Mutation returns the ExchangeRateMutation object of the builder. 179 func (erc *ExchangeRateCreate) Mutation() *ExchangeRateMutation { 180 return erc.mutation 181 } 182 183 // Save creates the ExchangeRate in the database. 184 func (erc *ExchangeRateCreate) Save(ctx context.Context) (*ExchangeRate, error) { 185 var ( 186 err error 187 node *ExchangeRate 188 ) 189 if err := erc.defaults(); err != nil { 190 return nil, err 191 } 192 if len(erc.hooks) == 0 { 193 if err = erc.check(); err != nil { 194 return nil, err 195 } 196 node, err = erc.sqlSave(ctx) 197 } else { 198 var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { 199 mutation, ok := m.(*ExchangeRateMutation) 200 if !ok { 201 return nil, fmt.Errorf("unexpected mutation type %T", m) 202 } 203 if err = erc.check(); err != nil { 204 return nil, err 205 } 206 erc.mutation = mutation 207 if node, err = erc.sqlSave(ctx); err != nil { 208 return nil, err 209 } 210 mutation.id = &node.ID 211 mutation.done = true 212 return node, err 213 }) 214 for i := len(erc.hooks) - 1; i >= 0; i-- { 215 if erc.hooks[i] == nil { 216 return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") 217 } 218 mut = erc.hooks[i](mut) 219 } 220 v, err := mut.Mutate(ctx, erc.mutation) 221 if err != nil { 222 return nil, err 223 } 224 nv, ok := v.(*ExchangeRate) 225 if !ok { 226 return nil, fmt.Errorf("unexpected node type %T returned from ExchangeRateMutation", v) 227 } 228 node = nv 229 } 230 return node, err 231 } 232 233 // SaveX calls Save and panics if Save returns an error. 234 func (erc *ExchangeRateCreate) SaveX(ctx context.Context) *ExchangeRate { 235 v, err := erc.Save(ctx) 236 if err != nil { 237 panic(err) 238 } 239 return v 240 } 241 242 // Exec executes the query. 243 func (erc *ExchangeRateCreate) Exec(ctx context.Context) error { 244 _, err := erc.Save(ctx) 245 return err 246 } 247 248 // ExecX is like Exec, but panics if an error occurs. 249 func (erc *ExchangeRateCreate) ExecX(ctx context.Context) { 250 if err := erc.Exec(ctx); err != nil { 251 panic(err) 252 } 253 } 254 255 // defaults sets the default values of the builder before save. 256 func (erc *ExchangeRateCreate) defaults() error { 257 if _, ok := erc.mutation.CreatedAt(); !ok { 258 if exchangerate.DefaultCreatedAt == nil { 259 return fmt.Errorf("ent: uninitialized exchangerate.DefaultCreatedAt (forgotten import ent/runtime?)") 260 } 261 v := exchangerate.DefaultCreatedAt() 262 erc.mutation.SetCreatedAt(v) 263 } 264 if _, ok := erc.mutation.UpdatedAt(); !ok { 265 if exchangerate.DefaultUpdatedAt == nil { 266 return fmt.Errorf("ent: uninitialized exchangerate.DefaultUpdatedAt (forgotten import ent/runtime?)") 267 } 268 v := exchangerate.DefaultUpdatedAt() 269 erc.mutation.SetUpdatedAt(v) 270 } 271 if _, ok := erc.mutation.DeletedAt(); !ok { 272 if exchangerate.DefaultDeletedAt == nil { 273 return fmt.Errorf("ent: uninitialized exchangerate.DefaultDeletedAt (forgotten import ent/runtime?)") 274 } 275 v := exchangerate.DefaultDeletedAt() 276 erc.mutation.SetDeletedAt(v) 277 } 278 if _, ok := erc.mutation.EntID(); !ok { 279 if exchangerate.DefaultEntID == nil { 280 return fmt.Errorf("ent: uninitialized exchangerate.DefaultEntID (forgotten import ent/runtime?)") 281 } 282 v := exchangerate.DefaultEntID() 283 erc.mutation.SetEntID(v) 284 } 285 if _, ok := erc.mutation.AppID(); !ok { 286 if exchangerate.DefaultAppID == nil { 287 return fmt.Errorf("ent: uninitialized exchangerate.DefaultAppID (forgotten import ent/runtime?)") 288 } 289 v := exchangerate.DefaultAppID() 290 erc.mutation.SetAppID(v) 291 } 292 if _, ok := erc.mutation.CoinTypeID(); !ok { 293 if exchangerate.DefaultCoinTypeID == nil { 294 return fmt.Errorf("ent: uninitialized exchangerate.DefaultCoinTypeID (forgotten import ent/runtime?)") 295 } 296 v := exchangerate.DefaultCoinTypeID() 297 erc.mutation.SetCoinTypeID(v) 298 } 299 if _, ok := erc.mutation.MarketValue(); !ok { 300 v := exchangerate.DefaultMarketValue 301 erc.mutation.SetMarketValue(v) 302 } 303 if _, ok := erc.mutation.SettleValue(); !ok { 304 v := exchangerate.DefaultSettleValue 305 erc.mutation.SetSettleValue(v) 306 } 307 if _, ok := erc.mutation.SettlePercent(); !ok { 308 v := exchangerate.DefaultSettlePercent 309 erc.mutation.SetSettlePercent(v) 310 } 311 if _, ok := erc.mutation.SettleTips(); !ok { 312 v := exchangerate.DefaultSettleTips 313 erc.mutation.SetSettleTips(v) 314 } 315 if _, ok := erc.mutation.Setter(); !ok { 316 if exchangerate.DefaultSetter == nil { 317 return fmt.Errorf("ent: uninitialized exchangerate.DefaultSetter (forgotten import ent/runtime?)") 318 } 319 v := exchangerate.DefaultSetter() 320 erc.mutation.SetSetter(v) 321 } 322 return nil 323 } 324 325 // check runs all checks and user-defined validators on the builder. 326 func (erc *ExchangeRateCreate) check() error { 327 if _, ok := erc.mutation.CreatedAt(); !ok { 328 return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "ExchangeRate.created_at"`)} 329 } 330 if _, ok := erc.mutation.UpdatedAt(); !ok { 331 return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "ExchangeRate.updated_at"`)} 332 } 333 if _, ok := erc.mutation.DeletedAt(); !ok { 334 return &ValidationError{Name: "deleted_at", err: errors.New(`ent: missing required field "ExchangeRate.deleted_at"`)} 335 } 336 if _, ok := erc.mutation.EntID(); !ok { 337 return &ValidationError{Name: "ent_id", err: errors.New(`ent: missing required field "ExchangeRate.ent_id"`)} 338 } 339 return nil 340 } 341 342 func (erc *ExchangeRateCreate) sqlSave(ctx context.Context) (*ExchangeRate, error) { 343 _node, _spec := erc.createSpec() 344 if err := sqlgraph.CreateNode(ctx, erc.driver, _spec); err != nil { 345 if sqlgraph.IsConstraintError(err) { 346 err = &ConstraintError{msg: err.Error(), wrap: err} 347 } 348 return nil, err 349 } 350 if _spec.ID.Value != _node.ID { 351 id := _spec.ID.Value.(int64) 352 _node.ID = uint32(id) 353 } 354 return _node, nil 355 } 356 357 func (erc *ExchangeRateCreate) createSpec() (*ExchangeRate, *sqlgraph.CreateSpec) { 358 var ( 359 _node = &ExchangeRate{config: erc.config} 360 _spec = &sqlgraph.CreateSpec{ 361 Table: exchangerate.Table, 362 ID: &sqlgraph.FieldSpec{ 363 Type: field.TypeUint32, 364 Column: exchangerate.FieldID, 365 }, 366 } 367 ) 368 _spec.OnConflict = erc.conflict 369 if id, ok := erc.mutation.ID(); ok { 370 _node.ID = id 371 _spec.ID.Value = id 372 } 373 if value, ok := erc.mutation.CreatedAt(); ok { 374 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 375 Type: field.TypeUint32, 376 Value: value, 377 Column: exchangerate.FieldCreatedAt, 378 }) 379 _node.CreatedAt = value 380 } 381 if value, ok := erc.mutation.UpdatedAt(); ok { 382 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 383 Type: field.TypeUint32, 384 Value: value, 385 Column: exchangerate.FieldUpdatedAt, 386 }) 387 _node.UpdatedAt = value 388 } 389 if value, ok := erc.mutation.DeletedAt(); ok { 390 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 391 Type: field.TypeUint32, 392 Value: value, 393 Column: exchangerate.FieldDeletedAt, 394 }) 395 _node.DeletedAt = value 396 } 397 if value, ok := erc.mutation.EntID(); ok { 398 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 399 Type: field.TypeUUID, 400 Value: value, 401 Column: exchangerate.FieldEntID, 402 }) 403 _node.EntID = value 404 } 405 if value, ok := erc.mutation.AppID(); ok { 406 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 407 Type: field.TypeUUID, 408 Value: value, 409 Column: exchangerate.FieldAppID, 410 }) 411 _node.AppID = value 412 } 413 if value, ok := erc.mutation.CoinTypeID(); ok { 414 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 415 Type: field.TypeUUID, 416 Value: value, 417 Column: exchangerate.FieldCoinTypeID, 418 }) 419 _node.CoinTypeID = value 420 } 421 if value, ok := erc.mutation.MarketValue(); ok { 422 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 423 Type: field.TypeOther, 424 Value: value, 425 Column: exchangerate.FieldMarketValue, 426 }) 427 _node.MarketValue = value 428 } 429 if value, ok := erc.mutation.SettleValue(); ok { 430 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 431 Type: field.TypeOther, 432 Value: value, 433 Column: exchangerate.FieldSettleValue, 434 }) 435 _node.SettleValue = value 436 } 437 if value, ok := erc.mutation.SettlePercent(); ok { 438 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 439 Type: field.TypeUint32, 440 Value: value, 441 Column: exchangerate.FieldSettlePercent, 442 }) 443 _node.SettlePercent = value 444 } 445 if value, ok := erc.mutation.SettleTips(); ok { 446 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 447 Type: field.TypeJSON, 448 Value: value, 449 Column: exchangerate.FieldSettleTips, 450 }) 451 _node.SettleTips = value 452 } 453 if value, ok := erc.mutation.Setter(); ok { 454 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 455 Type: field.TypeUUID, 456 Value: value, 457 Column: exchangerate.FieldSetter, 458 }) 459 _node.Setter = value 460 } 461 return _node, _spec 462 } 463 464 // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause 465 // of the `INSERT` statement. For example: 466 // 467 // client.ExchangeRate.Create(). 468 // SetCreatedAt(v). 469 // OnConflict( 470 // // Update the row with the new values 471 // // the was proposed for insertion. 472 // sql.ResolveWithNewValues(), 473 // ). 474 // // Override some of the fields with custom 475 // // update values. 476 // Update(func(u *ent.ExchangeRateUpsert) { 477 // SetCreatedAt(v+v). 478 // }). 479 // Exec(ctx) 480 // 481 func (erc *ExchangeRateCreate) OnConflict(opts ...sql.ConflictOption) *ExchangeRateUpsertOne { 482 erc.conflict = opts 483 return &ExchangeRateUpsertOne{ 484 create: erc, 485 } 486 } 487 488 // OnConflictColumns calls `OnConflict` and configures the columns 489 // as conflict target. Using this option is equivalent to using: 490 // 491 // client.ExchangeRate.Create(). 492 // OnConflict(sql.ConflictColumns(columns...)). 493 // Exec(ctx) 494 // 495 func (erc *ExchangeRateCreate) OnConflictColumns(columns ...string) *ExchangeRateUpsertOne { 496 erc.conflict = append(erc.conflict, sql.ConflictColumns(columns...)) 497 return &ExchangeRateUpsertOne{ 498 create: erc, 499 } 500 } 501 502 type ( 503 // ExchangeRateUpsertOne is the builder for "upsert"-ing 504 // one ExchangeRate node. 505 ExchangeRateUpsertOne struct { 506 create *ExchangeRateCreate 507 } 508 509 // ExchangeRateUpsert is the "OnConflict" setter. 510 ExchangeRateUpsert struct { 511 *sql.UpdateSet 512 } 513 ) 514 515 // SetCreatedAt sets the "created_at" field. 516 func (u *ExchangeRateUpsert) SetCreatedAt(v uint32) *ExchangeRateUpsert { 517 u.Set(exchangerate.FieldCreatedAt, v) 518 return u 519 } 520 521 // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. 522 func (u *ExchangeRateUpsert) UpdateCreatedAt() *ExchangeRateUpsert { 523 u.SetExcluded(exchangerate.FieldCreatedAt) 524 return u 525 } 526 527 // AddCreatedAt adds v to the "created_at" field. 528 func (u *ExchangeRateUpsert) AddCreatedAt(v uint32) *ExchangeRateUpsert { 529 u.Add(exchangerate.FieldCreatedAt, v) 530 return u 531 } 532 533 // SetUpdatedAt sets the "updated_at" field. 534 func (u *ExchangeRateUpsert) SetUpdatedAt(v uint32) *ExchangeRateUpsert { 535 u.Set(exchangerate.FieldUpdatedAt, v) 536 return u 537 } 538 539 // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. 540 func (u *ExchangeRateUpsert) UpdateUpdatedAt() *ExchangeRateUpsert { 541 u.SetExcluded(exchangerate.FieldUpdatedAt) 542 return u 543 } 544 545 // AddUpdatedAt adds v to the "updated_at" field. 546 func (u *ExchangeRateUpsert) AddUpdatedAt(v uint32) *ExchangeRateUpsert { 547 u.Add(exchangerate.FieldUpdatedAt, v) 548 return u 549 } 550 551 // SetDeletedAt sets the "deleted_at" field. 552 func (u *ExchangeRateUpsert) SetDeletedAt(v uint32) *ExchangeRateUpsert { 553 u.Set(exchangerate.FieldDeletedAt, v) 554 return u 555 } 556 557 // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. 558 func (u *ExchangeRateUpsert) UpdateDeletedAt() *ExchangeRateUpsert { 559 u.SetExcluded(exchangerate.FieldDeletedAt) 560 return u 561 } 562 563 // AddDeletedAt adds v to the "deleted_at" field. 564 func (u *ExchangeRateUpsert) AddDeletedAt(v uint32) *ExchangeRateUpsert { 565 u.Add(exchangerate.FieldDeletedAt, v) 566 return u 567 } 568 569 // SetEntID sets the "ent_id" field. 570 func (u *ExchangeRateUpsert) SetEntID(v uuid.UUID) *ExchangeRateUpsert { 571 u.Set(exchangerate.FieldEntID, v) 572 return u 573 } 574 575 // UpdateEntID sets the "ent_id" field to the value that was provided on create. 576 func (u *ExchangeRateUpsert) UpdateEntID() *ExchangeRateUpsert { 577 u.SetExcluded(exchangerate.FieldEntID) 578 return u 579 } 580 581 // SetAppID sets the "app_id" field. 582 func (u *ExchangeRateUpsert) SetAppID(v uuid.UUID) *ExchangeRateUpsert { 583 u.Set(exchangerate.FieldAppID, v) 584 return u 585 } 586 587 // UpdateAppID sets the "app_id" field to the value that was provided on create. 588 func (u *ExchangeRateUpsert) UpdateAppID() *ExchangeRateUpsert { 589 u.SetExcluded(exchangerate.FieldAppID) 590 return u 591 } 592 593 // ClearAppID clears the value of the "app_id" field. 594 func (u *ExchangeRateUpsert) ClearAppID() *ExchangeRateUpsert { 595 u.SetNull(exchangerate.FieldAppID) 596 return u 597 } 598 599 // SetCoinTypeID sets the "coin_type_id" field. 600 func (u *ExchangeRateUpsert) SetCoinTypeID(v uuid.UUID) *ExchangeRateUpsert { 601 u.Set(exchangerate.FieldCoinTypeID, v) 602 return u 603 } 604 605 // UpdateCoinTypeID sets the "coin_type_id" field to the value that was provided on create. 606 func (u *ExchangeRateUpsert) UpdateCoinTypeID() *ExchangeRateUpsert { 607 u.SetExcluded(exchangerate.FieldCoinTypeID) 608 return u 609 } 610 611 // ClearCoinTypeID clears the value of the "coin_type_id" field. 612 func (u *ExchangeRateUpsert) ClearCoinTypeID() *ExchangeRateUpsert { 613 u.SetNull(exchangerate.FieldCoinTypeID) 614 return u 615 } 616 617 // SetMarketValue sets the "market_value" field. 618 func (u *ExchangeRateUpsert) SetMarketValue(v decimal.Decimal) *ExchangeRateUpsert { 619 u.Set(exchangerate.FieldMarketValue, v) 620 return u 621 } 622 623 // UpdateMarketValue sets the "market_value" field to the value that was provided on create. 624 func (u *ExchangeRateUpsert) UpdateMarketValue() *ExchangeRateUpsert { 625 u.SetExcluded(exchangerate.FieldMarketValue) 626 return u 627 } 628 629 // ClearMarketValue clears the value of the "market_value" field. 630 func (u *ExchangeRateUpsert) ClearMarketValue() *ExchangeRateUpsert { 631 u.SetNull(exchangerate.FieldMarketValue) 632 return u 633 } 634 635 // SetSettleValue sets the "settle_value" field. 636 func (u *ExchangeRateUpsert) SetSettleValue(v decimal.Decimal) *ExchangeRateUpsert { 637 u.Set(exchangerate.FieldSettleValue, v) 638 return u 639 } 640 641 // UpdateSettleValue sets the "settle_value" field to the value that was provided on create. 642 func (u *ExchangeRateUpsert) UpdateSettleValue() *ExchangeRateUpsert { 643 u.SetExcluded(exchangerate.FieldSettleValue) 644 return u 645 } 646 647 // ClearSettleValue clears the value of the "settle_value" field. 648 func (u *ExchangeRateUpsert) ClearSettleValue() *ExchangeRateUpsert { 649 u.SetNull(exchangerate.FieldSettleValue) 650 return u 651 } 652 653 // SetSettlePercent sets the "settle_percent" field. 654 func (u *ExchangeRateUpsert) SetSettlePercent(v uint32) *ExchangeRateUpsert { 655 u.Set(exchangerate.FieldSettlePercent, v) 656 return u 657 } 658 659 // UpdateSettlePercent sets the "settle_percent" field to the value that was provided on create. 660 func (u *ExchangeRateUpsert) UpdateSettlePercent() *ExchangeRateUpsert { 661 u.SetExcluded(exchangerate.FieldSettlePercent) 662 return u 663 } 664 665 // AddSettlePercent adds v to the "settle_percent" field. 666 func (u *ExchangeRateUpsert) AddSettlePercent(v uint32) *ExchangeRateUpsert { 667 u.Add(exchangerate.FieldSettlePercent, v) 668 return u 669 } 670 671 // ClearSettlePercent clears the value of the "settle_percent" field. 672 func (u *ExchangeRateUpsert) ClearSettlePercent() *ExchangeRateUpsert { 673 u.SetNull(exchangerate.FieldSettlePercent) 674 return u 675 } 676 677 // SetSettleTips sets the "settle_tips" field. 678 func (u *ExchangeRateUpsert) SetSettleTips(v []string) *ExchangeRateUpsert { 679 u.Set(exchangerate.FieldSettleTips, v) 680 return u 681 } 682 683 // UpdateSettleTips sets the "settle_tips" field to the value that was provided on create. 684 func (u *ExchangeRateUpsert) UpdateSettleTips() *ExchangeRateUpsert { 685 u.SetExcluded(exchangerate.FieldSettleTips) 686 return u 687 } 688 689 // ClearSettleTips clears the value of the "settle_tips" field. 690 func (u *ExchangeRateUpsert) ClearSettleTips() *ExchangeRateUpsert { 691 u.SetNull(exchangerate.FieldSettleTips) 692 return u 693 } 694 695 // SetSetter sets the "setter" field. 696 func (u *ExchangeRateUpsert) SetSetter(v uuid.UUID) *ExchangeRateUpsert { 697 u.Set(exchangerate.FieldSetter, v) 698 return u 699 } 700 701 // UpdateSetter sets the "setter" field to the value that was provided on create. 702 func (u *ExchangeRateUpsert) UpdateSetter() *ExchangeRateUpsert { 703 u.SetExcluded(exchangerate.FieldSetter) 704 return u 705 } 706 707 // ClearSetter clears the value of the "setter" field. 708 func (u *ExchangeRateUpsert) ClearSetter() *ExchangeRateUpsert { 709 u.SetNull(exchangerate.FieldSetter) 710 return u 711 } 712 713 // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field. 714 // Using this option is equivalent to using: 715 // 716 // client.ExchangeRate.Create(). 717 // OnConflict( 718 // sql.ResolveWithNewValues(), 719 // sql.ResolveWith(func(u *sql.UpdateSet) { 720 // u.SetIgnore(exchangerate.FieldID) 721 // }), 722 // ). 723 // Exec(ctx) 724 // 725 func (u *ExchangeRateUpsertOne) UpdateNewValues() *ExchangeRateUpsertOne { 726 u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) 727 u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { 728 if _, exists := u.create.mutation.ID(); exists { 729 s.SetIgnore(exchangerate.FieldID) 730 } 731 })) 732 return u 733 } 734 735 // Ignore sets each column to itself in case of conflict. 736 // Using this option is equivalent to using: 737 // 738 // client.ExchangeRate.Create(). 739 // OnConflict(sql.ResolveWithIgnore()). 740 // Exec(ctx) 741 // 742 func (u *ExchangeRateUpsertOne) Ignore() *ExchangeRateUpsertOne { 743 u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) 744 return u 745 } 746 747 // DoNothing configures the conflict_action to `DO NOTHING`. 748 // Supported only by SQLite and PostgreSQL. 749 func (u *ExchangeRateUpsertOne) DoNothing() *ExchangeRateUpsertOne { 750 u.create.conflict = append(u.create.conflict, sql.DoNothing()) 751 return u 752 } 753 754 // Update allows overriding fields `UPDATE` values. See the ExchangeRateCreate.OnConflict 755 // documentation for more info. 756 func (u *ExchangeRateUpsertOne) Update(set func(*ExchangeRateUpsert)) *ExchangeRateUpsertOne { 757 u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { 758 set(&ExchangeRateUpsert{UpdateSet: update}) 759 })) 760 return u 761 } 762 763 // SetCreatedAt sets the "created_at" field. 764 func (u *ExchangeRateUpsertOne) SetCreatedAt(v uint32) *ExchangeRateUpsertOne { 765 return u.Update(func(s *ExchangeRateUpsert) { 766 s.SetCreatedAt(v) 767 }) 768 } 769 770 // AddCreatedAt adds v to the "created_at" field. 771 func (u *ExchangeRateUpsertOne) AddCreatedAt(v uint32) *ExchangeRateUpsertOne { 772 return u.Update(func(s *ExchangeRateUpsert) { 773 s.AddCreatedAt(v) 774 }) 775 } 776 777 // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. 778 func (u *ExchangeRateUpsertOne) UpdateCreatedAt() *ExchangeRateUpsertOne { 779 return u.Update(func(s *ExchangeRateUpsert) { 780 s.UpdateCreatedAt() 781 }) 782 } 783 784 // SetUpdatedAt sets the "updated_at" field. 785 func (u *ExchangeRateUpsertOne) SetUpdatedAt(v uint32) *ExchangeRateUpsertOne { 786 return u.Update(func(s *ExchangeRateUpsert) { 787 s.SetUpdatedAt(v) 788 }) 789 } 790 791 // AddUpdatedAt adds v to the "updated_at" field. 792 func (u *ExchangeRateUpsertOne) AddUpdatedAt(v uint32) *ExchangeRateUpsertOne { 793 return u.Update(func(s *ExchangeRateUpsert) { 794 s.AddUpdatedAt(v) 795 }) 796 } 797 798 // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. 799 func (u *ExchangeRateUpsertOne) UpdateUpdatedAt() *ExchangeRateUpsertOne { 800 return u.Update(func(s *ExchangeRateUpsert) { 801 s.UpdateUpdatedAt() 802 }) 803 } 804 805 // SetDeletedAt sets the "deleted_at" field. 806 func (u *ExchangeRateUpsertOne) SetDeletedAt(v uint32) *ExchangeRateUpsertOne { 807 return u.Update(func(s *ExchangeRateUpsert) { 808 s.SetDeletedAt(v) 809 }) 810 } 811 812 // AddDeletedAt adds v to the "deleted_at" field. 813 func (u *ExchangeRateUpsertOne) AddDeletedAt(v uint32) *ExchangeRateUpsertOne { 814 return u.Update(func(s *ExchangeRateUpsert) { 815 s.AddDeletedAt(v) 816 }) 817 } 818 819 // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. 820 func (u *ExchangeRateUpsertOne) UpdateDeletedAt() *ExchangeRateUpsertOne { 821 return u.Update(func(s *ExchangeRateUpsert) { 822 s.UpdateDeletedAt() 823 }) 824 } 825 826 // SetEntID sets the "ent_id" field. 827 func (u *ExchangeRateUpsertOne) SetEntID(v uuid.UUID) *ExchangeRateUpsertOne { 828 return u.Update(func(s *ExchangeRateUpsert) { 829 s.SetEntID(v) 830 }) 831 } 832 833 // UpdateEntID sets the "ent_id" field to the value that was provided on create. 834 func (u *ExchangeRateUpsertOne) UpdateEntID() *ExchangeRateUpsertOne { 835 return u.Update(func(s *ExchangeRateUpsert) { 836 s.UpdateEntID() 837 }) 838 } 839 840 // SetAppID sets the "app_id" field. 841 func (u *ExchangeRateUpsertOne) SetAppID(v uuid.UUID) *ExchangeRateUpsertOne { 842 return u.Update(func(s *ExchangeRateUpsert) { 843 s.SetAppID(v) 844 }) 845 } 846 847 // UpdateAppID sets the "app_id" field to the value that was provided on create. 848 func (u *ExchangeRateUpsertOne) UpdateAppID() *ExchangeRateUpsertOne { 849 return u.Update(func(s *ExchangeRateUpsert) { 850 s.UpdateAppID() 851 }) 852 } 853 854 // ClearAppID clears the value of the "app_id" field. 855 func (u *ExchangeRateUpsertOne) ClearAppID() *ExchangeRateUpsertOne { 856 return u.Update(func(s *ExchangeRateUpsert) { 857 s.ClearAppID() 858 }) 859 } 860 861 // SetCoinTypeID sets the "coin_type_id" field. 862 func (u *ExchangeRateUpsertOne) SetCoinTypeID(v uuid.UUID) *ExchangeRateUpsertOne { 863 return u.Update(func(s *ExchangeRateUpsert) { 864 s.SetCoinTypeID(v) 865 }) 866 } 867 868 // UpdateCoinTypeID sets the "coin_type_id" field to the value that was provided on create. 869 func (u *ExchangeRateUpsertOne) UpdateCoinTypeID() *ExchangeRateUpsertOne { 870 return u.Update(func(s *ExchangeRateUpsert) { 871 s.UpdateCoinTypeID() 872 }) 873 } 874 875 // ClearCoinTypeID clears the value of the "coin_type_id" field. 876 func (u *ExchangeRateUpsertOne) ClearCoinTypeID() *ExchangeRateUpsertOne { 877 return u.Update(func(s *ExchangeRateUpsert) { 878 s.ClearCoinTypeID() 879 }) 880 } 881 882 // SetMarketValue sets the "market_value" field. 883 func (u *ExchangeRateUpsertOne) SetMarketValue(v decimal.Decimal) *ExchangeRateUpsertOne { 884 return u.Update(func(s *ExchangeRateUpsert) { 885 s.SetMarketValue(v) 886 }) 887 } 888 889 // UpdateMarketValue sets the "market_value" field to the value that was provided on create. 890 func (u *ExchangeRateUpsertOne) UpdateMarketValue() *ExchangeRateUpsertOne { 891 return u.Update(func(s *ExchangeRateUpsert) { 892 s.UpdateMarketValue() 893 }) 894 } 895 896 // ClearMarketValue clears the value of the "market_value" field. 897 func (u *ExchangeRateUpsertOne) ClearMarketValue() *ExchangeRateUpsertOne { 898 return u.Update(func(s *ExchangeRateUpsert) { 899 s.ClearMarketValue() 900 }) 901 } 902 903 // SetSettleValue sets the "settle_value" field. 904 func (u *ExchangeRateUpsertOne) SetSettleValue(v decimal.Decimal) *ExchangeRateUpsertOne { 905 return u.Update(func(s *ExchangeRateUpsert) { 906 s.SetSettleValue(v) 907 }) 908 } 909 910 // UpdateSettleValue sets the "settle_value" field to the value that was provided on create. 911 func (u *ExchangeRateUpsertOne) UpdateSettleValue() *ExchangeRateUpsertOne { 912 return u.Update(func(s *ExchangeRateUpsert) { 913 s.UpdateSettleValue() 914 }) 915 } 916 917 // ClearSettleValue clears the value of the "settle_value" field. 918 func (u *ExchangeRateUpsertOne) ClearSettleValue() *ExchangeRateUpsertOne { 919 return u.Update(func(s *ExchangeRateUpsert) { 920 s.ClearSettleValue() 921 }) 922 } 923 924 // SetSettlePercent sets the "settle_percent" field. 925 func (u *ExchangeRateUpsertOne) SetSettlePercent(v uint32) *ExchangeRateUpsertOne { 926 return u.Update(func(s *ExchangeRateUpsert) { 927 s.SetSettlePercent(v) 928 }) 929 } 930 931 // AddSettlePercent adds v to the "settle_percent" field. 932 func (u *ExchangeRateUpsertOne) AddSettlePercent(v uint32) *ExchangeRateUpsertOne { 933 return u.Update(func(s *ExchangeRateUpsert) { 934 s.AddSettlePercent(v) 935 }) 936 } 937 938 // UpdateSettlePercent sets the "settle_percent" field to the value that was provided on create. 939 func (u *ExchangeRateUpsertOne) UpdateSettlePercent() *ExchangeRateUpsertOne { 940 return u.Update(func(s *ExchangeRateUpsert) { 941 s.UpdateSettlePercent() 942 }) 943 } 944 945 // ClearSettlePercent clears the value of the "settle_percent" field. 946 func (u *ExchangeRateUpsertOne) ClearSettlePercent() *ExchangeRateUpsertOne { 947 return u.Update(func(s *ExchangeRateUpsert) { 948 s.ClearSettlePercent() 949 }) 950 } 951 952 // SetSettleTips sets the "settle_tips" field. 953 func (u *ExchangeRateUpsertOne) SetSettleTips(v []string) *ExchangeRateUpsertOne { 954 return u.Update(func(s *ExchangeRateUpsert) { 955 s.SetSettleTips(v) 956 }) 957 } 958 959 // UpdateSettleTips sets the "settle_tips" field to the value that was provided on create. 960 func (u *ExchangeRateUpsertOne) UpdateSettleTips() *ExchangeRateUpsertOne { 961 return u.Update(func(s *ExchangeRateUpsert) { 962 s.UpdateSettleTips() 963 }) 964 } 965 966 // ClearSettleTips clears the value of the "settle_tips" field. 967 func (u *ExchangeRateUpsertOne) ClearSettleTips() *ExchangeRateUpsertOne { 968 return u.Update(func(s *ExchangeRateUpsert) { 969 s.ClearSettleTips() 970 }) 971 } 972 973 // SetSetter sets the "setter" field. 974 func (u *ExchangeRateUpsertOne) SetSetter(v uuid.UUID) *ExchangeRateUpsertOne { 975 return u.Update(func(s *ExchangeRateUpsert) { 976 s.SetSetter(v) 977 }) 978 } 979 980 // UpdateSetter sets the "setter" field to the value that was provided on create. 981 func (u *ExchangeRateUpsertOne) UpdateSetter() *ExchangeRateUpsertOne { 982 return u.Update(func(s *ExchangeRateUpsert) { 983 s.UpdateSetter() 984 }) 985 } 986 987 // ClearSetter clears the value of the "setter" field. 988 func (u *ExchangeRateUpsertOne) ClearSetter() *ExchangeRateUpsertOne { 989 return u.Update(func(s *ExchangeRateUpsert) { 990 s.ClearSetter() 991 }) 992 } 993 994 // Exec executes the query. 995 func (u *ExchangeRateUpsertOne) Exec(ctx context.Context) error { 996 if len(u.create.conflict) == 0 { 997 return errors.New("ent: missing options for ExchangeRateCreate.OnConflict") 998 } 999 return u.create.Exec(ctx) 1000 } 1001 1002 // ExecX is like Exec, but panics if an error occurs. 1003 func (u *ExchangeRateUpsertOne) ExecX(ctx context.Context) { 1004 if err := u.create.Exec(ctx); err != nil { 1005 panic(err) 1006 } 1007 } 1008 1009 // Exec executes the UPSERT query and returns the inserted/updated ID. 1010 func (u *ExchangeRateUpsertOne) ID(ctx context.Context) (id uint32, err error) { 1011 node, err := u.create.Save(ctx) 1012 if err != nil { 1013 return id, err 1014 } 1015 return node.ID, nil 1016 } 1017 1018 // IDX is like ID, but panics if an error occurs. 1019 func (u *ExchangeRateUpsertOne) IDX(ctx context.Context) uint32 { 1020 id, err := u.ID(ctx) 1021 if err != nil { 1022 panic(err) 1023 } 1024 return id 1025 } 1026 1027 // ExchangeRateCreateBulk is the builder for creating many ExchangeRate entities in bulk. 1028 type ExchangeRateCreateBulk struct { 1029 config 1030 builders []*ExchangeRateCreate 1031 conflict []sql.ConflictOption 1032 } 1033 1034 // Save creates the ExchangeRate entities in the database. 1035 func (ercb *ExchangeRateCreateBulk) Save(ctx context.Context) ([]*ExchangeRate, error) { 1036 specs := make([]*sqlgraph.CreateSpec, len(ercb.builders)) 1037 nodes := make([]*ExchangeRate, len(ercb.builders)) 1038 mutators := make([]Mutator, len(ercb.builders)) 1039 for i := range ercb.builders { 1040 func(i int, root context.Context) { 1041 builder := ercb.builders[i] 1042 builder.defaults() 1043 var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { 1044 mutation, ok := m.(*ExchangeRateMutation) 1045 if !ok { 1046 return nil, fmt.Errorf("unexpected mutation type %T", m) 1047 } 1048 if err := builder.check(); err != nil { 1049 return nil, err 1050 } 1051 builder.mutation = mutation 1052 nodes[i], specs[i] = builder.createSpec() 1053 var err error 1054 if i < len(mutators)-1 { 1055 _, err = mutators[i+1].Mutate(root, ercb.builders[i+1].mutation) 1056 } else { 1057 spec := &sqlgraph.BatchCreateSpec{Nodes: specs} 1058 spec.OnConflict = ercb.conflict 1059 // Invoke the actual operation on the latest mutation in the chain. 1060 if err = sqlgraph.BatchCreate(ctx, ercb.driver, spec); err != nil { 1061 if sqlgraph.IsConstraintError(err) { 1062 err = &ConstraintError{msg: err.Error(), wrap: err} 1063 } 1064 } 1065 } 1066 if err != nil { 1067 return nil, err 1068 } 1069 mutation.id = &nodes[i].ID 1070 if specs[i].ID.Value != nil && nodes[i].ID == 0 { 1071 id := specs[i].ID.Value.(int64) 1072 nodes[i].ID = uint32(id) 1073 } 1074 mutation.done = true 1075 return nodes[i], nil 1076 }) 1077 for i := len(builder.hooks) - 1; i >= 0; i-- { 1078 mut = builder.hooks[i](mut) 1079 } 1080 mutators[i] = mut 1081 }(i, ctx) 1082 } 1083 if len(mutators) > 0 { 1084 if _, err := mutators[0].Mutate(ctx, ercb.builders[0].mutation); err != nil { 1085 return nil, err 1086 } 1087 } 1088 return nodes, nil 1089 } 1090 1091 // SaveX is like Save, but panics if an error occurs. 1092 func (ercb *ExchangeRateCreateBulk) SaveX(ctx context.Context) []*ExchangeRate { 1093 v, err := ercb.Save(ctx) 1094 if err != nil { 1095 panic(err) 1096 } 1097 return v 1098 } 1099 1100 // Exec executes the query. 1101 func (ercb *ExchangeRateCreateBulk) Exec(ctx context.Context) error { 1102 _, err := ercb.Save(ctx) 1103 return err 1104 } 1105 1106 // ExecX is like Exec, but panics if an error occurs. 1107 func (ercb *ExchangeRateCreateBulk) ExecX(ctx context.Context) { 1108 if err := ercb.Exec(ctx); err != nil { 1109 panic(err) 1110 } 1111 } 1112 1113 // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause 1114 // of the `INSERT` statement. For example: 1115 // 1116 // client.ExchangeRate.CreateBulk(builders...). 1117 // OnConflict( 1118 // // Update the row with the new values 1119 // // the was proposed for insertion. 1120 // sql.ResolveWithNewValues(), 1121 // ). 1122 // // Override some of the fields with custom 1123 // // update values. 1124 // Update(func(u *ent.ExchangeRateUpsert) { 1125 // SetCreatedAt(v+v). 1126 // }). 1127 // Exec(ctx) 1128 // 1129 func (ercb *ExchangeRateCreateBulk) OnConflict(opts ...sql.ConflictOption) *ExchangeRateUpsertBulk { 1130 ercb.conflict = opts 1131 return &ExchangeRateUpsertBulk{ 1132 create: ercb, 1133 } 1134 } 1135 1136 // OnConflictColumns calls `OnConflict` and configures the columns 1137 // as conflict target. Using this option is equivalent to using: 1138 // 1139 // client.ExchangeRate.Create(). 1140 // OnConflict(sql.ConflictColumns(columns...)). 1141 // Exec(ctx) 1142 // 1143 func (ercb *ExchangeRateCreateBulk) OnConflictColumns(columns ...string) *ExchangeRateUpsertBulk { 1144 ercb.conflict = append(ercb.conflict, sql.ConflictColumns(columns...)) 1145 return &ExchangeRateUpsertBulk{ 1146 create: ercb, 1147 } 1148 } 1149 1150 // ExchangeRateUpsertBulk is the builder for "upsert"-ing 1151 // a bulk of ExchangeRate nodes. 1152 type ExchangeRateUpsertBulk struct { 1153 create *ExchangeRateCreateBulk 1154 } 1155 1156 // UpdateNewValues updates the mutable fields using the new values that 1157 // were set on create. Using this option is equivalent to using: 1158 // 1159 // client.ExchangeRate.Create(). 1160 // OnConflict( 1161 // sql.ResolveWithNewValues(), 1162 // sql.ResolveWith(func(u *sql.UpdateSet) { 1163 // u.SetIgnore(exchangerate.FieldID) 1164 // }), 1165 // ). 1166 // Exec(ctx) 1167 // 1168 func (u *ExchangeRateUpsertBulk) UpdateNewValues() *ExchangeRateUpsertBulk { 1169 u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) 1170 u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { 1171 for _, b := range u.create.builders { 1172 if _, exists := b.mutation.ID(); exists { 1173 s.SetIgnore(exchangerate.FieldID) 1174 return 1175 } 1176 } 1177 })) 1178 return u 1179 } 1180 1181 // Ignore sets each column to itself in case of conflict. 1182 // Using this option is equivalent to using: 1183 // 1184 // client.ExchangeRate.Create(). 1185 // OnConflict(sql.ResolveWithIgnore()). 1186 // Exec(ctx) 1187 // 1188 func (u *ExchangeRateUpsertBulk) Ignore() *ExchangeRateUpsertBulk { 1189 u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) 1190 return u 1191 } 1192 1193 // DoNothing configures the conflict_action to `DO NOTHING`. 1194 // Supported only by SQLite and PostgreSQL. 1195 func (u *ExchangeRateUpsertBulk) DoNothing() *ExchangeRateUpsertBulk { 1196 u.create.conflict = append(u.create.conflict, sql.DoNothing()) 1197 return u 1198 } 1199 1200 // Update allows overriding fields `UPDATE` values. See the ExchangeRateCreateBulk.OnConflict 1201 // documentation for more info. 1202 func (u *ExchangeRateUpsertBulk) Update(set func(*ExchangeRateUpsert)) *ExchangeRateUpsertBulk { 1203 u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { 1204 set(&ExchangeRateUpsert{UpdateSet: update}) 1205 })) 1206 return u 1207 } 1208 1209 // SetCreatedAt sets the "created_at" field. 1210 func (u *ExchangeRateUpsertBulk) SetCreatedAt(v uint32) *ExchangeRateUpsertBulk { 1211 return u.Update(func(s *ExchangeRateUpsert) { 1212 s.SetCreatedAt(v) 1213 }) 1214 } 1215 1216 // AddCreatedAt adds v to the "created_at" field. 1217 func (u *ExchangeRateUpsertBulk) AddCreatedAt(v uint32) *ExchangeRateUpsertBulk { 1218 return u.Update(func(s *ExchangeRateUpsert) { 1219 s.AddCreatedAt(v) 1220 }) 1221 } 1222 1223 // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. 1224 func (u *ExchangeRateUpsertBulk) UpdateCreatedAt() *ExchangeRateUpsertBulk { 1225 return u.Update(func(s *ExchangeRateUpsert) { 1226 s.UpdateCreatedAt() 1227 }) 1228 } 1229 1230 // SetUpdatedAt sets the "updated_at" field. 1231 func (u *ExchangeRateUpsertBulk) SetUpdatedAt(v uint32) *ExchangeRateUpsertBulk { 1232 return u.Update(func(s *ExchangeRateUpsert) { 1233 s.SetUpdatedAt(v) 1234 }) 1235 } 1236 1237 // AddUpdatedAt adds v to the "updated_at" field. 1238 func (u *ExchangeRateUpsertBulk) AddUpdatedAt(v uint32) *ExchangeRateUpsertBulk { 1239 return u.Update(func(s *ExchangeRateUpsert) { 1240 s.AddUpdatedAt(v) 1241 }) 1242 } 1243 1244 // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. 1245 func (u *ExchangeRateUpsertBulk) UpdateUpdatedAt() *ExchangeRateUpsertBulk { 1246 return u.Update(func(s *ExchangeRateUpsert) { 1247 s.UpdateUpdatedAt() 1248 }) 1249 } 1250 1251 // SetDeletedAt sets the "deleted_at" field. 1252 func (u *ExchangeRateUpsertBulk) SetDeletedAt(v uint32) *ExchangeRateUpsertBulk { 1253 return u.Update(func(s *ExchangeRateUpsert) { 1254 s.SetDeletedAt(v) 1255 }) 1256 } 1257 1258 // AddDeletedAt adds v to the "deleted_at" field. 1259 func (u *ExchangeRateUpsertBulk) AddDeletedAt(v uint32) *ExchangeRateUpsertBulk { 1260 return u.Update(func(s *ExchangeRateUpsert) { 1261 s.AddDeletedAt(v) 1262 }) 1263 } 1264 1265 // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. 1266 func (u *ExchangeRateUpsertBulk) UpdateDeletedAt() *ExchangeRateUpsertBulk { 1267 return u.Update(func(s *ExchangeRateUpsert) { 1268 s.UpdateDeletedAt() 1269 }) 1270 } 1271 1272 // SetEntID sets the "ent_id" field. 1273 func (u *ExchangeRateUpsertBulk) SetEntID(v uuid.UUID) *ExchangeRateUpsertBulk { 1274 return u.Update(func(s *ExchangeRateUpsert) { 1275 s.SetEntID(v) 1276 }) 1277 } 1278 1279 // UpdateEntID sets the "ent_id" field to the value that was provided on create. 1280 func (u *ExchangeRateUpsertBulk) UpdateEntID() *ExchangeRateUpsertBulk { 1281 return u.Update(func(s *ExchangeRateUpsert) { 1282 s.UpdateEntID() 1283 }) 1284 } 1285 1286 // SetAppID sets the "app_id" field. 1287 func (u *ExchangeRateUpsertBulk) SetAppID(v uuid.UUID) *ExchangeRateUpsertBulk { 1288 return u.Update(func(s *ExchangeRateUpsert) { 1289 s.SetAppID(v) 1290 }) 1291 } 1292 1293 // UpdateAppID sets the "app_id" field to the value that was provided on create. 1294 func (u *ExchangeRateUpsertBulk) UpdateAppID() *ExchangeRateUpsertBulk { 1295 return u.Update(func(s *ExchangeRateUpsert) { 1296 s.UpdateAppID() 1297 }) 1298 } 1299 1300 // ClearAppID clears the value of the "app_id" field. 1301 func (u *ExchangeRateUpsertBulk) ClearAppID() *ExchangeRateUpsertBulk { 1302 return u.Update(func(s *ExchangeRateUpsert) { 1303 s.ClearAppID() 1304 }) 1305 } 1306 1307 // SetCoinTypeID sets the "coin_type_id" field. 1308 func (u *ExchangeRateUpsertBulk) SetCoinTypeID(v uuid.UUID) *ExchangeRateUpsertBulk { 1309 return u.Update(func(s *ExchangeRateUpsert) { 1310 s.SetCoinTypeID(v) 1311 }) 1312 } 1313 1314 // UpdateCoinTypeID sets the "coin_type_id" field to the value that was provided on create. 1315 func (u *ExchangeRateUpsertBulk) UpdateCoinTypeID() *ExchangeRateUpsertBulk { 1316 return u.Update(func(s *ExchangeRateUpsert) { 1317 s.UpdateCoinTypeID() 1318 }) 1319 } 1320 1321 // ClearCoinTypeID clears the value of the "coin_type_id" field. 1322 func (u *ExchangeRateUpsertBulk) ClearCoinTypeID() *ExchangeRateUpsertBulk { 1323 return u.Update(func(s *ExchangeRateUpsert) { 1324 s.ClearCoinTypeID() 1325 }) 1326 } 1327 1328 // SetMarketValue sets the "market_value" field. 1329 func (u *ExchangeRateUpsertBulk) SetMarketValue(v decimal.Decimal) *ExchangeRateUpsertBulk { 1330 return u.Update(func(s *ExchangeRateUpsert) { 1331 s.SetMarketValue(v) 1332 }) 1333 } 1334 1335 // UpdateMarketValue sets the "market_value" field to the value that was provided on create. 1336 func (u *ExchangeRateUpsertBulk) UpdateMarketValue() *ExchangeRateUpsertBulk { 1337 return u.Update(func(s *ExchangeRateUpsert) { 1338 s.UpdateMarketValue() 1339 }) 1340 } 1341 1342 // ClearMarketValue clears the value of the "market_value" field. 1343 func (u *ExchangeRateUpsertBulk) ClearMarketValue() *ExchangeRateUpsertBulk { 1344 return u.Update(func(s *ExchangeRateUpsert) { 1345 s.ClearMarketValue() 1346 }) 1347 } 1348 1349 // SetSettleValue sets the "settle_value" field. 1350 func (u *ExchangeRateUpsertBulk) SetSettleValue(v decimal.Decimal) *ExchangeRateUpsertBulk { 1351 return u.Update(func(s *ExchangeRateUpsert) { 1352 s.SetSettleValue(v) 1353 }) 1354 } 1355 1356 // UpdateSettleValue sets the "settle_value" field to the value that was provided on create. 1357 func (u *ExchangeRateUpsertBulk) UpdateSettleValue() *ExchangeRateUpsertBulk { 1358 return u.Update(func(s *ExchangeRateUpsert) { 1359 s.UpdateSettleValue() 1360 }) 1361 } 1362 1363 // ClearSettleValue clears the value of the "settle_value" field. 1364 func (u *ExchangeRateUpsertBulk) ClearSettleValue() *ExchangeRateUpsertBulk { 1365 return u.Update(func(s *ExchangeRateUpsert) { 1366 s.ClearSettleValue() 1367 }) 1368 } 1369 1370 // SetSettlePercent sets the "settle_percent" field. 1371 func (u *ExchangeRateUpsertBulk) SetSettlePercent(v uint32) *ExchangeRateUpsertBulk { 1372 return u.Update(func(s *ExchangeRateUpsert) { 1373 s.SetSettlePercent(v) 1374 }) 1375 } 1376 1377 // AddSettlePercent adds v to the "settle_percent" field. 1378 func (u *ExchangeRateUpsertBulk) AddSettlePercent(v uint32) *ExchangeRateUpsertBulk { 1379 return u.Update(func(s *ExchangeRateUpsert) { 1380 s.AddSettlePercent(v) 1381 }) 1382 } 1383 1384 // UpdateSettlePercent sets the "settle_percent" field to the value that was provided on create. 1385 func (u *ExchangeRateUpsertBulk) UpdateSettlePercent() *ExchangeRateUpsertBulk { 1386 return u.Update(func(s *ExchangeRateUpsert) { 1387 s.UpdateSettlePercent() 1388 }) 1389 } 1390 1391 // ClearSettlePercent clears the value of the "settle_percent" field. 1392 func (u *ExchangeRateUpsertBulk) ClearSettlePercent() *ExchangeRateUpsertBulk { 1393 return u.Update(func(s *ExchangeRateUpsert) { 1394 s.ClearSettlePercent() 1395 }) 1396 } 1397 1398 // SetSettleTips sets the "settle_tips" field. 1399 func (u *ExchangeRateUpsertBulk) SetSettleTips(v []string) *ExchangeRateUpsertBulk { 1400 return u.Update(func(s *ExchangeRateUpsert) { 1401 s.SetSettleTips(v) 1402 }) 1403 } 1404 1405 // UpdateSettleTips sets the "settle_tips" field to the value that was provided on create. 1406 func (u *ExchangeRateUpsertBulk) UpdateSettleTips() *ExchangeRateUpsertBulk { 1407 return u.Update(func(s *ExchangeRateUpsert) { 1408 s.UpdateSettleTips() 1409 }) 1410 } 1411 1412 // ClearSettleTips clears the value of the "settle_tips" field. 1413 func (u *ExchangeRateUpsertBulk) ClearSettleTips() *ExchangeRateUpsertBulk { 1414 return u.Update(func(s *ExchangeRateUpsert) { 1415 s.ClearSettleTips() 1416 }) 1417 } 1418 1419 // SetSetter sets the "setter" field. 1420 func (u *ExchangeRateUpsertBulk) SetSetter(v uuid.UUID) *ExchangeRateUpsertBulk { 1421 return u.Update(func(s *ExchangeRateUpsert) { 1422 s.SetSetter(v) 1423 }) 1424 } 1425 1426 // UpdateSetter sets the "setter" field to the value that was provided on create. 1427 func (u *ExchangeRateUpsertBulk) UpdateSetter() *ExchangeRateUpsertBulk { 1428 return u.Update(func(s *ExchangeRateUpsert) { 1429 s.UpdateSetter() 1430 }) 1431 } 1432 1433 // ClearSetter clears the value of the "setter" field. 1434 func (u *ExchangeRateUpsertBulk) ClearSetter() *ExchangeRateUpsertBulk { 1435 return u.Update(func(s *ExchangeRateUpsert) { 1436 s.ClearSetter() 1437 }) 1438 } 1439 1440 // Exec executes the query. 1441 func (u *ExchangeRateUpsertBulk) Exec(ctx context.Context) error { 1442 for i, b := range u.create.builders { 1443 if len(b.conflict) != 0 { 1444 return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the ExchangeRateCreateBulk instead", i) 1445 } 1446 } 1447 if len(u.create.conflict) == 0 { 1448 return errors.New("ent: missing options for ExchangeRateCreateBulk.OnConflict") 1449 } 1450 return u.create.Exec(ctx) 1451 } 1452 1453 // ExecX is like Exec, but panics if an error occurs. 1454 func (u *ExchangeRateUpsertBulk) ExecX(ctx context.Context) { 1455 if err := u.create.Exec(ctx); err != nil { 1456 panic(err) 1457 } 1458 }