ent.go 19 KB

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