ent.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "reflect"
  8. "sync"
  9. "wechat-api/ent/agent"
  10. "wechat-api/ent/agentbase"
  11. "wechat-api/ent/aliyunavatar"
  12. "wechat-api/ent/allocagent"
  13. "wechat-api/ent/apikey"
  14. "wechat-api/ent/batchmsg"
  15. "wechat-api/ent/category"
  16. "wechat-api/ent/chatrecords"
  17. "wechat-api/ent/chatsession"
  18. "wechat-api/ent/contact"
  19. "wechat-api/ent/creditbalance"
  20. "wechat-api/ent/creditusage"
  21. "wechat-api/ent/employee"
  22. "wechat-api/ent/employeeconfig"
  23. "wechat-api/ent/label"
  24. "wechat-api/ent/labelrelationship"
  25. "wechat-api/ent/labeltagging"
  26. "wechat-api/ent/message"
  27. "wechat-api/ent/messagerecords"
  28. "wechat-api/ent/msg"
  29. "wechat-api/ent/payrecharge"
  30. "wechat-api/ent/server"
  31. "wechat-api/ent/sopnode"
  32. "wechat-api/ent/sopstage"
  33. "wechat-api/ent/soptask"
  34. "wechat-api/ent/token"
  35. "wechat-api/ent/tutorial"
  36. "wechat-api/ent/usagedetail"
  37. "wechat-api/ent/usagestatisticday"
  38. "wechat-api/ent/usagestatistichour"
  39. "wechat-api/ent/usagestatisticmonth"
  40. "wechat-api/ent/usagetotal"
  41. "wechat-api/ent/whatsapp"
  42. "wechat-api/ent/whatsappchannel"
  43. "wechat-api/ent/workexperience"
  44. "wechat-api/ent/wpchatroom"
  45. "wechat-api/ent/wpchatroommember"
  46. "wechat-api/ent/wx"
  47. "wechat-api/ent/wxcard"
  48. "wechat-api/ent/wxcarduser"
  49. "wechat-api/ent/wxcardvisit"
  50. "entgo.io/ent"
  51. "entgo.io/ent/dialect/sql"
  52. "entgo.io/ent/dialect/sql/sqlgraph"
  53. )
  54. // ent aliases to avoid import conflicts in user's code.
  55. type (
  56. Op = ent.Op
  57. Hook = ent.Hook
  58. Value = ent.Value
  59. Query = ent.Query
  60. QueryContext = ent.QueryContext
  61. Querier = ent.Querier
  62. QuerierFunc = ent.QuerierFunc
  63. Interceptor = ent.Interceptor
  64. InterceptFunc = ent.InterceptFunc
  65. Traverser = ent.Traverser
  66. TraverseFunc = ent.TraverseFunc
  67. Policy = ent.Policy
  68. Mutator = ent.Mutator
  69. Mutation = ent.Mutation
  70. MutateFunc = ent.MutateFunc
  71. )
  72. type clientCtxKey struct{}
  73. // FromContext returns a Client stored inside a context, or nil if there isn't one.
  74. func FromContext(ctx context.Context) *Client {
  75. c, _ := ctx.Value(clientCtxKey{}).(*Client)
  76. return c
  77. }
  78. // NewContext returns a new context with the given Client attached.
  79. func NewContext(parent context.Context, c *Client) context.Context {
  80. return context.WithValue(parent, clientCtxKey{}, c)
  81. }
  82. type txCtxKey struct{}
  83. // TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
  84. func TxFromContext(ctx context.Context) *Tx {
  85. tx, _ := ctx.Value(txCtxKey{}).(*Tx)
  86. return tx
  87. }
  88. // NewTxContext returns a new context with the given Tx attached.
  89. func NewTxContext(parent context.Context, tx *Tx) context.Context {
  90. return context.WithValue(parent, txCtxKey{}, tx)
  91. }
  92. // OrderFunc applies an ordering on the sql selector.
  93. // Deprecated: Use Asc/Desc functions or the package builders instead.
  94. type OrderFunc func(*sql.Selector)
  95. var (
  96. initCheck sync.Once
  97. columnCheck sql.ColumnCheck
  98. )
  99. // columnChecker checks if the column exists in the given table.
  100. func checkColumn(table, column string) error {
  101. initCheck.Do(func() {
  102. columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
  103. agent.Table: agent.ValidColumn,
  104. agentbase.Table: agentbase.ValidColumn,
  105. aliyunavatar.Table: aliyunavatar.ValidColumn,
  106. allocagent.Table: allocagent.ValidColumn,
  107. apikey.Table: apikey.ValidColumn,
  108. batchmsg.Table: batchmsg.ValidColumn,
  109. category.Table: category.ValidColumn,
  110. chatrecords.Table: chatrecords.ValidColumn,
  111. chatsession.Table: chatsession.ValidColumn,
  112. contact.Table: contact.ValidColumn,
  113. creditbalance.Table: creditbalance.ValidColumn,
  114. creditusage.Table: creditusage.ValidColumn,
  115. employee.Table: employee.ValidColumn,
  116. employeeconfig.Table: employeeconfig.ValidColumn,
  117. label.Table: label.ValidColumn,
  118. labelrelationship.Table: labelrelationship.ValidColumn,
  119. labeltagging.Table: labeltagging.ValidColumn,
  120. message.Table: message.ValidColumn,
  121. messagerecords.Table: messagerecords.ValidColumn,
  122. msg.Table: msg.ValidColumn,
  123. payrecharge.Table: payrecharge.ValidColumn,
  124. server.Table: server.ValidColumn,
  125. sopnode.Table: sopnode.ValidColumn,
  126. sopstage.Table: sopstage.ValidColumn,
  127. soptask.Table: soptask.ValidColumn,
  128. token.Table: token.ValidColumn,
  129. tutorial.Table: tutorial.ValidColumn,
  130. usagedetail.Table: usagedetail.ValidColumn,
  131. usagestatisticday.Table: usagestatisticday.ValidColumn,
  132. usagestatistichour.Table: usagestatistichour.ValidColumn,
  133. usagestatisticmonth.Table: usagestatisticmonth.ValidColumn,
  134. usagetotal.Table: usagetotal.ValidColumn,
  135. whatsapp.Table: whatsapp.ValidColumn,
  136. whatsappchannel.Table: whatsappchannel.ValidColumn,
  137. workexperience.Table: workexperience.ValidColumn,
  138. wpchatroom.Table: wpchatroom.ValidColumn,
  139. wpchatroommember.Table: wpchatroommember.ValidColumn,
  140. wx.Table: wx.ValidColumn,
  141. wxcard.Table: wxcard.ValidColumn,
  142. wxcarduser.Table: wxcarduser.ValidColumn,
  143. wxcardvisit.Table: wxcardvisit.ValidColumn,
  144. })
  145. })
  146. return columnCheck(table, column)
  147. }
  148. // Asc applies the given fields in ASC order.
  149. func Asc(fields ...string) func(*sql.Selector) {
  150. return func(s *sql.Selector) {
  151. for _, f := range fields {
  152. if err := checkColumn(s.TableName(), f); err != nil {
  153. s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)})
  154. }
  155. s.OrderBy(sql.Asc(s.C(f)))
  156. }
  157. }
  158. }
  159. // Desc applies the given fields in DESC order.
  160. func Desc(fields ...string) func(*sql.Selector) {
  161. return func(s *sql.Selector) {
  162. for _, f := range fields {
  163. if err := checkColumn(s.TableName(), f); err != nil {
  164. s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)})
  165. }
  166. s.OrderBy(sql.Desc(s.C(f)))
  167. }
  168. }
  169. }
  170. // AggregateFunc applies an aggregation step on the group-by traversal/selector.
  171. type AggregateFunc func(*sql.Selector) string
  172. // As is a pseudo aggregation function for renaming another other functions with custom names. For example:
  173. //
  174. // GroupBy(field1, field2).
  175. // Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")).
  176. // Scan(ctx, &v)
  177. func As(fn AggregateFunc, end string) AggregateFunc {
  178. return func(s *sql.Selector) string {
  179. return sql.As(fn(s), end)
  180. }
  181. }
  182. // Count applies the "count" aggregation function on each group.
  183. func Count() AggregateFunc {
  184. return func(s *sql.Selector) string {
  185. return sql.Count("*")
  186. }
  187. }
  188. // Max applies the "max" aggregation function on the given field of each group.
  189. func Max(field string) AggregateFunc {
  190. return func(s *sql.Selector) string {
  191. if err := checkColumn(s.TableName(), field); err != nil {
  192. s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
  193. return ""
  194. }
  195. return sql.Max(s.C(field))
  196. }
  197. }
  198. // Mean applies the "mean" aggregation function on the given field of each group.
  199. func Mean(field string) AggregateFunc {
  200. return func(s *sql.Selector) string {
  201. if err := checkColumn(s.TableName(), field); err != nil {
  202. s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
  203. return ""
  204. }
  205. return sql.Avg(s.C(field))
  206. }
  207. }
  208. // Min applies the "min" aggregation function on the given field of each group.
  209. func Min(field string) AggregateFunc {
  210. return func(s *sql.Selector) string {
  211. if err := checkColumn(s.TableName(), field); err != nil {
  212. s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
  213. return ""
  214. }
  215. return sql.Min(s.C(field))
  216. }
  217. }
  218. // Sum applies the "sum" aggregation function on the given field of each group.
  219. func Sum(field string) AggregateFunc {
  220. return func(s *sql.Selector) string {
  221. if err := checkColumn(s.TableName(), field); err != nil {
  222. s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
  223. return ""
  224. }
  225. return sql.Sum(s.C(field))
  226. }
  227. }
  228. // ValidationError returns when validating a field or edge fails.
  229. type ValidationError struct {
  230. Name string // Field or edge name.
  231. err error
  232. }
  233. // Error implements the error interface.
  234. func (e *ValidationError) Error() string {
  235. return e.err.Error()
  236. }
  237. // Unwrap implements the errors.Wrapper interface.
  238. func (e *ValidationError) Unwrap() error {
  239. return e.err
  240. }
  241. // IsValidationError returns a boolean indicating whether the error is a validation error.
  242. func IsValidationError(err error) bool {
  243. if err == nil {
  244. return false
  245. }
  246. var e *ValidationError
  247. return errors.As(err, &e)
  248. }
  249. // NotFoundError returns when trying to fetch a specific entity and it was not found in the database.
  250. type NotFoundError struct {
  251. label string
  252. }
  253. // Error implements the error interface.
  254. func (e *NotFoundError) Error() string {
  255. return "ent: " + e.label + " not found"
  256. }
  257. // IsNotFound returns a boolean indicating whether the error is a not found error.
  258. func IsNotFound(err error) bool {
  259. if err == nil {
  260. return false
  261. }
  262. var e *NotFoundError
  263. return errors.As(err, &e)
  264. }
  265. // MaskNotFound masks not found error.
  266. func MaskNotFound(err error) error {
  267. if IsNotFound(err) {
  268. return nil
  269. }
  270. return err
  271. }
  272. // NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.
  273. type NotSingularError struct {
  274. label string
  275. }
  276. // Error implements the error interface.
  277. func (e *NotSingularError) Error() string {
  278. return "ent: " + e.label + " not singular"
  279. }
  280. // IsNotSingular returns a boolean indicating whether the error is a not singular error.
  281. func IsNotSingular(err error) bool {
  282. if err == nil {
  283. return false
  284. }
  285. var e *NotSingularError
  286. return errors.As(err, &e)
  287. }
  288. // NotLoadedError returns when trying to get a node that was not loaded by the query.
  289. type NotLoadedError struct {
  290. edge string
  291. }
  292. // Error implements the error interface.
  293. func (e *NotLoadedError) Error() string {
  294. return "ent: " + e.edge + " edge was not loaded"
  295. }
  296. // IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
  297. func IsNotLoaded(err error) bool {
  298. if err == nil {
  299. return false
  300. }
  301. var e *NotLoadedError
  302. return errors.As(err, &e)
  303. }
  304. // ConstraintError returns when trying to create/update one or more entities and
  305. // one or more of their constraints failed. For example, violation of edge or
  306. // field uniqueness.
  307. type ConstraintError struct {
  308. msg string
  309. wrap error
  310. }
  311. // Error implements the error interface.
  312. func (e ConstraintError) Error() string {
  313. return "ent: constraint failed: " + e.msg
  314. }
  315. // Unwrap implements the errors.Wrapper interface.
  316. func (e *ConstraintError) Unwrap() error {
  317. return e.wrap
  318. }
  319. // IsConstraintError returns a boolean indicating whether the error is a constraint failure.
  320. func IsConstraintError(err error) bool {
  321. if err == nil {
  322. return false
  323. }
  324. var e *ConstraintError
  325. return errors.As(err, &e)
  326. }
  327. // selector embedded by the different Select/GroupBy builders.
  328. type selector struct {
  329. label string
  330. flds *[]string
  331. fns []AggregateFunc
  332. scan func(context.Context, any) error
  333. }
  334. // ScanX is like Scan, but panics if an error occurs.
  335. func (s *selector) ScanX(ctx context.Context, v any) {
  336. if err := s.scan(ctx, v); err != nil {
  337. panic(err)
  338. }
  339. }
  340. // Strings returns list of strings from a selector. It is only allowed when selecting one field.
  341. func (s *selector) Strings(ctx context.Context) ([]string, error) {
  342. if len(*s.flds) > 1 {
  343. return nil, errors.New("ent: Strings is not achievable when selecting more than 1 field")
  344. }
  345. var v []string
  346. if err := s.scan(ctx, &v); err != nil {
  347. return nil, err
  348. }
  349. return v, nil
  350. }
  351. // StringsX is like Strings, but panics if an error occurs.
  352. func (s *selector) StringsX(ctx context.Context) []string {
  353. v, err := s.Strings(ctx)
  354. if err != nil {
  355. panic(err)
  356. }
  357. return v
  358. }
  359. // String returns a single string from a selector. It is only allowed when selecting one field.
  360. func (s *selector) String(ctx context.Context) (_ string, err error) {
  361. var v []string
  362. if v, err = s.Strings(ctx); err != nil {
  363. return
  364. }
  365. switch len(v) {
  366. case 1:
  367. return v[0], nil
  368. case 0:
  369. err = &NotFoundError{s.label}
  370. default:
  371. err = fmt.Errorf("ent: Strings returned %d results when one was expected", len(v))
  372. }
  373. return
  374. }
  375. // StringX is like String, but panics if an error occurs.
  376. func (s *selector) StringX(ctx context.Context) string {
  377. v, err := s.String(ctx)
  378. if err != nil {
  379. panic(err)
  380. }
  381. return v
  382. }
  383. // Ints returns list of ints from a selector. It is only allowed when selecting one field.
  384. func (s *selector) Ints(ctx context.Context) ([]int, error) {
  385. if len(*s.flds) > 1 {
  386. return nil, errors.New("ent: Ints is not achievable when selecting more than 1 field")
  387. }
  388. var v []int
  389. if err := s.scan(ctx, &v); err != nil {
  390. return nil, err
  391. }
  392. return v, nil
  393. }
  394. // IntsX is like Ints, but panics if an error occurs.
  395. func (s *selector) IntsX(ctx context.Context) []int {
  396. v, err := s.Ints(ctx)
  397. if err != nil {
  398. panic(err)
  399. }
  400. return v
  401. }
  402. // Int returns a single int from a selector. It is only allowed when selecting one field.
  403. func (s *selector) Int(ctx context.Context) (_ int, err error) {
  404. var v []int
  405. if v, err = s.Ints(ctx); err != nil {
  406. return
  407. }
  408. switch len(v) {
  409. case 1:
  410. return v[0], nil
  411. case 0:
  412. err = &NotFoundError{s.label}
  413. default:
  414. err = fmt.Errorf("ent: Ints returned %d results when one was expected", len(v))
  415. }
  416. return
  417. }
  418. // IntX is like Int, but panics if an error occurs.
  419. func (s *selector) IntX(ctx context.Context) int {
  420. v, err := s.Int(ctx)
  421. if err != nil {
  422. panic(err)
  423. }
  424. return v
  425. }
  426. // Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
  427. func (s *selector) Float64s(ctx context.Context) ([]float64, error) {
  428. if len(*s.flds) > 1 {
  429. return nil, errors.New("ent: Float64s is not achievable when selecting more than 1 field")
  430. }
  431. var v []float64
  432. if err := s.scan(ctx, &v); err != nil {
  433. return nil, err
  434. }
  435. return v, nil
  436. }
  437. // Float64sX is like Float64s, but panics if an error occurs.
  438. func (s *selector) Float64sX(ctx context.Context) []float64 {
  439. v, err := s.Float64s(ctx)
  440. if err != nil {
  441. panic(err)
  442. }
  443. return v
  444. }
  445. // Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
  446. func (s *selector) Float64(ctx context.Context) (_ float64, err error) {
  447. var v []float64
  448. if v, err = s.Float64s(ctx); err != nil {
  449. return
  450. }
  451. switch len(v) {
  452. case 1:
  453. return v[0], nil
  454. case 0:
  455. err = &NotFoundError{s.label}
  456. default:
  457. err = fmt.Errorf("ent: Float64s returned %d results when one was expected", len(v))
  458. }
  459. return
  460. }
  461. // Float64X is like Float64, but panics if an error occurs.
  462. func (s *selector) Float64X(ctx context.Context) float64 {
  463. v, err := s.Float64(ctx)
  464. if err != nil {
  465. panic(err)
  466. }
  467. return v
  468. }
  469. // Bools returns list of bools from a selector. It is only allowed when selecting one field.
  470. func (s *selector) Bools(ctx context.Context) ([]bool, error) {
  471. if len(*s.flds) > 1 {
  472. return nil, errors.New("ent: Bools is not achievable when selecting more than 1 field")
  473. }
  474. var v []bool
  475. if err := s.scan(ctx, &v); err != nil {
  476. return nil, err
  477. }
  478. return v, nil
  479. }
  480. // BoolsX is like Bools, but panics if an error occurs.
  481. func (s *selector) BoolsX(ctx context.Context) []bool {
  482. v, err := s.Bools(ctx)
  483. if err != nil {
  484. panic(err)
  485. }
  486. return v
  487. }
  488. // Bool returns a single bool from a selector. It is only allowed when selecting one field.
  489. func (s *selector) Bool(ctx context.Context) (_ bool, err error) {
  490. var v []bool
  491. if v, err = s.Bools(ctx); err != nil {
  492. return
  493. }
  494. switch len(v) {
  495. case 1:
  496. return v[0], nil
  497. case 0:
  498. err = &NotFoundError{s.label}
  499. default:
  500. err = fmt.Errorf("ent: Bools returned %d results when one was expected", len(v))
  501. }
  502. return
  503. }
  504. // BoolX is like Bool, but panics if an error occurs.
  505. func (s *selector) BoolX(ctx context.Context) bool {
  506. v, err := s.Bool(ctx)
  507. if err != nil {
  508. panic(err)
  509. }
  510. return v
  511. }
  512. // withHooks invokes the builder operation with the given hooks, if any.
  513. func withHooks[V Value, M any, PM interface {
  514. *M
  515. Mutation
  516. }](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) {
  517. if len(hooks) == 0 {
  518. return exec(ctx)
  519. }
  520. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  521. mutationT, ok := any(m).(PM)
  522. if !ok {
  523. return nil, fmt.Errorf("unexpected mutation type %T", m)
  524. }
  525. // Set the mutation to the builder.
  526. *mutation = *mutationT
  527. return exec(ctx)
  528. })
  529. for i := len(hooks) - 1; i >= 0; i-- {
  530. if hooks[i] == nil {
  531. return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
  532. }
  533. mut = hooks[i](mut)
  534. }
  535. v, err := mut.Mutate(ctx, mutation)
  536. if err != nil {
  537. return value, err
  538. }
  539. nv, ok := v.(V)
  540. if !ok {
  541. return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation)
  542. }
  543. return nv, nil
  544. }
  545. // setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist.
  546. func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context {
  547. if ent.QueryFromContext(ctx) == nil {
  548. qc.Op = op
  549. ctx = ent.NewQueryContext(ctx, qc)
  550. }
  551. return ctx
  552. }
  553. func querierAll[V Value, Q interface {
  554. sqlAll(context.Context, ...queryHook) (V, error)
  555. }]() Querier {
  556. return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
  557. query, ok := q.(Q)
  558. if !ok {
  559. return nil, fmt.Errorf("unexpected query type %T", q)
  560. }
  561. return query.sqlAll(ctx)
  562. })
  563. }
  564. func querierCount[Q interface {
  565. sqlCount(context.Context) (int, error)
  566. }]() Querier {
  567. return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
  568. query, ok := q.(Q)
  569. if !ok {
  570. return nil, fmt.Errorf("unexpected query type %T", q)
  571. }
  572. return query.sqlCount(ctx)
  573. })
  574. }
  575. func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) {
  576. for i := len(inters) - 1; i >= 0; i-- {
  577. qr = inters[i].Intercept(qr)
  578. }
  579. rv, err := qr.Query(ctx, q)
  580. if err != nil {
  581. return v, err
  582. }
  583. vt, ok := rv.(V)
  584. if !ok {
  585. return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v)
  586. }
  587. return vt, nil
  588. }
  589. func scanWithInterceptors[Q1 ent.Query, Q2 interface {
  590. sqlScan(context.Context, Q1, any) error
  591. }](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error {
  592. rv := reflect.ValueOf(v)
  593. var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
  594. query, ok := q.(Q1)
  595. if !ok {
  596. return nil, fmt.Errorf("unexpected query type %T", q)
  597. }
  598. if err := selectOrGroup.sqlScan(ctx, query, v); err != nil {
  599. return nil, err
  600. }
  601. if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() {
  602. return rv.Elem().Interface(), nil
  603. }
  604. return v, nil
  605. })
  606. for i := len(inters) - 1; i >= 0; i-- {
  607. qr = inters[i].Intercept(qr)
  608. }
  609. vv, err := qr.Query(ctx, rootQuery)
  610. if err != nil {
  611. return err
  612. }
  613. switch rv2 := reflect.ValueOf(vv); {
  614. case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer:
  615. case rv.Type() == rv2.Type():
  616. rv.Elem().Set(rv2.Elem())
  617. case rv.Elem().Type() == rv2.Type():
  618. rv.Elem().Set(rv2)
  619. }
  620. return nil
  621. }
  622. // queryHook describes an internal hook for the different sqlAll methods.
  623. type queryHook func(context.Context, *sqlgraph.QuerySpec)