accountgroup_query.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "fmt"
  6. "math"
  7. "entgo.io/ent"
  8. "entgo.io/ent/dialect"
  9. "entgo.io/ent/dialect/sql"
  10. "entgo.io/ent/dialect/sql/sqlgraph"
  11. "github.com/Wei-Shaw/sub2api/ent/account"
  12. "github.com/Wei-Shaw/sub2api/ent/accountgroup"
  13. "github.com/Wei-Shaw/sub2api/ent/group"
  14. "github.com/Wei-Shaw/sub2api/ent/predicate"
  15. )
  16. // AccountGroupQuery is the builder for querying AccountGroup entities.
  17. type AccountGroupQuery struct {
  18. config
  19. ctx *QueryContext
  20. order []accountgroup.OrderOption
  21. inters []Interceptor
  22. predicates []predicate.AccountGroup
  23. withAccount *AccountQuery
  24. withGroup *GroupQuery
  25. modifiers []func(*sql.Selector)
  26. // intermediate query (i.e. traversal path).
  27. sql *sql.Selector
  28. path func(context.Context) (*sql.Selector, error)
  29. }
  30. // Where adds a new predicate for the AccountGroupQuery builder.
  31. func (_q *AccountGroupQuery) Where(ps ...predicate.AccountGroup) *AccountGroupQuery {
  32. _q.predicates = append(_q.predicates, ps...)
  33. return _q
  34. }
  35. // Limit the number of records to be returned by this query.
  36. func (_q *AccountGroupQuery) Limit(limit int) *AccountGroupQuery {
  37. _q.ctx.Limit = &limit
  38. return _q
  39. }
  40. // Offset to start from.
  41. func (_q *AccountGroupQuery) Offset(offset int) *AccountGroupQuery {
  42. _q.ctx.Offset = &offset
  43. return _q
  44. }
  45. // Unique configures the query builder to filter duplicate records on query.
  46. // By default, unique is set to true, and can be disabled using this method.
  47. func (_q *AccountGroupQuery) Unique(unique bool) *AccountGroupQuery {
  48. _q.ctx.Unique = &unique
  49. return _q
  50. }
  51. // Order specifies how the records should be ordered.
  52. func (_q *AccountGroupQuery) Order(o ...accountgroup.OrderOption) *AccountGroupQuery {
  53. _q.order = append(_q.order, o...)
  54. return _q
  55. }
  56. // QueryAccount chains the current query on the "account" edge.
  57. func (_q *AccountGroupQuery) QueryAccount() *AccountQuery {
  58. query := (&AccountClient{config: _q.config}).Query()
  59. query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
  60. if err := _q.prepareQuery(ctx); err != nil {
  61. return nil, err
  62. }
  63. selector := _q.sqlQuery(ctx)
  64. if err := selector.Err(); err != nil {
  65. return nil, err
  66. }
  67. step := sqlgraph.NewStep(
  68. sqlgraph.From(accountgroup.Table, accountgroup.AccountColumn, selector),
  69. sqlgraph.To(account.Table, account.FieldID),
  70. sqlgraph.Edge(sqlgraph.M2O, false, accountgroup.AccountTable, accountgroup.AccountColumn),
  71. )
  72. fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
  73. return fromU, nil
  74. }
  75. return query
  76. }
  77. // QueryGroup chains the current query on the "group" edge.
  78. func (_q *AccountGroupQuery) QueryGroup() *GroupQuery {
  79. query := (&GroupClient{config: _q.config}).Query()
  80. query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
  81. if err := _q.prepareQuery(ctx); err != nil {
  82. return nil, err
  83. }
  84. selector := _q.sqlQuery(ctx)
  85. if err := selector.Err(); err != nil {
  86. return nil, err
  87. }
  88. step := sqlgraph.NewStep(
  89. sqlgraph.From(accountgroup.Table, accountgroup.GroupColumn, selector),
  90. sqlgraph.To(group.Table, group.FieldID),
  91. sqlgraph.Edge(sqlgraph.M2O, false, accountgroup.GroupTable, accountgroup.GroupColumn),
  92. )
  93. fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
  94. return fromU, nil
  95. }
  96. return query
  97. }
  98. // First returns the first AccountGroup entity from the query.
  99. // Returns a *NotFoundError when no AccountGroup was found.
  100. func (_q *AccountGroupQuery) First(ctx context.Context) (*AccountGroup, error) {
  101. nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
  102. if err != nil {
  103. return nil, err
  104. }
  105. if len(nodes) == 0 {
  106. return nil, &NotFoundError{accountgroup.Label}
  107. }
  108. return nodes[0], nil
  109. }
  110. // FirstX is like First, but panics if an error occurs.
  111. func (_q *AccountGroupQuery) FirstX(ctx context.Context) *AccountGroup {
  112. node, err := _q.First(ctx)
  113. if err != nil && !IsNotFound(err) {
  114. panic(err)
  115. }
  116. return node
  117. }
  118. // Only returns a single AccountGroup entity found by the query, ensuring it only returns one.
  119. // Returns a *NotSingularError when more than one AccountGroup entity is found.
  120. // Returns a *NotFoundError when no AccountGroup entities are found.
  121. func (_q *AccountGroupQuery) Only(ctx context.Context) (*AccountGroup, error) {
  122. nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
  123. if err != nil {
  124. return nil, err
  125. }
  126. switch len(nodes) {
  127. case 1:
  128. return nodes[0], nil
  129. case 0:
  130. return nil, &NotFoundError{accountgroup.Label}
  131. default:
  132. return nil, &NotSingularError{accountgroup.Label}
  133. }
  134. }
  135. // OnlyX is like Only, but panics if an error occurs.
  136. func (_q *AccountGroupQuery) OnlyX(ctx context.Context) *AccountGroup {
  137. node, err := _q.Only(ctx)
  138. if err != nil {
  139. panic(err)
  140. }
  141. return node
  142. }
  143. // All executes the query and returns a list of AccountGroups.
  144. func (_q *AccountGroupQuery) All(ctx context.Context) ([]*AccountGroup, error) {
  145. ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
  146. if err := _q.prepareQuery(ctx); err != nil {
  147. return nil, err
  148. }
  149. qr := querierAll[[]*AccountGroup, *AccountGroupQuery]()
  150. return withInterceptors[[]*AccountGroup](ctx, _q, qr, _q.inters)
  151. }
  152. // AllX is like All, but panics if an error occurs.
  153. func (_q *AccountGroupQuery) AllX(ctx context.Context) []*AccountGroup {
  154. nodes, err := _q.All(ctx)
  155. if err != nil {
  156. panic(err)
  157. }
  158. return nodes
  159. }
  160. // Count returns the count of the given query.
  161. func (_q *AccountGroupQuery) Count(ctx context.Context) (int, error) {
  162. ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
  163. if err := _q.prepareQuery(ctx); err != nil {
  164. return 0, err
  165. }
  166. return withInterceptors[int](ctx, _q, querierCount[*AccountGroupQuery](), _q.inters)
  167. }
  168. // CountX is like Count, but panics if an error occurs.
  169. func (_q *AccountGroupQuery) CountX(ctx context.Context) int {
  170. count, err := _q.Count(ctx)
  171. if err != nil {
  172. panic(err)
  173. }
  174. return count
  175. }
  176. // Exist returns true if the query has elements in the graph.
  177. func (_q *AccountGroupQuery) Exist(ctx context.Context) (bool, error) {
  178. ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
  179. switch _, err := _q.First(ctx); {
  180. case IsNotFound(err):
  181. return false, nil
  182. case err != nil:
  183. return false, fmt.Errorf("ent: check existence: %w", err)
  184. default:
  185. return true, nil
  186. }
  187. }
  188. // ExistX is like Exist, but panics if an error occurs.
  189. func (_q *AccountGroupQuery) ExistX(ctx context.Context) bool {
  190. exist, err := _q.Exist(ctx)
  191. if err != nil {
  192. panic(err)
  193. }
  194. return exist
  195. }
  196. // Clone returns a duplicate of the AccountGroupQuery builder, including all associated steps. It can be
  197. // used to prepare common query builders and use them differently after the clone is made.
  198. func (_q *AccountGroupQuery) Clone() *AccountGroupQuery {
  199. if _q == nil {
  200. return nil
  201. }
  202. return &AccountGroupQuery{
  203. config: _q.config,
  204. ctx: _q.ctx.Clone(),
  205. order: append([]accountgroup.OrderOption{}, _q.order...),
  206. inters: append([]Interceptor{}, _q.inters...),
  207. predicates: append([]predicate.AccountGroup{}, _q.predicates...),
  208. withAccount: _q.withAccount.Clone(),
  209. withGroup: _q.withGroup.Clone(),
  210. // clone intermediate query.
  211. sql: _q.sql.Clone(),
  212. path: _q.path,
  213. }
  214. }
  215. // WithAccount tells the query-builder to eager-load the nodes that are connected to
  216. // the "account" edge. The optional arguments are used to configure the query builder of the edge.
  217. func (_q *AccountGroupQuery) WithAccount(opts ...func(*AccountQuery)) *AccountGroupQuery {
  218. query := (&AccountClient{config: _q.config}).Query()
  219. for _, opt := range opts {
  220. opt(query)
  221. }
  222. _q.withAccount = query
  223. return _q
  224. }
  225. // WithGroup tells the query-builder to eager-load the nodes that are connected to
  226. // the "group" edge. The optional arguments are used to configure the query builder of the edge.
  227. func (_q *AccountGroupQuery) WithGroup(opts ...func(*GroupQuery)) *AccountGroupQuery {
  228. query := (&GroupClient{config: _q.config}).Query()
  229. for _, opt := range opts {
  230. opt(query)
  231. }
  232. _q.withGroup = query
  233. return _q
  234. }
  235. // GroupBy is used to group vertices by one or more fields/columns.
  236. // It is often used with aggregate functions, like: count, max, mean, min, sum.
  237. //
  238. // Example:
  239. //
  240. // var v []struct {
  241. // AccountID int64 `json:"account_id,omitempty"`
  242. // Count int `json:"count,omitempty"`
  243. // }
  244. //
  245. // client.AccountGroup.Query().
  246. // GroupBy(accountgroup.FieldAccountID).
  247. // Aggregate(ent.Count()).
  248. // Scan(ctx, &v)
  249. func (_q *AccountGroupQuery) GroupBy(field string, fields ...string) *AccountGroupGroupBy {
  250. _q.ctx.Fields = append([]string{field}, fields...)
  251. grbuild := &AccountGroupGroupBy{build: _q}
  252. grbuild.flds = &_q.ctx.Fields
  253. grbuild.label = accountgroup.Label
  254. grbuild.scan = grbuild.Scan
  255. return grbuild
  256. }
  257. // Select allows the selection one or more fields/columns for the given query,
  258. // instead of selecting all fields in the entity.
  259. //
  260. // Example:
  261. //
  262. // var v []struct {
  263. // AccountID int64 `json:"account_id,omitempty"`
  264. // }
  265. //
  266. // client.AccountGroup.Query().
  267. // Select(accountgroup.FieldAccountID).
  268. // Scan(ctx, &v)
  269. func (_q *AccountGroupQuery) Select(fields ...string) *AccountGroupSelect {
  270. _q.ctx.Fields = append(_q.ctx.Fields, fields...)
  271. sbuild := &AccountGroupSelect{AccountGroupQuery: _q}
  272. sbuild.label = accountgroup.Label
  273. sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
  274. return sbuild
  275. }
  276. // Aggregate returns a AccountGroupSelect configured with the given aggregations.
  277. func (_q *AccountGroupQuery) Aggregate(fns ...AggregateFunc) *AccountGroupSelect {
  278. return _q.Select().Aggregate(fns...)
  279. }
  280. func (_q *AccountGroupQuery) prepareQuery(ctx context.Context) error {
  281. for _, inter := range _q.inters {
  282. if inter == nil {
  283. return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
  284. }
  285. if trv, ok := inter.(Traverser); ok {
  286. if err := trv.Traverse(ctx, _q); err != nil {
  287. return err
  288. }
  289. }
  290. }
  291. for _, f := range _q.ctx.Fields {
  292. if !accountgroup.ValidColumn(f) {
  293. return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  294. }
  295. }
  296. if _q.path != nil {
  297. prev, err := _q.path(ctx)
  298. if err != nil {
  299. return err
  300. }
  301. _q.sql = prev
  302. }
  303. return nil
  304. }
  305. func (_q *AccountGroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*AccountGroup, error) {
  306. var (
  307. nodes = []*AccountGroup{}
  308. _spec = _q.querySpec()
  309. loadedTypes = [2]bool{
  310. _q.withAccount != nil,
  311. _q.withGroup != nil,
  312. }
  313. )
  314. _spec.ScanValues = func(columns []string) ([]any, error) {
  315. return (*AccountGroup).scanValues(nil, columns)
  316. }
  317. _spec.Assign = func(columns []string, values []any) error {
  318. node := &AccountGroup{config: _q.config}
  319. nodes = append(nodes, node)
  320. node.Edges.loadedTypes = loadedTypes
  321. return node.assignValues(columns, values)
  322. }
  323. if len(_q.modifiers) > 0 {
  324. _spec.Modifiers = _q.modifiers
  325. }
  326. for i := range hooks {
  327. hooks[i](ctx, _spec)
  328. }
  329. if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
  330. return nil, err
  331. }
  332. if len(nodes) == 0 {
  333. return nodes, nil
  334. }
  335. if query := _q.withAccount; query != nil {
  336. if err := _q.loadAccount(ctx, query, nodes, nil,
  337. func(n *AccountGroup, e *Account) { n.Edges.Account = e }); err != nil {
  338. return nil, err
  339. }
  340. }
  341. if query := _q.withGroup; query != nil {
  342. if err := _q.loadGroup(ctx, query, nodes, nil,
  343. func(n *AccountGroup, e *Group) { n.Edges.Group = e }); err != nil {
  344. return nil, err
  345. }
  346. }
  347. return nodes, nil
  348. }
  349. func (_q *AccountGroupQuery) loadAccount(ctx context.Context, query *AccountQuery, nodes []*AccountGroup, init func(*AccountGroup), assign func(*AccountGroup, *Account)) error {
  350. ids := make([]int64, 0, len(nodes))
  351. nodeids := make(map[int64][]*AccountGroup)
  352. for i := range nodes {
  353. fk := nodes[i].AccountID
  354. if _, ok := nodeids[fk]; !ok {
  355. ids = append(ids, fk)
  356. }
  357. nodeids[fk] = append(nodeids[fk], nodes[i])
  358. }
  359. if len(ids) == 0 {
  360. return nil
  361. }
  362. query.Where(account.IDIn(ids...))
  363. neighbors, err := query.All(ctx)
  364. if err != nil {
  365. return err
  366. }
  367. for _, n := range neighbors {
  368. nodes, ok := nodeids[n.ID]
  369. if !ok {
  370. return fmt.Errorf(`unexpected foreign-key "account_id" returned %v`, n.ID)
  371. }
  372. for i := range nodes {
  373. assign(nodes[i], n)
  374. }
  375. }
  376. return nil
  377. }
  378. func (_q *AccountGroupQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes []*AccountGroup, init func(*AccountGroup), assign func(*AccountGroup, *Group)) error {
  379. ids := make([]int64, 0, len(nodes))
  380. nodeids := make(map[int64][]*AccountGroup)
  381. for i := range nodes {
  382. fk := nodes[i].GroupID
  383. if _, ok := nodeids[fk]; !ok {
  384. ids = append(ids, fk)
  385. }
  386. nodeids[fk] = append(nodeids[fk], nodes[i])
  387. }
  388. if len(ids) == 0 {
  389. return nil
  390. }
  391. query.Where(group.IDIn(ids...))
  392. neighbors, err := query.All(ctx)
  393. if err != nil {
  394. return err
  395. }
  396. for _, n := range neighbors {
  397. nodes, ok := nodeids[n.ID]
  398. if !ok {
  399. return fmt.Errorf(`unexpected foreign-key "group_id" returned %v`, n.ID)
  400. }
  401. for i := range nodes {
  402. assign(nodes[i], n)
  403. }
  404. }
  405. return nil
  406. }
  407. func (_q *AccountGroupQuery) sqlCount(ctx context.Context) (int, error) {
  408. _spec := _q.querySpec()
  409. if len(_q.modifiers) > 0 {
  410. _spec.Modifiers = _q.modifiers
  411. }
  412. _spec.Unique = false
  413. _spec.Node.Columns = nil
  414. return sqlgraph.CountNodes(ctx, _q.driver, _spec)
  415. }
  416. func (_q *AccountGroupQuery) querySpec() *sqlgraph.QuerySpec {
  417. _spec := sqlgraph.NewQuerySpec(accountgroup.Table, accountgroup.Columns, nil)
  418. _spec.From = _q.sql
  419. if unique := _q.ctx.Unique; unique != nil {
  420. _spec.Unique = *unique
  421. } else if _q.path != nil {
  422. _spec.Unique = true
  423. }
  424. if fields := _q.ctx.Fields; len(fields) > 0 {
  425. _spec.Node.Columns = make([]string, 0, len(fields))
  426. for i := range fields {
  427. _spec.Node.Columns = append(_spec.Node.Columns, fields[i])
  428. }
  429. if _q.withAccount != nil {
  430. _spec.Node.AddColumnOnce(accountgroup.FieldAccountID)
  431. }
  432. if _q.withGroup != nil {
  433. _spec.Node.AddColumnOnce(accountgroup.FieldGroupID)
  434. }
  435. }
  436. if ps := _q.predicates; len(ps) > 0 {
  437. _spec.Predicate = func(selector *sql.Selector) {
  438. for i := range ps {
  439. ps[i](selector)
  440. }
  441. }
  442. }
  443. if limit := _q.ctx.Limit; limit != nil {
  444. _spec.Limit = *limit
  445. }
  446. if offset := _q.ctx.Offset; offset != nil {
  447. _spec.Offset = *offset
  448. }
  449. if ps := _q.order; len(ps) > 0 {
  450. _spec.Order = func(selector *sql.Selector) {
  451. for i := range ps {
  452. ps[i](selector)
  453. }
  454. }
  455. }
  456. return _spec
  457. }
  458. func (_q *AccountGroupQuery) sqlQuery(ctx context.Context) *sql.Selector {
  459. builder := sql.Dialect(_q.driver.Dialect())
  460. t1 := builder.Table(accountgroup.Table)
  461. columns := _q.ctx.Fields
  462. if len(columns) == 0 {
  463. columns = accountgroup.Columns
  464. }
  465. selector := builder.Select(t1.Columns(columns...)...).From(t1)
  466. if _q.sql != nil {
  467. selector = _q.sql
  468. selector.Select(selector.Columns(columns...)...)
  469. }
  470. if _q.ctx.Unique != nil && *_q.ctx.Unique {
  471. selector.Distinct()
  472. }
  473. for _, m := range _q.modifiers {
  474. m(selector)
  475. }
  476. for _, p := range _q.predicates {
  477. p(selector)
  478. }
  479. for _, p := range _q.order {
  480. p(selector)
  481. }
  482. if offset := _q.ctx.Offset; offset != nil {
  483. // limit is mandatory for offset clause. We start
  484. // with default value, and override it below if needed.
  485. selector.Offset(*offset).Limit(math.MaxInt32)
  486. }
  487. if limit := _q.ctx.Limit; limit != nil {
  488. selector.Limit(*limit)
  489. }
  490. return selector
  491. }
  492. // ForUpdate locks the selected rows against concurrent updates, and prevent them from being
  493. // updated, deleted or "selected ... for update" by other sessions, until the transaction is
  494. // either committed or rolled-back.
  495. func (_q *AccountGroupQuery) ForUpdate(opts ...sql.LockOption) *AccountGroupQuery {
  496. if _q.driver.Dialect() == dialect.Postgres {
  497. _q.Unique(false)
  498. }
  499. _q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
  500. s.ForUpdate(opts...)
  501. })
  502. return _q
  503. }
  504. // ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
  505. // on any rows that are read. Other sessions can read the rows, but cannot modify them
  506. // until your transaction commits.
  507. func (_q *AccountGroupQuery) ForShare(opts ...sql.LockOption) *AccountGroupQuery {
  508. if _q.driver.Dialect() == dialect.Postgres {
  509. _q.Unique(false)
  510. }
  511. _q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
  512. s.ForShare(opts...)
  513. })
  514. return _q
  515. }
  516. // AccountGroupGroupBy is the group-by builder for AccountGroup entities.
  517. type AccountGroupGroupBy struct {
  518. selector
  519. build *AccountGroupQuery
  520. }
  521. // Aggregate adds the given aggregation functions to the group-by query.
  522. func (_g *AccountGroupGroupBy) Aggregate(fns ...AggregateFunc) *AccountGroupGroupBy {
  523. _g.fns = append(_g.fns, fns...)
  524. return _g
  525. }
  526. // Scan applies the selector query and scans the result into the given value.
  527. func (_g *AccountGroupGroupBy) Scan(ctx context.Context, v any) error {
  528. ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
  529. if err := _g.build.prepareQuery(ctx); err != nil {
  530. return err
  531. }
  532. return scanWithInterceptors[*AccountGroupQuery, *AccountGroupGroupBy](ctx, _g.build, _g, _g.build.inters, v)
  533. }
  534. func (_g *AccountGroupGroupBy) sqlScan(ctx context.Context, root *AccountGroupQuery, v any) error {
  535. selector := root.sqlQuery(ctx).Select()
  536. aggregation := make([]string, 0, len(_g.fns))
  537. for _, fn := range _g.fns {
  538. aggregation = append(aggregation, fn(selector))
  539. }
  540. if len(selector.SelectedColumns()) == 0 {
  541. columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
  542. for _, f := range *_g.flds {
  543. columns = append(columns, selector.C(f))
  544. }
  545. columns = append(columns, aggregation...)
  546. selector.Select(columns...)
  547. }
  548. selector.GroupBy(selector.Columns(*_g.flds...)...)
  549. if err := selector.Err(); err != nil {
  550. return err
  551. }
  552. rows := &sql.Rows{}
  553. query, args := selector.Query()
  554. if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
  555. return err
  556. }
  557. defer rows.Close()
  558. return sql.ScanSlice(rows, v)
  559. }
  560. // AccountGroupSelect is the builder for selecting fields of AccountGroup entities.
  561. type AccountGroupSelect struct {
  562. *AccountGroupQuery
  563. selector
  564. }
  565. // Aggregate adds the given aggregation functions to the selector query.
  566. func (_s *AccountGroupSelect) Aggregate(fns ...AggregateFunc) *AccountGroupSelect {
  567. _s.fns = append(_s.fns, fns...)
  568. return _s
  569. }
  570. // Scan applies the selector query and scans the result into the given value.
  571. func (_s *AccountGroupSelect) Scan(ctx context.Context, v any) error {
  572. ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
  573. if err := _s.prepareQuery(ctx); err != nil {
  574. return err
  575. }
  576. return scanWithInterceptors[*AccountGroupQuery, *AccountGroupSelect](ctx, _s.AccountGroupQuery, _s, _s.inters, v)
  577. }
  578. func (_s *AccountGroupSelect) sqlScan(ctx context.Context, root *AccountGroupQuery, v any) error {
  579. selector := root.sqlQuery(ctx)
  580. aggregation := make([]string, 0, len(_s.fns))
  581. for _, fn := range _s.fns {
  582. aggregation = append(aggregation, fn(selector))
  583. }
  584. switch n := len(*_s.selector.flds); {
  585. case n == 0 && len(aggregation) > 0:
  586. selector.Select(aggregation...)
  587. case n != 0 && len(aggregation) > 0:
  588. selector.AppendSelect(aggregation...)
  589. }
  590. rows := &sql.Rows{}
  591. query, args := selector.Query()
  592. if err := _s.driver.Query(ctx, query, args, rows); err != nil {
  593. return err
  594. }
  595. defer rows.Close()
  596. return sql.ScanSlice(rows, v)
  597. }