identityadoptiondecision_query.go 23 KB

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