github.com/ngocphuongnb/tetua@v0.0.7-alpha/packages/entrepository/ent/setting_query.go (about) 1 // Code generated by entc, DO NOT EDIT. 2 3 package ent 4 5 import ( 6 "context" 7 "errors" 8 "fmt" 9 "math" 10 11 "entgo.io/ent/dialect/sql" 12 "entgo.io/ent/dialect/sql/sqlgraph" 13 "entgo.io/ent/schema/field" 14 "github.com/ngocphuongnb/tetua/packages/entrepository/ent/predicate" 15 "github.com/ngocphuongnb/tetua/packages/entrepository/ent/setting" 16 ) 17 18 // SettingQuery is the builder for querying Setting entities. 19 type SettingQuery struct { 20 config 21 limit *int 22 offset *int 23 unique *bool 24 order []OrderFunc 25 fields []string 26 predicates []predicate.Setting 27 // intermediate query (i.e. traversal path). 28 sql *sql.Selector 29 path func(context.Context) (*sql.Selector, error) 30 } 31 32 // Where adds a new predicate for the SettingQuery builder. 33 func (sq *SettingQuery) Where(ps ...predicate.Setting) *SettingQuery { 34 sq.predicates = append(sq.predicates, ps...) 35 return sq 36 } 37 38 // Limit adds a limit step to the query. 39 func (sq *SettingQuery) Limit(limit int) *SettingQuery { 40 sq.limit = &limit 41 return sq 42 } 43 44 // Offset adds an offset step to the query. 45 func (sq *SettingQuery) Offset(offset int) *SettingQuery { 46 sq.offset = &offset 47 return sq 48 } 49 50 // Unique configures the query builder to filter duplicate records on query. 51 // By default, unique is set to true, and can be disabled using this method. 52 func (sq *SettingQuery) Unique(unique bool) *SettingQuery { 53 sq.unique = &unique 54 return sq 55 } 56 57 // Order adds an order step to the query. 58 func (sq *SettingQuery) Order(o ...OrderFunc) *SettingQuery { 59 sq.order = append(sq.order, o...) 60 return sq 61 } 62 63 // First returns the first Setting entity from the query. 64 // Returns a *NotFoundError when no Setting was found. 65 func (sq *SettingQuery) First(ctx context.Context) (*Setting, error) { 66 nodes, err := sq.Limit(1).All(ctx) 67 if err != nil { 68 return nil, err 69 } 70 if len(nodes) == 0 { 71 return nil, &NotFoundError{setting.Label} 72 } 73 return nodes[0], nil 74 } 75 76 // FirstX is like First, but panics if an error occurs. 77 func (sq *SettingQuery) FirstX(ctx context.Context) *Setting { 78 node, err := sq.First(ctx) 79 if err != nil && !IsNotFound(err) { 80 panic(err) 81 } 82 return node 83 } 84 85 // FirstID returns the first Setting ID from the query. 86 // Returns a *NotFoundError when no Setting ID was found. 87 func (sq *SettingQuery) FirstID(ctx context.Context) (id int, err error) { 88 var ids []int 89 if ids, err = sq.Limit(1).IDs(ctx); err != nil { 90 return 91 } 92 if len(ids) == 0 { 93 err = &NotFoundError{setting.Label} 94 return 95 } 96 return ids[0], nil 97 } 98 99 // FirstIDX is like FirstID, but panics if an error occurs. 100 func (sq *SettingQuery) FirstIDX(ctx context.Context) int { 101 id, err := sq.FirstID(ctx) 102 if err != nil && !IsNotFound(err) { 103 panic(err) 104 } 105 return id 106 } 107 108 // Only returns a single Setting entity found by the query, ensuring it only returns one. 109 // Returns a *NotSingularError when more than one Setting entity is found. 110 // Returns a *NotFoundError when no Setting entities are found. 111 func (sq *SettingQuery) Only(ctx context.Context) (*Setting, error) { 112 nodes, err := sq.Limit(2).All(ctx) 113 if err != nil { 114 return nil, err 115 } 116 switch len(nodes) { 117 case 1: 118 return nodes[0], nil 119 case 0: 120 return nil, &NotFoundError{setting.Label} 121 default: 122 return nil, &NotSingularError{setting.Label} 123 } 124 } 125 126 // OnlyX is like Only, but panics if an error occurs. 127 func (sq *SettingQuery) OnlyX(ctx context.Context) *Setting { 128 node, err := sq.Only(ctx) 129 if err != nil { 130 panic(err) 131 } 132 return node 133 } 134 135 // OnlyID is like Only, but returns the only Setting ID in the query. 136 // Returns a *NotSingularError when more than one Setting ID is found. 137 // Returns a *NotFoundError when no entities are found. 138 func (sq *SettingQuery) OnlyID(ctx context.Context) (id int, err error) { 139 var ids []int 140 if ids, err = sq.Limit(2).IDs(ctx); err != nil { 141 return 142 } 143 switch len(ids) { 144 case 1: 145 id = ids[0] 146 case 0: 147 err = &NotFoundError{setting.Label} 148 default: 149 err = &NotSingularError{setting.Label} 150 } 151 return 152 } 153 154 // OnlyIDX is like OnlyID, but panics if an error occurs. 155 func (sq *SettingQuery) OnlyIDX(ctx context.Context) int { 156 id, err := sq.OnlyID(ctx) 157 if err != nil { 158 panic(err) 159 } 160 return id 161 } 162 163 // All executes the query and returns a list of Settings. 164 func (sq *SettingQuery) All(ctx context.Context) ([]*Setting, error) { 165 if err := sq.prepareQuery(ctx); err != nil { 166 return nil, err 167 } 168 return sq.sqlAll(ctx) 169 } 170 171 // AllX is like All, but panics if an error occurs. 172 func (sq *SettingQuery) AllX(ctx context.Context) []*Setting { 173 nodes, err := sq.All(ctx) 174 if err != nil { 175 panic(err) 176 } 177 return nodes 178 } 179 180 // IDs executes the query and returns a list of Setting IDs. 181 func (sq *SettingQuery) IDs(ctx context.Context) ([]int, error) { 182 var ids []int 183 if err := sq.Select(setting.FieldID).Scan(ctx, &ids); err != nil { 184 return nil, err 185 } 186 return ids, nil 187 } 188 189 // IDsX is like IDs, but panics if an error occurs. 190 func (sq *SettingQuery) IDsX(ctx context.Context) []int { 191 ids, err := sq.IDs(ctx) 192 if err != nil { 193 panic(err) 194 } 195 return ids 196 } 197 198 // Count returns the count of the given query. 199 func (sq *SettingQuery) Count(ctx context.Context) (int, error) { 200 if err := sq.prepareQuery(ctx); err != nil { 201 return 0, err 202 } 203 return sq.sqlCount(ctx) 204 } 205 206 // CountX is like Count, but panics if an error occurs. 207 func (sq *SettingQuery) CountX(ctx context.Context) int { 208 count, err := sq.Count(ctx) 209 if err != nil { 210 panic(err) 211 } 212 return count 213 } 214 215 // Exist returns true if the query has elements in the graph. 216 func (sq *SettingQuery) Exist(ctx context.Context) (bool, error) { 217 if err := sq.prepareQuery(ctx); err != nil { 218 return false, err 219 } 220 return sq.sqlExist(ctx) 221 } 222 223 // ExistX is like Exist, but panics if an error occurs. 224 func (sq *SettingQuery) ExistX(ctx context.Context) bool { 225 exist, err := sq.Exist(ctx) 226 if err != nil { 227 panic(err) 228 } 229 return exist 230 } 231 232 // Clone returns a duplicate of the SettingQuery builder, including all associated steps. It can be 233 // used to prepare common query builders and use them differently after the clone is made. 234 func (sq *SettingQuery) Clone() *SettingQuery { 235 if sq == nil { 236 return nil 237 } 238 return &SettingQuery{ 239 config: sq.config, 240 limit: sq.limit, 241 offset: sq.offset, 242 order: append([]OrderFunc{}, sq.order...), 243 predicates: append([]predicate.Setting{}, sq.predicates...), 244 // clone intermediate query. 245 sql: sq.sql.Clone(), 246 path: sq.path, 247 unique: sq.unique, 248 } 249 } 250 251 // GroupBy is used to group vertices by one or more fields/columns. 252 // It is often used with aggregate functions, like: count, max, mean, min, sum. 253 // 254 // Example: 255 // 256 // var v []struct { 257 // CreatedAt time.Time `json:"omitempty"` 258 // Count int `json:"count,omitempty"` 259 // } 260 // 261 // client.Setting.Query(). 262 // GroupBy(setting.FieldCreatedAt). 263 // Aggregate(ent.Count()). 264 // Scan(ctx, &v) 265 // 266 func (sq *SettingQuery) GroupBy(field string, fields ...string) *SettingGroupBy { 267 group := &SettingGroupBy{config: sq.config} 268 group.fields = append([]string{field}, fields...) 269 group.path = func(ctx context.Context) (prev *sql.Selector, err error) { 270 if err := sq.prepareQuery(ctx); err != nil { 271 return nil, err 272 } 273 return sq.sqlQuery(ctx), nil 274 } 275 return group 276 } 277 278 // Select allows the selection one or more fields/columns for the given query, 279 // instead of selecting all fields in the entity. 280 // 281 // Example: 282 // 283 // var v []struct { 284 // CreatedAt time.Time `json:"omitempty"` 285 // } 286 // 287 // client.Setting.Query(). 288 // Select(setting.FieldCreatedAt). 289 // Scan(ctx, &v) 290 // 291 func (sq *SettingQuery) Select(fields ...string) *SettingSelect { 292 sq.fields = append(sq.fields, fields...) 293 return &SettingSelect{SettingQuery: sq} 294 } 295 296 func (sq *SettingQuery) prepareQuery(ctx context.Context) error { 297 for _, f := range sq.fields { 298 if !setting.ValidColumn(f) { 299 return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} 300 } 301 } 302 if sq.path != nil { 303 prev, err := sq.path(ctx) 304 if err != nil { 305 return err 306 } 307 sq.sql = prev 308 } 309 return nil 310 } 311 312 func (sq *SettingQuery) sqlAll(ctx context.Context) ([]*Setting, error) { 313 var ( 314 nodes = []*Setting{} 315 _spec = sq.querySpec() 316 ) 317 _spec.ScanValues = func(columns []string) ([]interface{}, error) { 318 node := &Setting{config: sq.config} 319 nodes = append(nodes, node) 320 return node.scanValues(columns) 321 } 322 _spec.Assign = func(columns []string, values []interface{}) error { 323 if len(nodes) == 0 { 324 return fmt.Errorf("ent: Assign called without calling ScanValues") 325 } 326 node := nodes[len(nodes)-1] 327 return node.assignValues(columns, values) 328 } 329 if err := sqlgraph.QueryNodes(ctx, sq.driver, _spec); err != nil { 330 return nil, err 331 } 332 if len(nodes) == 0 { 333 return nodes, nil 334 } 335 return nodes, nil 336 } 337 338 func (sq *SettingQuery) sqlCount(ctx context.Context) (int, error) { 339 _spec := sq.querySpec() 340 _spec.Node.Columns = sq.fields 341 if len(sq.fields) > 0 { 342 _spec.Unique = sq.unique != nil && *sq.unique 343 } 344 return sqlgraph.CountNodes(ctx, sq.driver, _spec) 345 } 346 347 func (sq *SettingQuery) sqlExist(ctx context.Context) (bool, error) { 348 n, err := sq.sqlCount(ctx) 349 if err != nil { 350 return false, fmt.Errorf("ent: check existence: %w", err) 351 } 352 return n > 0, nil 353 } 354 355 func (sq *SettingQuery) querySpec() *sqlgraph.QuerySpec { 356 _spec := &sqlgraph.QuerySpec{ 357 Node: &sqlgraph.NodeSpec{ 358 Table: setting.Table, 359 Columns: setting.Columns, 360 ID: &sqlgraph.FieldSpec{ 361 Type: field.TypeInt, 362 Column: setting.FieldID, 363 }, 364 }, 365 From: sq.sql, 366 Unique: true, 367 } 368 if unique := sq.unique; unique != nil { 369 _spec.Unique = *unique 370 } 371 if fields := sq.fields; len(fields) > 0 { 372 _spec.Node.Columns = make([]string, 0, len(fields)) 373 _spec.Node.Columns = append(_spec.Node.Columns, setting.FieldID) 374 for i := range fields { 375 if fields[i] != setting.FieldID { 376 _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) 377 } 378 } 379 } 380 if ps := sq.predicates; len(ps) > 0 { 381 _spec.Predicate = func(selector *sql.Selector) { 382 for i := range ps { 383 ps[i](selector) 384 } 385 } 386 } 387 if limit := sq.limit; limit != nil { 388 _spec.Limit = *limit 389 } 390 if offset := sq.offset; offset != nil { 391 _spec.Offset = *offset 392 } 393 if ps := sq.order; len(ps) > 0 { 394 _spec.Order = func(selector *sql.Selector) { 395 for i := range ps { 396 ps[i](selector) 397 } 398 } 399 } 400 return _spec 401 } 402 403 func (sq *SettingQuery) sqlQuery(ctx context.Context) *sql.Selector { 404 builder := sql.Dialect(sq.driver.Dialect()) 405 t1 := builder.Table(setting.Table) 406 columns := sq.fields 407 if len(columns) == 0 { 408 columns = setting.Columns 409 } 410 selector := builder.Select(t1.Columns(columns...)...).From(t1) 411 if sq.sql != nil { 412 selector = sq.sql 413 selector.Select(selector.Columns(columns...)...) 414 } 415 if sq.unique != nil && *sq.unique { 416 selector.Distinct() 417 } 418 for _, p := range sq.predicates { 419 p(selector) 420 } 421 for _, p := range sq.order { 422 p(selector) 423 } 424 if offset := sq.offset; offset != nil { 425 // limit is mandatory for offset clause. We start 426 // with default value, and override it below if needed. 427 selector.Offset(*offset).Limit(math.MaxInt32) 428 } 429 if limit := sq.limit; limit != nil { 430 selector.Limit(*limit) 431 } 432 return selector 433 } 434 435 // SettingGroupBy is the group-by builder for Setting entities. 436 type SettingGroupBy struct { 437 config 438 fields []string 439 fns []AggregateFunc 440 // intermediate query (i.e. traversal path). 441 sql *sql.Selector 442 path func(context.Context) (*sql.Selector, error) 443 } 444 445 // Aggregate adds the given aggregation functions to the group-by query. 446 func (sgb *SettingGroupBy) Aggregate(fns ...AggregateFunc) *SettingGroupBy { 447 sgb.fns = append(sgb.fns, fns...) 448 return sgb 449 } 450 451 // Scan applies the group-by query and scans the result into the given value. 452 func (sgb *SettingGroupBy) Scan(ctx context.Context, v interface{}) error { 453 query, err := sgb.path(ctx) 454 if err != nil { 455 return err 456 } 457 sgb.sql = query 458 return sgb.sqlScan(ctx, v) 459 } 460 461 // ScanX is like Scan, but panics if an error occurs. 462 func (sgb *SettingGroupBy) ScanX(ctx context.Context, v interface{}) { 463 if err := sgb.Scan(ctx, v); err != nil { 464 panic(err) 465 } 466 } 467 468 // Strings returns list of strings from group-by. 469 // It is only allowed when executing a group-by query with one field. 470 func (sgb *SettingGroupBy) Strings(ctx context.Context) ([]string, error) { 471 if len(sgb.fields) > 1 { 472 return nil, errors.New("ent: SettingGroupBy.Strings is not achievable when grouping more than 1 field") 473 } 474 var v []string 475 if err := sgb.Scan(ctx, &v); err != nil { 476 return nil, err 477 } 478 return v, nil 479 } 480 481 // StringsX is like Strings, but panics if an error occurs. 482 func (sgb *SettingGroupBy) StringsX(ctx context.Context) []string { 483 v, err := sgb.Strings(ctx) 484 if err != nil { 485 panic(err) 486 } 487 return v 488 } 489 490 // String returns a single string from a group-by query. 491 // It is only allowed when executing a group-by query with one field. 492 func (sgb *SettingGroupBy) String(ctx context.Context) (_ string, err error) { 493 var v []string 494 if v, err = sgb.Strings(ctx); err != nil { 495 return 496 } 497 switch len(v) { 498 case 1: 499 return v[0], nil 500 case 0: 501 err = &NotFoundError{setting.Label} 502 default: 503 err = fmt.Errorf("ent: SettingGroupBy.Strings returned %d results when one was expected", len(v)) 504 } 505 return 506 } 507 508 // StringX is like String, but panics if an error occurs. 509 func (sgb *SettingGroupBy) StringX(ctx context.Context) string { 510 v, err := sgb.String(ctx) 511 if err != nil { 512 panic(err) 513 } 514 return v 515 } 516 517 // Ints returns list of ints from group-by. 518 // It is only allowed when executing a group-by query with one field. 519 func (sgb *SettingGroupBy) Ints(ctx context.Context) ([]int, error) { 520 if len(sgb.fields) > 1 { 521 return nil, errors.New("ent: SettingGroupBy.Ints is not achievable when grouping more than 1 field") 522 } 523 var v []int 524 if err := sgb.Scan(ctx, &v); err != nil { 525 return nil, err 526 } 527 return v, nil 528 } 529 530 // IntsX is like Ints, but panics if an error occurs. 531 func (sgb *SettingGroupBy) IntsX(ctx context.Context) []int { 532 v, err := sgb.Ints(ctx) 533 if err != nil { 534 panic(err) 535 } 536 return v 537 } 538 539 // Int returns a single int from a group-by query. 540 // It is only allowed when executing a group-by query with one field. 541 func (sgb *SettingGroupBy) Int(ctx context.Context) (_ int, err error) { 542 var v []int 543 if v, err = sgb.Ints(ctx); err != nil { 544 return 545 } 546 switch len(v) { 547 case 1: 548 return v[0], nil 549 case 0: 550 err = &NotFoundError{setting.Label} 551 default: 552 err = fmt.Errorf("ent: SettingGroupBy.Ints returned %d results when one was expected", len(v)) 553 } 554 return 555 } 556 557 // IntX is like Int, but panics if an error occurs. 558 func (sgb *SettingGroupBy) IntX(ctx context.Context) int { 559 v, err := sgb.Int(ctx) 560 if err != nil { 561 panic(err) 562 } 563 return v 564 } 565 566 // Float64s returns list of float64s from group-by. 567 // It is only allowed when executing a group-by query with one field. 568 func (sgb *SettingGroupBy) Float64s(ctx context.Context) ([]float64, error) { 569 if len(sgb.fields) > 1 { 570 return nil, errors.New("ent: SettingGroupBy.Float64s is not achievable when grouping more than 1 field") 571 } 572 var v []float64 573 if err := sgb.Scan(ctx, &v); err != nil { 574 return nil, err 575 } 576 return v, nil 577 } 578 579 // Float64sX is like Float64s, but panics if an error occurs. 580 func (sgb *SettingGroupBy) Float64sX(ctx context.Context) []float64 { 581 v, err := sgb.Float64s(ctx) 582 if err != nil { 583 panic(err) 584 } 585 return v 586 } 587 588 // Float64 returns a single float64 from a group-by query. 589 // It is only allowed when executing a group-by query with one field. 590 func (sgb *SettingGroupBy) Float64(ctx context.Context) (_ float64, err error) { 591 var v []float64 592 if v, err = sgb.Float64s(ctx); err != nil { 593 return 594 } 595 switch len(v) { 596 case 1: 597 return v[0], nil 598 case 0: 599 err = &NotFoundError{setting.Label} 600 default: 601 err = fmt.Errorf("ent: SettingGroupBy.Float64s returned %d results when one was expected", len(v)) 602 } 603 return 604 } 605 606 // Float64X is like Float64, but panics if an error occurs. 607 func (sgb *SettingGroupBy) Float64X(ctx context.Context) float64 { 608 v, err := sgb.Float64(ctx) 609 if err != nil { 610 panic(err) 611 } 612 return v 613 } 614 615 // Bools returns list of bools from group-by. 616 // It is only allowed when executing a group-by query with one field. 617 func (sgb *SettingGroupBy) Bools(ctx context.Context) ([]bool, error) { 618 if len(sgb.fields) > 1 { 619 return nil, errors.New("ent: SettingGroupBy.Bools is not achievable when grouping more than 1 field") 620 } 621 var v []bool 622 if err := sgb.Scan(ctx, &v); err != nil { 623 return nil, err 624 } 625 return v, nil 626 } 627 628 // BoolsX is like Bools, but panics if an error occurs. 629 func (sgb *SettingGroupBy) BoolsX(ctx context.Context) []bool { 630 v, err := sgb.Bools(ctx) 631 if err != nil { 632 panic(err) 633 } 634 return v 635 } 636 637 // Bool returns a single bool from a group-by query. 638 // It is only allowed when executing a group-by query with one field. 639 func (sgb *SettingGroupBy) Bool(ctx context.Context) (_ bool, err error) { 640 var v []bool 641 if v, err = sgb.Bools(ctx); err != nil { 642 return 643 } 644 switch len(v) { 645 case 1: 646 return v[0], nil 647 case 0: 648 err = &NotFoundError{setting.Label} 649 default: 650 err = fmt.Errorf("ent: SettingGroupBy.Bools returned %d results when one was expected", len(v)) 651 } 652 return 653 } 654 655 // BoolX is like Bool, but panics if an error occurs. 656 func (sgb *SettingGroupBy) BoolX(ctx context.Context) bool { 657 v, err := sgb.Bool(ctx) 658 if err != nil { 659 panic(err) 660 } 661 return v 662 } 663 664 func (sgb *SettingGroupBy) sqlScan(ctx context.Context, v interface{}) error { 665 for _, f := range sgb.fields { 666 if !setting.ValidColumn(f) { 667 return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} 668 } 669 } 670 selector := sgb.sqlQuery() 671 if err := selector.Err(); err != nil { 672 return err 673 } 674 rows := &sql.Rows{} 675 query, args := selector.Query() 676 if err := sgb.driver.Query(ctx, query, args, rows); err != nil { 677 return err 678 } 679 defer rows.Close() 680 return sql.ScanSlice(rows, v) 681 } 682 683 func (sgb *SettingGroupBy) sqlQuery() *sql.Selector { 684 selector := sgb.sql.Select() 685 aggregation := make([]string, 0, len(sgb.fns)) 686 for _, fn := range sgb.fns { 687 aggregation = append(aggregation, fn(selector)) 688 } 689 // If no columns were selected in a custom aggregation function, the default 690 // selection is the fields used for "group-by", and the aggregation functions. 691 if len(selector.SelectedColumns()) == 0 { 692 columns := make([]string, 0, len(sgb.fields)+len(sgb.fns)) 693 for _, f := range sgb.fields { 694 columns = append(columns, selector.C(f)) 695 } 696 columns = append(columns, aggregation...) 697 selector.Select(columns...) 698 } 699 return selector.GroupBy(selector.Columns(sgb.fields...)...) 700 } 701 702 // SettingSelect is the builder for selecting fields of Setting entities. 703 type SettingSelect struct { 704 *SettingQuery 705 // intermediate query (i.e. traversal path). 706 sql *sql.Selector 707 } 708 709 // Scan applies the selector query and scans the result into the given value. 710 func (ss *SettingSelect) Scan(ctx context.Context, v interface{}) error { 711 if err := ss.prepareQuery(ctx); err != nil { 712 return err 713 } 714 ss.sql = ss.SettingQuery.sqlQuery(ctx) 715 return ss.sqlScan(ctx, v) 716 } 717 718 // ScanX is like Scan, but panics if an error occurs. 719 func (ss *SettingSelect) ScanX(ctx context.Context, v interface{}) { 720 if err := ss.Scan(ctx, v); err != nil { 721 panic(err) 722 } 723 } 724 725 // Strings returns list of strings from a selector. It is only allowed when selecting one field. 726 func (ss *SettingSelect) Strings(ctx context.Context) ([]string, error) { 727 if len(ss.fields) > 1 { 728 return nil, errors.New("ent: SettingSelect.Strings is not achievable when selecting more than 1 field") 729 } 730 var v []string 731 if err := ss.Scan(ctx, &v); err != nil { 732 return nil, err 733 } 734 return v, nil 735 } 736 737 // StringsX is like Strings, but panics if an error occurs. 738 func (ss *SettingSelect) StringsX(ctx context.Context) []string { 739 v, err := ss.Strings(ctx) 740 if err != nil { 741 panic(err) 742 } 743 return v 744 } 745 746 // String returns a single string from a selector. It is only allowed when selecting one field. 747 func (ss *SettingSelect) String(ctx context.Context) (_ string, err error) { 748 var v []string 749 if v, err = ss.Strings(ctx); err != nil { 750 return 751 } 752 switch len(v) { 753 case 1: 754 return v[0], nil 755 case 0: 756 err = &NotFoundError{setting.Label} 757 default: 758 err = fmt.Errorf("ent: SettingSelect.Strings returned %d results when one was expected", len(v)) 759 } 760 return 761 } 762 763 // StringX is like String, but panics if an error occurs. 764 func (ss *SettingSelect) StringX(ctx context.Context) string { 765 v, err := ss.String(ctx) 766 if err != nil { 767 panic(err) 768 } 769 return v 770 } 771 772 // Ints returns list of ints from a selector. It is only allowed when selecting one field. 773 func (ss *SettingSelect) Ints(ctx context.Context) ([]int, error) { 774 if len(ss.fields) > 1 { 775 return nil, errors.New("ent: SettingSelect.Ints is not achievable when selecting more than 1 field") 776 } 777 var v []int 778 if err := ss.Scan(ctx, &v); err != nil { 779 return nil, err 780 } 781 return v, nil 782 } 783 784 // IntsX is like Ints, but panics if an error occurs. 785 func (ss *SettingSelect) IntsX(ctx context.Context) []int { 786 v, err := ss.Ints(ctx) 787 if err != nil { 788 panic(err) 789 } 790 return v 791 } 792 793 // Int returns a single int from a selector. It is only allowed when selecting one field. 794 func (ss *SettingSelect) Int(ctx context.Context) (_ int, err error) { 795 var v []int 796 if v, err = ss.Ints(ctx); err != nil { 797 return 798 } 799 switch len(v) { 800 case 1: 801 return v[0], nil 802 case 0: 803 err = &NotFoundError{setting.Label} 804 default: 805 err = fmt.Errorf("ent: SettingSelect.Ints returned %d results when one was expected", len(v)) 806 } 807 return 808 } 809 810 // IntX is like Int, but panics if an error occurs. 811 func (ss *SettingSelect) IntX(ctx context.Context) int { 812 v, err := ss.Int(ctx) 813 if err != nil { 814 panic(err) 815 } 816 return v 817 } 818 819 // Float64s returns list of float64s from a selector. It is only allowed when selecting one field. 820 func (ss *SettingSelect) Float64s(ctx context.Context) ([]float64, error) { 821 if len(ss.fields) > 1 { 822 return nil, errors.New("ent: SettingSelect.Float64s is not achievable when selecting more than 1 field") 823 } 824 var v []float64 825 if err := ss.Scan(ctx, &v); err != nil { 826 return nil, err 827 } 828 return v, nil 829 } 830 831 // Float64sX is like Float64s, but panics if an error occurs. 832 func (ss *SettingSelect) Float64sX(ctx context.Context) []float64 { 833 v, err := ss.Float64s(ctx) 834 if err != nil { 835 panic(err) 836 } 837 return v 838 } 839 840 // Float64 returns a single float64 from a selector. It is only allowed when selecting one field. 841 func (ss *SettingSelect) Float64(ctx context.Context) (_ float64, err error) { 842 var v []float64 843 if v, err = ss.Float64s(ctx); err != nil { 844 return 845 } 846 switch len(v) { 847 case 1: 848 return v[0], nil 849 case 0: 850 err = &NotFoundError{setting.Label} 851 default: 852 err = fmt.Errorf("ent: SettingSelect.Float64s returned %d results when one was expected", len(v)) 853 } 854 return 855 } 856 857 // Float64X is like Float64, but panics if an error occurs. 858 func (ss *SettingSelect) Float64X(ctx context.Context) float64 { 859 v, err := ss.Float64(ctx) 860 if err != nil { 861 panic(err) 862 } 863 return v 864 } 865 866 // Bools returns list of bools from a selector. It is only allowed when selecting one field. 867 func (ss *SettingSelect) Bools(ctx context.Context) ([]bool, error) { 868 if len(ss.fields) > 1 { 869 return nil, errors.New("ent: SettingSelect.Bools is not achievable when selecting more than 1 field") 870 } 871 var v []bool 872 if err := ss.Scan(ctx, &v); err != nil { 873 return nil, err 874 } 875 return v, nil 876 } 877 878 // BoolsX is like Bools, but panics if an error occurs. 879 func (ss *SettingSelect) BoolsX(ctx context.Context) []bool { 880 v, err := ss.Bools(ctx) 881 if err != nil { 882 panic(err) 883 } 884 return v 885 } 886 887 // Bool returns a single bool from a selector. It is only allowed when selecting one field. 888 func (ss *SettingSelect) Bool(ctx context.Context) (_ bool, err error) { 889 var v []bool 890 if v, err = ss.Bools(ctx); err != nil { 891 return 892 } 893 switch len(v) { 894 case 1: 895 return v[0], nil 896 case 0: 897 err = &NotFoundError{setting.Label} 898 default: 899 err = fmt.Errorf("ent: SettingSelect.Bools returned %d results when one was expected", len(v)) 900 } 901 return 902 } 903 904 // BoolX is like Bool, but panics if an error occurs. 905 func (ss *SettingSelect) BoolX(ctx context.Context) bool { 906 v, err := ss.Bool(ctx) 907 if err != nil { 908 panic(err) 909 } 910 return v 911 } 912 913 func (ss *SettingSelect) sqlScan(ctx context.Context, v interface{}) error { 914 rows := &sql.Rows{} 915 query, args := ss.sql.Query() 916 if err := ss.driver.Query(ctx, query, args, rows); err != nil { 917 return err 918 } 919 defer rows.Close() 920 return sql.ScanSlice(rows, v) 921 }