authidentitychannel_query.go 20 KB

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