github.com/oinume/lekcije@v0.0.0-20231017100347-5b4c5eb6ab24/backend/model2/notification_time_span.go (about) 1 // Code generated by SQLBoiler 4.14.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. 2 // This file is meant to be re-generated in place and/or deleted at any time. 3 4 package model2 5 6 import ( 7 "context" 8 "database/sql" 9 "fmt" 10 "reflect" 11 "strconv" 12 "strings" 13 "sync" 14 "time" 15 16 "github.com/friendsofgo/errors" 17 "github.com/volatiletech/sqlboiler/v4/boil" 18 "github.com/volatiletech/sqlboiler/v4/queries" 19 "github.com/volatiletech/sqlboiler/v4/queries/qm" 20 "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" 21 "github.com/volatiletech/strmangle" 22 ) 23 24 // NotificationTimeSpan is an object representing the database table. 25 type NotificationTimeSpan struct { 26 UserID uint `boil:"user_id" json:"user_id" toml:"user_id" yaml:"user_id"` 27 Number uint8 `boil:"number" json:"number" toml:"number" yaml:"number"` 28 FromTime string `boil:"from_time" json:"from_time" toml:"from_time" yaml:"from_time"` 29 ToTime string `boil:"to_time" json:"to_time" toml:"to_time" yaml:"to_time"` 30 CreatedAt time.Time `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"` 31 32 R *notificationTimeSpanR `boil:"-" json:"-" toml:"-" yaml:"-"` 33 L notificationTimeSpanL `boil:"-" json:"-" toml:"-" yaml:"-"` 34 } 35 36 var NotificationTimeSpanColumns = struct { 37 UserID string 38 Number string 39 FromTime string 40 ToTime string 41 CreatedAt string 42 }{ 43 UserID: "user_id", 44 Number: "number", 45 FromTime: "from_time", 46 ToTime: "to_time", 47 CreatedAt: "created_at", 48 } 49 50 var NotificationTimeSpanTableColumns = struct { 51 UserID string 52 Number string 53 FromTime string 54 ToTime string 55 CreatedAt string 56 }{ 57 UserID: "notification_time_span.user_id", 58 Number: "notification_time_span.number", 59 FromTime: "notification_time_span.from_time", 60 ToTime: "notification_time_span.to_time", 61 CreatedAt: "notification_time_span.created_at", 62 } 63 64 // Generated where 65 66 var NotificationTimeSpanWhere = struct { 67 UserID whereHelperuint 68 Number whereHelperuint8 69 FromTime whereHelperstring 70 ToTime whereHelperstring 71 CreatedAt whereHelpertime_Time 72 }{ 73 UserID: whereHelperuint{field: "`notification_time_span`.`user_id`"}, 74 Number: whereHelperuint8{field: "`notification_time_span`.`number`"}, 75 FromTime: whereHelperstring{field: "`notification_time_span`.`from_time`"}, 76 ToTime: whereHelperstring{field: "`notification_time_span`.`to_time`"}, 77 CreatedAt: whereHelpertime_Time{field: "`notification_time_span`.`created_at`"}, 78 } 79 80 // NotificationTimeSpanRels is where relationship names are stored. 81 var NotificationTimeSpanRels = struct { 82 }{} 83 84 // notificationTimeSpanR is where relationships are stored. 85 type notificationTimeSpanR struct { 86 } 87 88 // NewStruct creates a new relationship struct 89 func (*notificationTimeSpanR) NewStruct() *notificationTimeSpanR { 90 return ¬ificationTimeSpanR{} 91 } 92 93 // notificationTimeSpanL is where Load methods for each relationship are stored. 94 type notificationTimeSpanL struct{} 95 96 var ( 97 notificationTimeSpanAllColumns = []string{"user_id", "number", "from_time", "to_time", "created_at"} 98 notificationTimeSpanColumnsWithoutDefault = []string{"user_id", "number", "from_time", "to_time", "created_at"} 99 notificationTimeSpanColumnsWithDefault = []string{} 100 notificationTimeSpanPrimaryKeyColumns = []string{"user_id", "number"} 101 notificationTimeSpanGeneratedColumns = []string{} 102 ) 103 104 type ( 105 // NotificationTimeSpanSlice is an alias for a slice of pointers to NotificationTimeSpan. 106 // This should almost always be used instead of []NotificationTimeSpan. 107 NotificationTimeSpanSlice []*NotificationTimeSpan 108 // NotificationTimeSpanHook is the signature for custom NotificationTimeSpan hook methods 109 NotificationTimeSpanHook func(context.Context, boil.ContextExecutor, *NotificationTimeSpan) error 110 111 notificationTimeSpanQuery struct { 112 *queries.Query 113 } 114 ) 115 116 // Cache for insert, update and upsert 117 var ( 118 notificationTimeSpanType = reflect.TypeOf(&NotificationTimeSpan{}) 119 notificationTimeSpanMapping = queries.MakeStructMapping(notificationTimeSpanType) 120 notificationTimeSpanPrimaryKeyMapping, _ = queries.BindMapping(notificationTimeSpanType, notificationTimeSpanMapping, notificationTimeSpanPrimaryKeyColumns) 121 notificationTimeSpanInsertCacheMut sync.RWMutex 122 notificationTimeSpanInsertCache = make(map[string]insertCache) 123 notificationTimeSpanUpdateCacheMut sync.RWMutex 124 notificationTimeSpanUpdateCache = make(map[string]updateCache) 125 notificationTimeSpanUpsertCacheMut sync.RWMutex 126 notificationTimeSpanUpsertCache = make(map[string]insertCache) 127 ) 128 129 var ( 130 // Force time package dependency for automated UpdatedAt/CreatedAt. 131 _ = time.Second 132 // Force qmhelper dependency for where clause generation (which doesn't 133 // always happen) 134 _ = qmhelper.Where 135 ) 136 137 var notificationTimeSpanAfterSelectHooks []NotificationTimeSpanHook 138 139 var notificationTimeSpanBeforeInsertHooks []NotificationTimeSpanHook 140 var notificationTimeSpanAfterInsertHooks []NotificationTimeSpanHook 141 142 var notificationTimeSpanBeforeUpdateHooks []NotificationTimeSpanHook 143 var notificationTimeSpanAfterUpdateHooks []NotificationTimeSpanHook 144 145 var notificationTimeSpanBeforeDeleteHooks []NotificationTimeSpanHook 146 var notificationTimeSpanAfterDeleteHooks []NotificationTimeSpanHook 147 148 var notificationTimeSpanBeforeUpsertHooks []NotificationTimeSpanHook 149 var notificationTimeSpanAfterUpsertHooks []NotificationTimeSpanHook 150 151 // doAfterSelectHooks executes all "after Select" hooks. 152 func (o *NotificationTimeSpan) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { 153 if boil.HooksAreSkipped(ctx) { 154 return nil 155 } 156 157 for _, hook := range notificationTimeSpanAfterSelectHooks { 158 if err := hook(ctx, exec, o); err != nil { 159 return err 160 } 161 } 162 163 return nil 164 } 165 166 // doBeforeInsertHooks executes all "before insert" hooks. 167 func (o *NotificationTimeSpan) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { 168 if boil.HooksAreSkipped(ctx) { 169 return nil 170 } 171 172 for _, hook := range notificationTimeSpanBeforeInsertHooks { 173 if err := hook(ctx, exec, o); err != nil { 174 return err 175 } 176 } 177 178 return nil 179 } 180 181 // doAfterInsertHooks executes all "after Insert" hooks. 182 func (o *NotificationTimeSpan) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { 183 if boil.HooksAreSkipped(ctx) { 184 return nil 185 } 186 187 for _, hook := range notificationTimeSpanAfterInsertHooks { 188 if err := hook(ctx, exec, o); err != nil { 189 return err 190 } 191 } 192 193 return nil 194 } 195 196 // doBeforeUpdateHooks executes all "before Update" hooks. 197 func (o *NotificationTimeSpan) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { 198 if boil.HooksAreSkipped(ctx) { 199 return nil 200 } 201 202 for _, hook := range notificationTimeSpanBeforeUpdateHooks { 203 if err := hook(ctx, exec, o); err != nil { 204 return err 205 } 206 } 207 208 return nil 209 } 210 211 // doAfterUpdateHooks executes all "after Update" hooks. 212 func (o *NotificationTimeSpan) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { 213 if boil.HooksAreSkipped(ctx) { 214 return nil 215 } 216 217 for _, hook := range notificationTimeSpanAfterUpdateHooks { 218 if err := hook(ctx, exec, o); err != nil { 219 return err 220 } 221 } 222 223 return nil 224 } 225 226 // doBeforeDeleteHooks executes all "before Delete" hooks. 227 func (o *NotificationTimeSpan) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { 228 if boil.HooksAreSkipped(ctx) { 229 return nil 230 } 231 232 for _, hook := range notificationTimeSpanBeforeDeleteHooks { 233 if err := hook(ctx, exec, o); err != nil { 234 return err 235 } 236 } 237 238 return nil 239 } 240 241 // doAfterDeleteHooks executes all "after Delete" hooks. 242 func (o *NotificationTimeSpan) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { 243 if boil.HooksAreSkipped(ctx) { 244 return nil 245 } 246 247 for _, hook := range notificationTimeSpanAfterDeleteHooks { 248 if err := hook(ctx, exec, o); err != nil { 249 return err 250 } 251 } 252 253 return nil 254 } 255 256 // doBeforeUpsertHooks executes all "before Upsert" hooks. 257 func (o *NotificationTimeSpan) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { 258 if boil.HooksAreSkipped(ctx) { 259 return nil 260 } 261 262 for _, hook := range notificationTimeSpanBeforeUpsertHooks { 263 if err := hook(ctx, exec, o); err != nil { 264 return err 265 } 266 } 267 268 return nil 269 } 270 271 // doAfterUpsertHooks executes all "after Upsert" hooks. 272 func (o *NotificationTimeSpan) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { 273 if boil.HooksAreSkipped(ctx) { 274 return nil 275 } 276 277 for _, hook := range notificationTimeSpanAfterUpsertHooks { 278 if err := hook(ctx, exec, o); err != nil { 279 return err 280 } 281 } 282 283 return nil 284 } 285 286 // AddNotificationTimeSpanHook registers your hook function for all future operations. 287 func AddNotificationTimeSpanHook(hookPoint boil.HookPoint, notificationTimeSpanHook NotificationTimeSpanHook) { 288 switch hookPoint { 289 case boil.AfterSelectHook: 290 notificationTimeSpanAfterSelectHooks = append(notificationTimeSpanAfterSelectHooks, notificationTimeSpanHook) 291 case boil.BeforeInsertHook: 292 notificationTimeSpanBeforeInsertHooks = append(notificationTimeSpanBeforeInsertHooks, notificationTimeSpanHook) 293 case boil.AfterInsertHook: 294 notificationTimeSpanAfterInsertHooks = append(notificationTimeSpanAfterInsertHooks, notificationTimeSpanHook) 295 case boil.BeforeUpdateHook: 296 notificationTimeSpanBeforeUpdateHooks = append(notificationTimeSpanBeforeUpdateHooks, notificationTimeSpanHook) 297 case boil.AfterUpdateHook: 298 notificationTimeSpanAfterUpdateHooks = append(notificationTimeSpanAfterUpdateHooks, notificationTimeSpanHook) 299 case boil.BeforeDeleteHook: 300 notificationTimeSpanBeforeDeleteHooks = append(notificationTimeSpanBeforeDeleteHooks, notificationTimeSpanHook) 301 case boil.AfterDeleteHook: 302 notificationTimeSpanAfterDeleteHooks = append(notificationTimeSpanAfterDeleteHooks, notificationTimeSpanHook) 303 case boil.BeforeUpsertHook: 304 notificationTimeSpanBeforeUpsertHooks = append(notificationTimeSpanBeforeUpsertHooks, notificationTimeSpanHook) 305 case boil.AfterUpsertHook: 306 notificationTimeSpanAfterUpsertHooks = append(notificationTimeSpanAfterUpsertHooks, notificationTimeSpanHook) 307 } 308 } 309 310 // One returns a single notificationTimeSpan record from the query. 311 func (q notificationTimeSpanQuery) One(ctx context.Context, exec boil.ContextExecutor) (*NotificationTimeSpan, error) { 312 o := &NotificationTimeSpan{} 313 314 queries.SetLimit(q.Query, 1) 315 316 err := q.Bind(ctx, exec, o) 317 if err != nil { 318 if errors.Is(err, sql.ErrNoRows) { 319 return nil, sql.ErrNoRows 320 } 321 return nil, errors.Wrap(err, "model2: failed to execute a one query for notification_time_span") 322 } 323 324 if err := o.doAfterSelectHooks(ctx, exec); err != nil { 325 return o, err 326 } 327 328 return o, nil 329 } 330 331 // All returns all NotificationTimeSpan records from the query. 332 func (q notificationTimeSpanQuery) All(ctx context.Context, exec boil.ContextExecutor) (NotificationTimeSpanSlice, error) { 333 var o []*NotificationTimeSpan 334 335 err := q.Bind(ctx, exec, &o) 336 if err != nil { 337 return nil, errors.Wrap(err, "model2: failed to assign all query results to NotificationTimeSpan slice") 338 } 339 340 if len(notificationTimeSpanAfterSelectHooks) != 0 { 341 for _, obj := range o { 342 if err := obj.doAfterSelectHooks(ctx, exec); err != nil { 343 return o, err 344 } 345 } 346 } 347 348 return o, nil 349 } 350 351 // Count returns the count of all NotificationTimeSpan records in the query. 352 func (q notificationTimeSpanQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) { 353 var count int64 354 355 queries.SetSelect(q.Query, nil) 356 queries.SetCount(q.Query) 357 358 err := q.Query.QueryRowContext(ctx, exec).Scan(&count) 359 if err != nil { 360 return 0, errors.Wrap(err, "model2: failed to count notification_time_span rows") 361 } 362 363 return count, nil 364 } 365 366 // Exists checks if the row exists in the table. 367 func (q notificationTimeSpanQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { 368 var count int64 369 370 queries.SetSelect(q.Query, nil) 371 queries.SetCount(q.Query) 372 queries.SetLimit(q.Query, 1) 373 374 err := q.Query.QueryRowContext(ctx, exec).Scan(&count) 375 if err != nil { 376 return false, errors.Wrap(err, "model2: failed to check if notification_time_span exists") 377 } 378 379 return count > 0, nil 380 } 381 382 // NotificationTimeSpans retrieves all the records using an executor. 383 func NotificationTimeSpans(mods ...qm.QueryMod) notificationTimeSpanQuery { 384 mods = append(mods, qm.From("`notification_time_span`")) 385 q := NewQuery(mods...) 386 if len(queries.GetSelect(q)) == 0 { 387 queries.SetSelect(q, []string{"`notification_time_span`.*"}) 388 } 389 390 return notificationTimeSpanQuery{q} 391 } 392 393 // FindNotificationTimeSpan retrieves a single record by ID with an executor. 394 // If selectCols is empty Find will return all columns. 395 func FindNotificationTimeSpan(ctx context.Context, exec boil.ContextExecutor, userID uint, number uint8, selectCols ...string) (*NotificationTimeSpan, error) { 396 notificationTimeSpanObj := &NotificationTimeSpan{} 397 398 sel := "*" 399 if len(selectCols) > 0 { 400 sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",") 401 } 402 query := fmt.Sprintf( 403 "select %s from `notification_time_span` where `user_id`=? AND `number`=?", sel, 404 ) 405 406 q := queries.Raw(query, userID, number) 407 408 err := q.Bind(ctx, exec, notificationTimeSpanObj) 409 if err != nil { 410 if errors.Is(err, sql.ErrNoRows) { 411 return nil, sql.ErrNoRows 412 } 413 return nil, errors.Wrap(err, "model2: unable to select from notification_time_span") 414 } 415 416 if err = notificationTimeSpanObj.doAfterSelectHooks(ctx, exec); err != nil { 417 return notificationTimeSpanObj, err 418 } 419 420 return notificationTimeSpanObj, nil 421 } 422 423 // Insert a single record using an executor. 424 // See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts. 425 func (o *NotificationTimeSpan) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error { 426 if o == nil { 427 return errors.New("model2: no notification_time_span provided for insertion") 428 } 429 430 var err error 431 if !boil.TimestampsAreSkipped(ctx) { 432 currTime := time.Now().In(boil.GetLocation()) 433 434 if o.CreatedAt.IsZero() { 435 o.CreatedAt = currTime 436 } 437 } 438 439 if err := o.doBeforeInsertHooks(ctx, exec); err != nil { 440 return err 441 } 442 443 nzDefaults := queries.NonZeroDefaultSet(notificationTimeSpanColumnsWithDefault, o) 444 445 key := makeCacheKey(columns, nzDefaults) 446 notificationTimeSpanInsertCacheMut.RLock() 447 cache, cached := notificationTimeSpanInsertCache[key] 448 notificationTimeSpanInsertCacheMut.RUnlock() 449 450 if !cached { 451 wl, returnColumns := columns.InsertColumnSet( 452 notificationTimeSpanAllColumns, 453 notificationTimeSpanColumnsWithDefault, 454 notificationTimeSpanColumnsWithoutDefault, 455 nzDefaults, 456 ) 457 458 cache.valueMapping, err = queries.BindMapping(notificationTimeSpanType, notificationTimeSpanMapping, wl) 459 if err != nil { 460 return err 461 } 462 cache.retMapping, err = queries.BindMapping(notificationTimeSpanType, notificationTimeSpanMapping, returnColumns) 463 if err != nil { 464 return err 465 } 466 if len(wl) != 0 { 467 cache.query = fmt.Sprintf("INSERT INTO `notification_time_span` (`%s`) %%sVALUES (%s)%%s", strings.Join(wl, "`,`"), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1)) 468 } else { 469 cache.query = "INSERT INTO `notification_time_span` () VALUES ()%s%s" 470 } 471 472 var queryOutput, queryReturning string 473 474 if len(cache.retMapping) != 0 { 475 cache.retQuery = fmt.Sprintf("SELECT `%s` FROM `notification_time_span` WHERE %s", strings.Join(returnColumns, "`,`"), strmangle.WhereClause("`", "`", 0, notificationTimeSpanPrimaryKeyColumns)) 476 } 477 478 cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning) 479 } 480 481 value := reflect.Indirect(reflect.ValueOf(o)) 482 vals := queries.ValuesFromMapping(value, cache.valueMapping) 483 484 if boil.IsDebug(ctx) { 485 writer := boil.DebugWriterFrom(ctx) 486 fmt.Fprintln(writer, cache.query) 487 fmt.Fprintln(writer, vals) 488 } 489 _, err = exec.ExecContext(ctx, cache.query, vals...) 490 491 if err != nil { 492 return errors.Wrap(err, "model2: unable to insert into notification_time_span") 493 } 494 495 var identifierCols []interface{} 496 497 if len(cache.retMapping) == 0 { 498 goto CacheNoHooks 499 } 500 501 identifierCols = []interface{}{ 502 o.UserID, 503 o.Number, 504 } 505 506 if boil.IsDebug(ctx) { 507 writer := boil.DebugWriterFrom(ctx) 508 fmt.Fprintln(writer, cache.retQuery) 509 fmt.Fprintln(writer, identifierCols...) 510 } 511 err = exec.QueryRowContext(ctx, cache.retQuery, identifierCols...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...) 512 if err != nil { 513 return errors.Wrap(err, "model2: unable to populate default values for notification_time_span") 514 } 515 516 CacheNoHooks: 517 if !cached { 518 notificationTimeSpanInsertCacheMut.Lock() 519 notificationTimeSpanInsertCache[key] = cache 520 notificationTimeSpanInsertCacheMut.Unlock() 521 } 522 523 return o.doAfterInsertHooks(ctx, exec) 524 } 525 526 // Update uses an executor to update the NotificationTimeSpan. 527 // See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates. 528 // Update does not automatically update the record in case of default values. Use .Reload() to refresh the records. 529 func (o *NotificationTimeSpan) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) { 530 var err error 531 if err = o.doBeforeUpdateHooks(ctx, exec); err != nil { 532 return 0, err 533 } 534 key := makeCacheKey(columns, nil) 535 notificationTimeSpanUpdateCacheMut.RLock() 536 cache, cached := notificationTimeSpanUpdateCache[key] 537 notificationTimeSpanUpdateCacheMut.RUnlock() 538 539 if !cached { 540 wl := columns.UpdateColumnSet( 541 notificationTimeSpanAllColumns, 542 notificationTimeSpanPrimaryKeyColumns, 543 ) 544 545 if !columns.IsWhitelist() { 546 wl = strmangle.SetComplement(wl, []string{"created_at"}) 547 } 548 if len(wl) == 0 { 549 return 0, errors.New("model2: unable to update notification_time_span, could not build whitelist") 550 } 551 552 cache.query = fmt.Sprintf("UPDATE `notification_time_span` SET %s WHERE %s", 553 strmangle.SetParamNames("`", "`", 0, wl), 554 strmangle.WhereClause("`", "`", 0, notificationTimeSpanPrimaryKeyColumns), 555 ) 556 cache.valueMapping, err = queries.BindMapping(notificationTimeSpanType, notificationTimeSpanMapping, append(wl, notificationTimeSpanPrimaryKeyColumns...)) 557 if err != nil { 558 return 0, err 559 } 560 } 561 562 values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) 563 564 if boil.IsDebug(ctx) { 565 writer := boil.DebugWriterFrom(ctx) 566 fmt.Fprintln(writer, cache.query) 567 fmt.Fprintln(writer, values) 568 } 569 var result sql.Result 570 result, err = exec.ExecContext(ctx, cache.query, values...) 571 if err != nil { 572 return 0, errors.Wrap(err, "model2: unable to update notification_time_span row") 573 } 574 575 rowsAff, err := result.RowsAffected() 576 if err != nil { 577 return 0, errors.Wrap(err, "model2: failed to get rows affected by update for notification_time_span") 578 } 579 580 if !cached { 581 notificationTimeSpanUpdateCacheMut.Lock() 582 notificationTimeSpanUpdateCache[key] = cache 583 notificationTimeSpanUpdateCacheMut.Unlock() 584 } 585 586 return rowsAff, o.doAfterUpdateHooks(ctx, exec) 587 } 588 589 // UpdateAll updates all rows with the specified column values. 590 func (q notificationTimeSpanQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) { 591 queries.SetUpdate(q.Query, cols) 592 593 result, err := q.Query.ExecContext(ctx, exec) 594 if err != nil { 595 return 0, errors.Wrap(err, "model2: unable to update all for notification_time_span") 596 } 597 598 rowsAff, err := result.RowsAffected() 599 if err != nil { 600 return 0, errors.Wrap(err, "model2: unable to retrieve rows affected for notification_time_span") 601 } 602 603 return rowsAff, nil 604 } 605 606 // UpdateAll updates all rows with the specified column values, using an executor. 607 func (o NotificationTimeSpanSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) { 608 ln := int64(len(o)) 609 if ln == 0 { 610 return 0, nil 611 } 612 613 if len(cols) == 0 { 614 return 0, errors.New("model2: update all requires at least one column argument") 615 } 616 617 colNames := make([]string, len(cols)) 618 args := make([]interface{}, len(cols)) 619 620 i := 0 621 for name, value := range cols { 622 colNames[i] = name 623 args[i] = value 624 i++ 625 } 626 627 // Append all of the primary key values for each column 628 for _, obj := range o { 629 pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), notificationTimeSpanPrimaryKeyMapping) 630 args = append(args, pkeyArgs...) 631 } 632 633 sql := fmt.Sprintf("UPDATE `notification_time_span` SET %s WHERE %s", 634 strmangle.SetParamNames("`", "`", 0, colNames), 635 strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, notificationTimeSpanPrimaryKeyColumns, len(o))) 636 637 if boil.IsDebug(ctx) { 638 writer := boil.DebugWriterFrom(ctx) 639 fmt.Fprintln(writer, sql) 640 fmt.Fprintln(writer, args...) 641 } 642 result, err := exec.ExecContext(ctx, sql, args...) 643 if err != nil { 644 return 0, errors.Wrap(err, "model2: unable to update all in notificationTimeSpan slice") 645 } 646 647 rowsAff, err := result.RowsAffected() 648 if err != nil { 649 return 0, errors.Wrap(err, "model2: unable to retrieve rows affected all in update all notificationTimeSpan") 650 } 651 return rowsAff, nil 652 } 653 654 var mySQLNotificationTimeSpanUniqueColumns = []string{} 655 656 // Upsert attempts an insert using an executor, and does an update or ignore on conflict. 657 // See boil.Columns documentation for how to properly use updateColumns and insertColumns. 658 func (o *NotificationTimeSpan) Upsert(ctx context.Context, exec boil.ContextExecutor, updateColumns, insertColumns boil.Columns) error { 659 if o == nil { 660 return errors.New("model2: no notification_time_span provided for upsert") 661 } 662 if !boil.TimestampsAreSkipped(ctx) { 663 currTime := time.Now().In(boil.GetLocation()) 664 665 if o.CreatedAt.IsZero() { 666 o.CreatedAt = currTime 667 } 668 } 669 670 if err := o.doBeforeUpsertHooks(ctx, exec); err != nil { 671 return err 672 } 673 674 nzDefaults := queries.NonZeroDefaultSet(notificationTimeSpanColumnsWithDefault, o) 675 nzUniques := queries.NonZeroDefaultSet(mySQLNotificationTimeSpanUniqueColumns, o) 676 677 if len(nzUniques) == 0 { 678 return errors.New("cannot upsert with a table that cannot conflict on a unique column") 679 } 680 681 // Build cache key in-line uglily - mysql vs psql problems 682 buf := strmangle.GetBuffer() 683 buf.WriteString(strconv.Itoa(updateColumns.Kind)) 684 for _, c := range updateColumns.Cols { 685 buf.WriteString(c) 686 } 687 buf.WriteByte('.') 688 buf.WriteString(strconv.Itoa(insertColumns.Kind)) 689 for _, c := range insertColumns.Cols { 690 buf.WriteString(c) 691 } 692 buf.WriteByte('.') 693 for _, c := range nzDefaults { 694 buf.WriteString(c) 695 } 696 buf.WriteByte('.') 697 for _, c := range nzUniques { 698 buf.WriteString(c) 699 } 700 key := buf.String() 701 strmangle.PutBuffer(buf) 702 703 notificationTimeSpanUpsertCacheMut.RLock() 704 cache, cached := notificationTimeSpanUpsertCache[key] 705 notificationTimeSpanUpsertCacheMut.RUnlock() 706 707 var err error 708 709 if !cached { 710 insert, ret := insertColumns.InsertColumnSet( 711 notificationTimeSpanAllColumns, 712 notificationTimeSpanColumnsWithDefault, 713 notificationTimeSpanColumnsWithoutDefault, 714 nzDefaults, 715 ) 716 717 update := updateColumns.UpdateColumnSet( 718 notificationTimeSpanAllColumns, 719 notificationTimeSpanPrimaryKeyColumns, 720 ) 721 722 if !updateColumns.IsNone() && len(update) == 0 { 723 return errors.New("model2: unable to upsert notification_time_span, could not build update column list") 724 } 725 726 ret = strmangle.SetComplement(ret, nzUniques) 727 cache.query = buildUpsertQueryMySQL(dialect, "`notification_time_span`", update, insert) 728 cache.retQuery = fmt.Sprintf( 729 "SELECT %s FROM `notification_time_span` WHERE %s", 730 strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, ret), ","), 731 strmangle.WhereClause("`", "`", 0, nzUniques), 732 ) 733 734 cache.valueMapping, err = queries.BindMapping(notificationTimeSpanType, notificationTimeSpanMapping, insert) 735 if err != nil { 736 return err 737 } 738 if len(ret) != 0 { 739 cache.retMapping, err = queries.BindMapping(notificationTimeSpanType, notificationTimeSpanMapping, ret) 740 if err != nil { 741 return err 742 } 743 } 744 } 745 746 value := reflect.Indirect(reflect.ValueOf(o)) 747 vals := queries.ValuesFromMapping(value, cache.valueMapping) 748 var returns []interface{} 749 if len(cache.retMapping) != 0 { 750 returns = queries.PtrsFromMapping(value, cache.retMapping) 751 } 752 753 if boil.IsDebug(ctx) { 754 writer := boil.DebugWriterFrom(ctx) 755 fmt.Fprintln(writer, cache.query) 756 fmt.Fprintln(writer, vals) 757 } 758 _, err = exec.ExecContext(ctx, cache.query, vals...) 759 760 if err != nil { 761 return errors.Wrap(err, "model2: unable to upsert for notification_time_span") 762 } 763 764 var uniqueMap []uint64 765 var nzUniqueCols []interface{} 766 767 if len(cache.retMapping) == 0 { 768 goto CacheNoHooks 769 } 770 771 uniqueMap, err = queries.BindMapping(notificationTimeSpanType, notificationTimeSpanMapping, nzUniques) 772 if err != nil { 773 return errors.Wrap(err, "model2: unable to retrieve unique values for notification_time_span") 774 } 775 nzUniqueCols = queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), uniqueMap) 776 777 if boil.IsDebug(ctx) { 778 writer := boil.DebugWriterFrom(ctx) 779 fmt.Fprintln(writer, cache.retQuery) 780 fmt.Fprintln(writer, nzUniqueCols...) 781 } 782 err = exec.QueryRowContext(ctx, cache.retQuery, nzUniqueCols...).Scan(returns...) 783 if err != nil { 784 return errors.Wrap(err, "model2: unable to populate default values for notification_time_span") 785 } 786 787 CacheNoHooks: 788 if !cached { 789 notificationTimeSpanUpsertCacheMut.Lock() 790 notificationTimeSpanUpsertCache[key] = cache 791 notificationTimeSpanUpsertCacheMut.Unlock() 792 } 793 794 return o.doAfterUpsertHooks(ctx, exec) 795 } 796 797 // Delete deletes a single NotificationTimeSpan record with an executor. 798 // Delete will match against the primary key column to find the record to delete. 799 func (o *NotificationTimeSpan) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) { 800 if o == nil { 801 return 0, errors.New("model2: no NotificationTimeSpan provided for delete") 802 } 803 804 if err := o.doBeforeDeleteHooks(ctx, exec); err != nil { 805 return 0, err 806 } 807 808 args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), notificationTimeSpanPrimaryKeyMapping) 809 sql := "DELETE FROM `notification_time_span` WHERE `user_id`=? AND `number`=?" 810 811 if boil.IsDebug(ctx) { 812 writer := boil.DebugWriterFrom(ctx) 813 fmt.Fprintln(writer, sql) 814 fmt.Fprintln(writer, args...) 815 } 816 result, err := exec.ExecContext(ctx, sql, args...) 817 if err != nil { 818 return 0, errors.Wrap(err, "model2: unable to delete from notification_time_span") 819 } 820 821 rowsAff, err := result.RowsAffected() 822 if err != nil { 823 return 0, errors.Wrap(err, "model2: failed to get rows affected by delete for notification_time_span") 824 } 825 826 if err := o.doAfterDeleteHooks(ctx, exec); err != nil { 827 return 0, err 828 } 829 830 return rowsAff, nil 831 } 832 833 // DeleteAll deletes all matching rows. 834 func (q notificationTimeSpanQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { 835 if q.Query == nil { 836 return 0, errors.New("model2: no notificationTimeSpanQuery provided for delete all") 837 } 838 839 queries.SetDelete(q.Query) 840 841 result, err := q.Query.ExecContext(ctx, exec) 842 if err != nil { 843 return 0, errors.Wrap(err, "model2: unable to delete all from notification_time_span") 844 } 845 846 rowsAff, err := result.RowsAffected() 847 if err != nil { 848 return 0, errors.Wrap(err, "model2: failed to get rows affected by deleteall for notification_time_span") 849 } 850 851 return rowsAff, nil 852 } 853 854 // DeleteAll deletes all rows in the slice, using an executor. 855 func (o NotificationTimeSpanSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { 856 if len(o) == 0 { 857 return 0, nil 858 } 859 860 if len(notificationTimeSpanBeforeDeleteHooks) != 0 { 861 for _, obj := range o { 862 if err := obj.doBeforeDeleteHooks(ctx, exec); err != nil { 863 return 0, err 864 } 865 } 866 } 867 868 var args []interface{} 869 for _, obj := range o { 870 pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), notificationTimeSpanPrimaryKeyMapping) 871 args = append(args, pkeyArgs...) 872 } 873 874 sql := "DELETE FROM `notification_time_span` WHERE " + 875 strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, notificationTimeSpanPrimaryKeyColumns, len(o)) 876 877 if boil.IsDebug(ctx) { 878 writer := boil.DebugWriterFrom(ctx) 879 fmt.Fprintln(writer, sql) 880 fmt.Fprintln(writer, args) 881 } 882 result, err := exec.ExecContext(ctx, sql, args...) 883 if err != nil { 884 return 0, errors.Wrap(err, "model2: unable to delete all from notificationTimeSpan slice") 885 } 886 887 rowsAff, err := result.RowsAffected() 888 if err != nil { 889 return 0, errors.Wrap(err, "model2: failed to get rows affected by deleteall for notification_time_span") 890 } 891 892 if len(notificationTimeSpanAfterDeleteHooks) != 0 { 893 for _, obj := range o { 894 if err := obj.doAfterDeleteHooks(ctx, exec); err != nil { 895 return 0, err 896 } 897 } 898 } 899 900 return rowsAff, nil 901 } 902 903 // Reload refetches the object from the database 904 // using the primary keys with an executor. 905 func (o *NotificationTimeSpan) Reload(ctx context.Context, exec boil.ContextExecutor) error { 906 ret, err := FindNotificationTimeSpan(ctx, exec, o.UserID, o.Number) 907 if err != nil { 908 return err 909 } 910 911 *o = *ret 912 return nil 913 } 914 915 // ReloadAll refetches every row with matching primary key column values 916 // and overwrites the original object slice with the newly updated slice. 917 func (o *NotificationTimeSpanSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error { 918 if o == nil || len(*o) == 0 { 919 return nil 920 } 921 922 slice := NotificationTimeSpanSlice{} 923 var args []interface{} 924 for _, obj := range *o { 925 pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), notificationTimeSpanPrimaryKeyMapping) 926 args = append(args, pkeyArgs...) 927 } 928 929 sql := "SELECT `notification_time_span`.* FROM `notification_time_span` WHERE " + 930 strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, notificationTimeSpanPrimaryKeyColumns, len(*o)) 931 932 q := queries.Raw(sql, args...) 933 934 err := q.Bind(ctx, exec, &slice) 935 if err != nil { 936 return errors.Wrap(err, "model2: unable to reload all in NotificationTimeSpanSlice") 937 } 938 939 *o = slice 940 941 return nil 942 } 943 944 // NotificationTimeSpanExists checks if the NotificationTimeSpan row exists. 945 func NotificationTimeSpanExists(ctx context.Context, exec boil.ContextExecutor, userID uint, number uint8) (bool, error) { 946 var exists bool 947 sql := "select exists(select 1 from `notification_time_span` where `user_id`=? AND `number`=? limit 1)" 948 949 if boil.IsDebug(ctx) { 950 writer := boil.DebugWriterFrom(ctx) 951 fmt.Fprintln(writer, sql) 952 fmt.Fprintln(writer, userID, number) 953 } 954 row := exec.QueryRowContext(ctx, sql, userID, number) 955 956 err := row.Scan(&exists) 957 if err != nil { 958 return false, errors.Wrap(err, "model2: unable to check if notification_time_span exists") 959 } 960 961 return exists, nil 962 } 963 964 // Exists checks if the NotificationTimeSpan row exists. 965 func (o *NotificationTimeSpan) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { 966 return NotificationTimeSpanExists(ctx, exec, o.UserID, o.Number) 967 }