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