group_query.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. // Code generated by entc, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "database/sql/driver"
  6. "errors"
  7. "fmt"
  8. "math"
  9. "code.osinet.fr/fgm/entdemo/ent/group"
  10. "code.osinet.fr/fgm/entdemo/ent/predicate"
  11. "code.osinet.fr/fgm/entdemo/ent/user"
  12. "github.com/facebookincubator/ent/dialect/sql"
  13. "github.com/facebookincubator/ent/dialect/sql/sqlgraph"
  14. "github.com/facebookincubator/ent/schema/field"
  15. )
  16. // GroupQuery is the builder for querying Group entities.
  17. type GroupQuery struct {
  18. config
  19. limit *int
  20. offset *int
  21. order []Order
  22. unique []string
  23. predicates []predicate.Group
  24. // eager-loading edges.
  25. withUsers *UserQuery
  26. // intermediate query.
  27. sql *sql.Selector
  28. }
  29. // Where adds a new predicate for the builder.
  30. func (gq *GroupQuery) Where(ps ...predicate.Group) *GroupQuery {
  31. gq.predicates = append(gq.predicates, ps...)
  32. return gq
  33. }
  34. // Limit adds a limit step to the query.
  35. func (gq *GroupQuery) Limit(limit int) *GroupQuery {
  36. gq.limit = &limit
  37. return gq
  38. }
  39. // Offset adds an offset step to the query.
  40. func (gq *GroupQuery) Offset(offset int) *GroupQuery {
  41. gq.offset = &offset
  42. return gq
  43. }
  44. // Order adds an order step to the query.
  45. func (gq *GroupQuery) Order(o ...Order) *GroupQuery {
  46. gq.order = append(gq.order, o...)
  47. return gq
  48. }
  49. // QueryUsers chains the current query on the users edge.
  50. func (gq *GroupQuery) QueryUsers() *UserQuery {
  51. query := &UserQuery{config: gq.config}
  52. step := sqlgraph.NewStep(
  53. sqlgraph.From(group.Table, group.FieldID, gq.sqlQuery()),
  54. sqlgraph.To(user.Table, user.FieldID),
  55. sqlgraph.Edge(sqlgraph.M2M, false, group.UsersTable, group.UsersPrimaryKey...),
  56. )
  57. query.sql = sqlgraph.SetNeighbors(gq.driver.Dialect(), step)
  58. return query
  59. }
  60. // First returns the first Group entity in the query. Returns *NotFoundError when no group was found.
  61. func (gq *GroupQuery) First(ctx context.Context) (*Group, error) {
  62. grs, err := gq.Limit(1).All(ctx)
  63. if err != nil {
  64. return nil, err
  65. }
  66. if len(grs) == 0 {
  67. return nil, &NotFoundError{group.Label}
  68. }
  69. return grs[0], nil
  70. }
  71. // FirstX is like First, but panics if an error occurs.
  72. func (gq *GroupQuery) FirstX(ctx context.Context) *Group {
  73. gr, err := gq.First(ctx)
  74. if err != nil && !IsNotFound(err) {
  75. panic(err)
  76. }
  77. return gr
  78. }
  79. // FirstID returns the first Group id in the query. Returns *NotFoundError when no id was found.
  80. func (gq *GroupQuery) FirstID(ctx context.Context) (id int, err error) {
  81. var ids []int
  82. if ids, err = gq.Limit(1).IDs(ctx); err != nil {
  83. return
  84. }
  85. if len(ids) == 0 {
  86. err = &NotFoundError{group.Label}
  87. return
  88. }
  89. return ids[0], nil
  90. }
  91. // FirstXID is like FirstID, but panics if an error occurs.
  92. func (gq *GroupQuery) FirstXID(ctx context.Context) int {
  93. id, err := gq.FirstID(ctx)
  94. if err != nil && !IsNotFound(err) {
  95. panic(err)
  96. }
  97. return id
  98. }
  99. // Only returns the only Group entity in the query, returns an error if not exactly one entity was returned.
  100. func (gq *GroupQuery) Only(ctx context.Context) (*Group, error) {
  101. grs, err := gq.Limit(2).All(ctx)
  102. if err != nil {
  103. return nil, err
  104. }
  105. switch len(grs) {
  106. case 1:
  107. return grs[0], nil
  108. case 0:
  109. return nil, &NotFoundError{group.Label}
  110. default:
  111. return nil, &NotSingularError{group.Label}
  112. }
  113. }
  114. // OnlyX is like Only, but panics if an error occurs.
  115. func (gq *GroupQuery) OnlyX(ctx context.Context) *Group {
  116. gr, err := gq.Only(ctx)
  117. if err != nil {
  118. panic(err)
  119. }
  120. return gr
  121. }
  122. // OnlyID returns the only Group id in the query, returns an error if not exactly one id was returned.
  123. func (gq *GroupQuery) OnlyID(ctx context.Context) (id int, err error) {
  124. var ids []int
  125. if ids, err = gq.Limit(2).IDs(ctx); err != nil {
  126. return
  127. }
  128. switch len(ids) {
  129. case 1:
  130. id = ids[0]
  131. case 0:
  132. err = &NotFoundError{group.Label}
  133. default:
  134. err = &NotSingularError{group.Label}
  135. }
  136. return
  137. }
  138. // OnlyXID is like OnlyID, but panics if an error occurs.
  139. func (gq *GroupQuery) OnlyXID(ctx context.Context) int {
  140. id, err := gq.OnlyID(ctx)
  141. if err != nil {
  142. panic(err)
  143. }
  144. return id
  145. }
  146. // All executes the query and returns a list of Groups.
  147. func (gq *GroupQuery) All(ctx context.Context) ([]*Group, error) {
  148. return gq.sqlAll(ctx)
  149. }
  150. // AllX is like All, but panics if an error occurs.
  151. func (gq *GroupQuery) AllX(ctx context.Context) []*Group {
  152. grs, err := gq.All(ctx)
  153. if err != nil {
  154. panic(err)
  155. }
  156. return grs
  157. }
  158. // IDs executes the query and returns a list of Group ids.
  159. func (gq *GroupQuery) IDs(ctx context.Context) ([]int, error) {
  160. var ids []int
  161. if err := gq.Select(group.FieldID).Scan(ctx, &ids); err != nil {
  162. return nil, err
  163. }
  164. return ids, nil
  165. }
  166. // IDsX is like IDs, but panics if an error occurs.
  167. func (gq *GroupQuery) IDsX(ctx context.Context) []int {
  168. ids, err := gq.IDs(ctx)
  169. if err != nil {
  170. panic(err)
  171. }
  172. return ids
  173. }
  174. // Count returns the count of the given query.
  175. func (gq *GroupQuery) Count(ctx context.Context) (int, error) {
  176. return gq.sqlCount(ctx)
  177. }
  178. // CountX is like Count, but panics if an error occurs.
  179. func (gq *GroupQuery) CountX(ctx context.Context) int {
  180. count, err := gq.Count(ctx)
  181. if err != nil {
  182. panic(err)
  183. }
  184. return count
  185. }
  186. // Exist returns true if the query has elements in the graph.
  187. func (gq *GroupQuery) Exist(ctx context.Context) (bool, error) {
  188. return gq.sqlExist(ctx)
  189. }
  190. // ExistX is like Exist, but panics if an error occurs.
  191. func (gq *GroupQuery) ExistX(ctx context.Context) bool {
  192. exist, err := gq.Exist(ctx)
  193. if err != nil {
  194. panic(err)
  195. }
  196. return exist
  197. }
  198. // Clone returns a duplicate of the query builder, including all associated steps. It can be
  199. // used to prepare common query builders and use them differently after the clone is made.
  200. func (gq *GroupQuery) Clone() *GroupQuery {
  201. return &GroupQuery{
  202. config: gq.config,
  203. limit: gq.limit,
  204. offset: gq.offset,
  205. order: append([]Order{}, gq.order...),
  206. unique: append([]string{}, gq.unique...),
  207. predicates: append([]predicate.Group{}, gq.predicates...),
  208. // clone intermediate query.
  209. sql: gq.sql.Clone(),
  210. }
  211. }
  212. // WithUsers tells the query-builder to eager-loads the nodes that are connected to
  213. // the "users" edge. The optional arguments used to configure the query builder of the edge.
  214. func (gq *GroupQuery) WithUsers(opts ...func(*UserQuery)) *GroupQuery {
  215. query := &UserQuery{config: gq.config}
  216. for _, opt := range opts {
  217. opt(query)
  218. }
  219. gq.withUsers = query
  220. return gq
  221. }
  222. // GroupBy used to group vertices by one or more fields/columns.
  223. // It is often used with aggregate functions, like: count, max, mean, min, sum.
  224. //
  225. // Example:
  226. //
  227. // var v []struct {
  228. // Name string `json:"name,omitempty"`
  229. // Count int `json:"count,omitempty"`
  230. // }
  231. //
  232. // client.Group.Query().
  233. // GroupBy(group.FieldName).
  234. // Aggregate(ent.Count()).
  235. // Scan(ctx, &v)
  236. //
  237. func (gq *GroupQuery) GroupBy(field string, fields ...string) *GroupGroupBy {
  238. group := &GroupGroupBy{config: gq.config}
  239. group.fields = append([]string{field}, fields...)
  240. group.sql = gq.sqlQuery()
  241. return group
  242. }
  243. // Select one or more fields from the given query.
  244. //
  245. // Example:
  246. //
  247. // var v []struct {
  248. // Name string `json:"name,omitempty"`
  249. // }
  250. //
  251. // client.Group.Query().
  252. // Select(group.FieldName).
  253. // Scan(ctx, &v)
  254. //
  255. func (gq *GroupQuery) Select(field string, fields ...string) *GroupSelect {
  256. selector := &GroupSelect{config: gq.config}
  257. selector.fields = append([]string{field}, fields...)
  258. selector.sql = gq.sqlQuery()
  259. return selector
  260. }
  261. func (gq *GroupQuery) sqlAll(ctx context.Context) ([]*Group, error) {
  262. var (
  263. nodes = []*Group{}
  264. _spec = gq.querySpec()
  265. loadedTypes = [1]bool{
  266. gq.withUsers != nil,
  267. }
  268. )
  269. _spec.ScanValues = func() []interface{} {
  270. node := &Group{config: gq.config}
  271. nodes = append(nodes, node)
  272. values := node.scanValues()
  273. return values
  274. }
  275. _spec.Assign = func(values ...interface{}) error {
  276. if len(nodes) == 0 {
  277. return fmt.Errorf("ent: Assign called without calling ScanValues")
  278. }
  279. node := nodes[len(nodes)-1]
  280. node.Edges.loadedTypes = loadedTypes
  281. return node.assignValues(values...)
  282. }
  283. if err := sqlgraph.QueryNodes(ctx, gq.driver, _spec); err != nil {
  284. return nil, err
  285. }
  286. if len(nodes) == 0 {
  287. return nodes, nil
  288. }
  289. if query := gq.withUsers; query != nil {
  290. fks := make([]driver.Value, 0, len(nodes))
  291. ids := make(map[int]*Group, len(nodes))
  292. for _, node := range nodes {
  293. ids[node.ID] = node
  294. fks = append(fks, node.ID)
  295. }
  296. var (
  297. edgeids []int
  298. edges = make(map[int][]*Group)
  299. )
  300. _spec := &sqlgraph.EdgeQuerySpec{
  301. Edge: &sqlgraph.EdgeSpec{
  302. Inverse: false,
  303. Table: group.UsersTable,
  304. Columns: group.UsersPrimaryKey,
  305. },
  306. Predicate: func(s *sql.Selector) {
  307. s.Where(sql.InValues(group.UsersPrimaryKey[0], fks...))
  308. },
  309. ScanValues: func() [2]interface{} {
  310. return [2]interface{}{&sql.NullInt64{}, &sql.NullInt64{}}
  311. },
  312. Assign: func(out, in interface{}) error {
  313. eout, ok := out.(*sql.NullInt64)
  314. if !ok || eout == nil {
  315. return fmt.Errorf("unexpected id value for edge-out")
  316. }
  317. ein, ok := in.(*sql.NullInt64)
  318. if !ok || ein == nil {
  319. return fmt.Errorf("unexpected id value for edge-in")
  320. }
  321. outValue := int(eout.Int64)
  322. inValue := int(ein.Int64)
  323. node, ok := ids[outValue]
  324. if !ok {
  325. return fmt.Errorf("unexpected node id in edges: %v", outValue)
  326. }
  327. edgeids = append(edgeids, inValue)
  328. edges[inValue] = append(edges[inValue], node)
  329. return nil
  330. },
  331. }
  332. if err := sqlgraph.QueryEdges(ctx, gq.driver, _spec); err != nil {
  333. return nil, fmt.Errorf(`query edges "users": %v`, err)
  334. }
  335. query.Where(user.IDIn(edgeids...))
  336. neighbors, err := query.All(ctx)
  337. if err != nil {
  338. return nil, err
  339. }
  340. for _, n := range neighbors {
  341. nodes, ok := edges[n.ID]
  342. if !ok {
  343. return nil, fmt.Errorf(`unexpected "users" node returned %v`, n.ID)
  344. }
  345. for i := range nodes {
  346. nodes[i].Edges.Users = append(nodes[i].Edges.Users, n)
  347. }
  348. }
  349. }
  350. return nodes, nil
  351. }
  352. func (gq *GroupQuery) sqlCount(ctx context.Context) (int, error) {
  353. _spec := gq.querySpec()
  354. return sqlgraph.CountNodes(ctx, gq.driver, _spec)
  355. }
  356. func (gq *GroupQuery) sqlExist(ctx context.Context) (bool, error) {
  357. n, err := gq.sqlCount(ctx)
  358. if err != nil {
  359. return false, fmt.Errorf("ent: check existence: %v", err)
  360. }
  361. return n > 0, nil
  362. }
  363. func (gq *GroupQuery) querySpec() *sqlgraph.QuerySpec {
  364. _spec := &sqlgraph.QuerySpec{
  365. Node: &sqlgraph.NodeSpec{
  366. Table: group.Table,
  367. Columns: group.Columns,
  368. ID: &sqlgraph.FieldSpec{
  369. Type: field.TypeInt,
  370. Column: group.FieldID,
  371. },
  372. },
  373. From: gq.sql,
  374. Unique: true,
  375. }
  376. if ps := gq.predicates; len(ps) > 0 {
  377. _spec.Predicate = func(selector *sql.Selector) {
  378. for i := range ps {
  379. ps[i](selector)
  380. }
  381. }
  382. }
  383. if limit := gq.limit; limit != nil {
  384. _spec.Limit = *limit
  385. }
  386. if offset := gq.offset; offset != nil {
  387. _spec.Offset = *offset
  388. }
  389. if ps := gq.order; len(ps) > 0 {
  390. _spec.Order = func(selector *sql.Selector) {
  391. for i := range ps {
  392. ps[i](selector)
  393. }
  394. }
  395. }
  396. return _spec
  397. }
  398. func (gq *GroupQuery) sqlQuery() *sql.Selector {
  399. builder := sql.Dialect(gq.driver.Dialect())
  400. t1 := builder.Table(group.Table)
  401. selector := builder.Select(t1.Columns(group.Columns...)...).From(t1)
  402. if gq.sql != nil {
  403. selector = gq.sql
  404. selector.Select(selector.Columns(group.Columns...)...)
  405. }
  406. for _, p := range gq.predicates {
  407. p(selector)
  408. }
  409. for _, p := range gq.order {
  410. p(selector)
  411. }
  412. if offset := gq.offset; offset != nil {
  413. // limit is mandatory for offset clause. We start
  414. // with default value, and override it below if needed.
  415. selector.Offset(*offset).Limit(math.MaxInt32)
  416. }
  417. if limit := gq.limit; limit != nil {
  418. selector.Limit(*limit)
  419. }
  420. return selector
  421. }
  422. // GroupGroupBy is the builder for group-by Group entities.
  423. type GroupGroupBy struct {
  424. config
  425. fields []string
  426. fns []Aggregate
  427. // intermediate query.
  428. sql *sql.Selector
  429. }
  430. // Aggregate adds the given aggregation functions to the group-by query.
  431. func (ggb *GroupGroupBy) Aggregate(fns ...Aggregate) *GroupGroupBy {
  432. ggb.fns = append(ggb.fns, fns...)
  433. return ggb
  434. }
  435. // Scan applies the group-by query and scan the result into the given value.
  436. func (ggb *GroupGroupBy) Scan(ctx context.Context, v interface{}) error {
  437. return ggb.sqlScan(ctx, v)
  438. }
  439. // ScanX is like Scan, but panics if an error occurs.
  440. func (ggb *GroupGroupBy) ScanX(ctx context.Context, v interface{}) {
  441. if err := ggb.Scan(ctx, v); err != nil {
  442. panic(err)
  443. }
  444. }
  445. // Strings returns list of strings from group-by. It is only allowed when querying group-by with one field.
  446. func (ggb *GroupGroupBy) Strings(ctx context.Context) ([]string, error) {
  447. if len(ggb.fields) > 1 {
  448. return nil, errors.New("ent: GroupGroupBy.Strings is not achievable when grouping more than 1 field")
  449. }
  450. var v []string
  451. if err := ggb.Scan(ctx, &v); err != nil {
  452. return nil, err
  453. }
  454. return v, nil
  455. }
  456. // StringsX is like Strings, but panics if an error occurs.
  457. func (ggb *GroupGroupBy) StringsX(ctx context.Context) []string {
  458. v, err := ggb.Strings(ctx)
  459. if err != nil {
  460. panic(err)
  461. }
  462. return v
  463. }
  464. // Ints returns list of ints from group-by. It is only allowed when querying group-by with one field.
  465. func (ggb *GroupGroupBy) Ints(ctx context.Context) ([]int, error) {
  466. if len(ggb.fields) > 1 {
  467. return nil, errors.New("ent: GroupGroupBy.Ints is not achievable when grouping more than 1 field")
  468. }
  469. var v []int
  470. if err := ggb.Scan(ctx, &v); err != nil {
  471. return nil, err
  472. }
  473. return v, nil
  474. }
  475. // IntsX is like Ints, but panics if an error occurs.
  476. func (ggb *GroupGroupBy) IntsX(ctx context.Context) []int {
  477. v, err := ggb.Ints(ctx)
  478. if err != nil {
  479. panic(err)
  480. }
  481. return v
  482. }
  483. // Float64s returns list of float64s from group-by. It is only allowed when querying group-by with one field.
  484. func (ggb *GroupGroupBy) Float64s(ctx context.Context) ([]float64, error) {
  485. if len(ggb.fields) > 1 {
  486. return nil, errors.New("ent: GroupGroupBy.Float64s is not achievable when grouping more than 1 field")
  487. }
  488. var v []float64
  489. if err := ggb.Scan(ctx, &v); err != nil {
  490. return nil, err
  491. }
  492. return v, nil
  493. }
  494. // Float64sX is like Float64s, but panics if an error occurs.
  495. func (ggb *GroupGroupBy) Float64sX(ctx context.Context) []float64 {
  496. v, err := ggb.Float64s(ctx)
  497. if err != nil {
  498. panic(err)
  499. }
  500. return v
  501. }
  502. // Bools returns list of bools from group-by. It is only allowed when querying group-by with one field.
  503. func (ggb *GroupGroupBy) Bools(ctx context.Context) ([]bool, error) {
  504. if len(ggb.fields) > 1 {
  505. return nil, errors.New("ent: GroupGroupBy.Bools is not achievable when grouping more than 1 field")
  506. }
  507. var v []bool
  508. if err := ggb.Scan(ctx, &v); err != nil {
  509. return nil, err
  510. }
  511. return v, nil
  512. }
  513. // BoolsX is like Bools, but panics if an error occurs.
  514. func (ggb *GroupGroupBy) BoolsX(ctx context.Context) []bool {
  515. v, err := ggb.Bools(ctx)
  516. if err != nil {
  517. panic(err)
  518. }
  519. return v
  520. }
  521. func (ggb *GroupGroupBy) sqlScan(ctx context.Context, v interface{}) error {
  522. rows := &sql.Rows{}
  523. query, args := ggb.sqlQuery().Query()
  524. if err := ggb.driver.Query(ctx, query, args, rows); err != nil {
  525. return err
  526. }
  527. defer rows.Close()
  528. return sql.ScanSlice(rows, v)
  529. }
  530. func (ggb *GroupGroupBy) sqlQuery() *sql.Selector {
  531. selector := ggb.sql
  532. columns := make([]string, 0, len(ggb.fields)+len(ggb.fns))
  533. columns = append(columns, ggb.fields...)
  534. for _, fn := range ggb.fns {
  535. columns = append(columns, fn(selector))
  536. }
  537. return selector.Select(columns...).GroupBy(ggb.fields...)
  538. }
  539. // GroupSelect is the builder for select fields of Group entities.
  540. type GroupSelect struct {
  541. config
  542. fields []string
  543. // intermediate queries.
  544. sql *sql.Selector
  545. }
  546. // Scan applies the selector query and scan the result into the given value.
  547. func (gs *GroupSelect) Scan(ctx context.Context, v interface{}) error {
  548. return gs.sqlScan(ctx, v)
  549. }
  550. // ScanX is like Scan, but panics if an error occurs.
  551. func (gs *GroupSelect) ScanX(ctx context.Context, v interface{}) {
  552. if err := gs.Scan(ctx, v); err != nil {
  553. panic(err)
  554. }
  555. }
  556. // Strings returns list of strings from selector. It is only allowed when selecting one field.
  557. func (gs *GroupSelect) Strings(ctx context.Context) ([]string, error) {
  558. if len(gs.fields) > 1 {
  559. return nil, errors.New("ent: GroupSelect.Strings is not achievable when selecting more than 1 field")
  560. }
  561. var v []string
  562. if err := gs.Scan(ctx, &v); err != nil {
  563. return nil, err
  564. }
  565. return v, nil
  566. }
  567. // StringsX is like Strings, but panics if an error occurs.
  568. func (gs *GroupSelect) StringsX(ctx context.Context) []string {
  569. v, err := gs.Strings(ctx)
  570. if err != nil {
  571. panic(err)
  572. }
  573. return v
  574. }
  575. // Ints returns list of ints from selector. It is only allowed when selecting one field.
  576. func (gs *GroupSelect) Ints(ctx context.Context) ([]int, error) {
  577. if len(gs.fields) > 1 {
  578. return nil, errors.New("ent: GroupSelect.Ints is not achievable when selecting more than 1 field")
  579. }
  580. var v []int
  581. if err := gs.Scan(ctx, &v); err != nil {
  582. return nil, err
  583. }
  584. return v, nil
  585. }
  586. // IntsX is like Ints, but panics if an error occurs.
  587. func (gs *GroupSelect) IntsX(ctx context.Context) []int {
  588. v, err := gs.Ints(ctx)
  589. if err != nil {
  590. panic(err)
  591. }
  592. return v
  593. }
  594. // Float64s returns list of float64s from selector. It is only allowed when selecting one field.
  595. func (gs *GroupSelect) Float64s(ctx context.Context) ([]float64, error) {
  596. if len(gs.fields) > 1 {
  597. return nil, errors.New("ent: GroupSelect.Float64s is not achievable when selecting more than 1 field")
  598. }
  599. var v []float64
  600. if err := gs.Scan(ctx, &v); err != nil {
  601. return nil, err
  602. }
  603. return v, nil
  604. }
  605. // Float64sX is like Float64s, but panics if an error occurs.
  606. func (gs *GroupSelect) Float64sX(ctx context.Context) []float64 {
  607. v, err := gs.Float64s(ctx)
  608. if err != nil {
  609. panic(err)
  610. }
  611. return v
  612. }
  613. // Bools returns list of bools from selector. It is only allowed when selecting one field.
  614. func (gs *GroupSelect) Bools(ctx context.Context) ([]bool, error) {
  615. if len(gs.fields) > 1 {
  616. return nil, errors.New("ent: GroupSelect.Bools is not achievable when selecting more than 1 field")
  617. }
  618. var v []bool
  619. if err := gs.Scan(ctx, &v); err != nil {
  620. return nil, err
  621. }
  622. return v, nil
  623. }
  624. // BoolsX is like Bools, but panics if an error occurs.
  625. func (gs *GroupSelect) BoolsX(ctx context.Context) []bool {
  626. v, err := gs.Bools(ctx)
  627. if err != nil {
  628. panic(err)
  629. }
  630. return v
  631. }
  632. func (gs *GroupSelect) sqlScan(ctx context.Context, v interface{}) error {
  633. rows := &sql.Rows{}
  634. query, args := gs.sqlQuery().Query()
  635. if err := gs.driver.Query(ctx, query, args, rows); err != nil {
  636. return err
  637. }
  638. defer rows.Close()
  639. return sql.ScanSlice(rows, v)
  640. }
  641. func (gs *GroupSelect) sqlQuery() sql.Querier {
  642. selector := gs.sql
  643. selector.Select(selector.Columns(gs.fields...)...)
  644. return selector
  645. }