intercept.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. // Code generated by ent, DO NOT EDIT.
  2. package intercept
  3. import (
  4. "context"
  5. "fmt"
  6. "wechat-api/ent"
  7. "wechat-api/ent/batchmsg"
  8. "wechat-api/ent/contact"
  9. "wechat-api/ent/label"
  10. "wechat-api/ent/labelrelationship"
  11. "wechat-api/ent/message"
  12. "wechat-api/ent/messagerecords"
  13. "wechat-api/ent/msg"
  14. "wechat-api/ent/predicate"
  15. "wechat-api/ent/server"
  16. "wechat-api/ent/sopnode"
  17. "wechat-api/ent/sopstage"
  18. "wechat-api/ent/soptask"
  19. "wechat-api/ent/wx"
  20. "entgo.io/ent/dialect/sql"
  21. )
  22. // The Query interface represents an operation that queries a graph.
  23. // By using this interface, users can write generic code that manipulates
  24. // query builders of different types.
  25. type Query interface {
  26. // Type returns the string representation of the query type.
  27. Type() string
  28. // Limit the number of records to be returned by this query.
  29. Limit(int)
  30. // Offset to start from.
  31. Offset(int)
  32. // Unique configures the query builder to filter duplicate records.
  33. Unique(bool)
  34. // Order specifies how the records should be ordered.
  35. Order(...func(*sql.Selector))
  36. // WhereP appends storage-level predicates to the query builder. Using this method, users
  37. // can use type-assertion to append predicates that do not depend on any generated package.
  38. WhereP(...func(*sql.Selector))
  39. }
  40. // The Func type is an adapter that allows ordinary functions to be used as interceptors.
  41. // Unlike traversal functions, interceptors are skipped during graph traversals. Note that the
  42. // implementation of Func is different from the one defined in entgo.io/ent.InterceptFunc.
  43. type Func func(context.Context, Query) error
  44. // Intercept calls f(ctx, q) and then applied the next Querier.
  45. func (f Func) Intercept(next ent.Querier) ent.Querier {
  46. return ent.QuerierFunc(func(ctx context.Context, q ent.Query) (ent.Value, error) {
  47. query, err := NewQuery(q)
  48. if err != nil {
  49. return nil, err
  50. }
  51. if err := f(ctx, query); err != nil {
  52. return nil, err
  53. }
  54. return next.Query(ctx, q)
  55. })
  56. }
  57. // The TraverseFunc type is an adapter to allow the use of ordinary function as Traverser.
  58. // If f is a function with the appropriate signature, TraverseFunc(f) is a Traverser that calls f.
  59. type TraverseFunc func(context.Context, Query) error
  60. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  61. func (f TraverseFunc) Intercept(next ent.Querier) ent.Querier {
  62. return next
  63. }
  64. // Traverse calls f(ctx, q).
  65. func (f TraverseFunc) Traverse(ctx context.Context, q ent.Query) error {
  66. query, err := NewQuery(q)
  67. if err != nil {
  68. return err
  69. }
  70. return f(ctx, query)
  71. }
  72. // The BatchMsgFunc type is an adapter to allow the use of ordinary function as a Querier.
  73. type BatchMsgFunc func(context.Context, *ent.BatchMsgQuery) (ent.Value, error)
  74. // Query calls f(ctx, q).
  75. func (f BatchMsgFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  76. if q, ok := q.(*ent.BatchMsgQuery); ok {
  77. return f(ctx, q)
  78. }
  79. return nil, fmt.Errorf("unexpected query type %T. expect *ent.BatchMsgQuery", q)
  80. }
  81. // The TraverseBatchMsg type is an adapter to allow the use of ordinary function as Traverser.
  82. type TraverseBatchMsg func(context.Context, *ent.BatchMsgQuery) error
  83. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  84. func (f TraverseBatchMsg) Intercept(next ent.Querier) ent.Querier {
  85. return next
  86. }
  87. // Traverse calls f(ctx, q).
  88. func (f TraverseBatchMsg) Traverse(ctx context.Context, q ent.Query) error {
  89. if q, ok := q.(*ent.BatchMsgQuery); ok {
  90. return f(ctx, q)
  91. }
  92. return fmt.Errorf("unexpected query type %T. expect *ent.BatchMsgQuery", q)
  93. }
  94. // The ContactFunc type is an adapter to allow the use of ordinary function as a Querier.
  95. type ContactFunc func(context.Context, *ent.ContactQuery) (ent.Value, error)
  96. // Query calls f(ctx, q).
  97. func (f ContactFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  98. if q, ok := q.(*ent.ContactQuery); ok {
  99. return f(ctx, q)
  100. }
  101. return nil, fmt.Errorf("unexpected query type %T. expect *ent.ContactQuery", q)
  102. }
  103. // The TraverseContact type is an adapter to allow the use of ordinary function as Traverser.
  104. type TraverseContact func(context.Context, *ent.ContactQuery) error
  105. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  106. func (f TraverseContact) Intercept(next ent.Querier) ent.Querier {
  107. return next
  108. }
  109. // Traverse calls f(ctx, q).
  110. func (f TraverseContact) Traverse(ctx context.Context, q ent.Query) error {
  111. if q, ok := q.(*ent.ContactQuery); ok {
  112. return f(ctx, q)
  113. }
  114. return fmt.Errorf("unexpected query type %T. expect *ent.ContactQuery", q)
  115. }
  116. // The LabelFunc type is an adapter to allow the use of ordinary function as a Querier.
  117. type LabelFunc func(context.Context, *ent.LabelQuery) (ent.Value, error)
  118. // Query calls f(ctx, q).
  119. func (f LabelFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  120. if q, ok := q.(*ent.LabelQuery); ok {
  121. return f(ctx, q)
  122. }
  123. return nil, fmt.Errorf("unexpected query type %T. expect *ent.LabelQuery", q)
  124. }
  125. // The TraverseLabel type is an adapter to allow the use of ordinary function as Traverser.
  126. type TraverseLabel func(context.Context, *ent.LabelQuery) error
  127. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  128. func (f TraverseLabel) Intercept(next ent.Querier) ent.Querier {
  129. return next
  130. }
  131. // Traverse calls f(ctx, q).
  132. func (f TraverseLabel) Traverse(ctx context.Context, q ent.Query) error {
  133. if q, ok := q.(*ent.LabelQuery); ok {
  134. return f(ctx, q)
  135. }
  136. return fmt.Errorf("unexpected query type %T. expect *ent.LabelQuery", q)
  137. }
  138. // The LabelRelationshipFunc type is an adapter to allow the use of ordinary function as a Querier.
  139. type LabelRelationshipFunc func(context.Context, *ent.LabelRelationshipQuery) (ent.Value, error)
  140. // Query calls f(ctx, q).
  141. func (f LabelRelationshipFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  142. if q, ok := q.(*ent.LabelRelationshipQuery); ok {
  143. return f(ctx, q)
  144. }
  145. return nil, fmt.Errorf("unexpected query type %T. expect *ent.LabelRelationshipQuery", q)
  146. }
  147. // The TraverseLabelRelationship type is an adapter to allow the use of ordinary function as Traverser.
  148. type TraverseLabelRelationship func(context.Context, *ent.LabelRelationshipQuery) error
  149. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  150. func (f TraverseLabelRelationship) Intercept(next ent.Querier) ent.Querier {
  151. return next
  152. }
  153. // Traverse calls f(ctx, q).
  154. func (f TraverseLabelRelationship) Traverse(ctx context.Context, q ent.Query) error {
  155. if q, ok := q.(*ent.LabelRelationshipQuery); ok {
  156. return f(ctx, q)
  157. }
  158. return fmt.Errorf("unexpected query type %T. expect *ent.LabelRelationshipQuery", q)
  159. }
  160. // The MessageFunc type is an adapter to allow the use of ordinary function as a Querier.
  161. type MessageFunc func(context.Context, *ent.MessageQuery) (ent.Value, error)
  162. // Query calls f(ctx, q).
  163. func (f MessageFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  164. if q, ok := q.(*ent.MessageQuery); ok {
  165. return f(ctx, q)
  166. }
  167. return nil, fmt.Errorf("unexpected query type %T. expect *ent.MessageQuery", q)
  168. }
  169. // The TraverseMessage type is an adapter to allow the use of ordinary function as Traverser.
  170. type TraverseMessage func(context.Context, *ent.MessageQuery) error
  171. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  172. func (f TraverseMessage) Intercept(next ent.Querier) ent.Querier {
  173. return next
  174. }
  175. // Traverse calls f(ctx, q).
  176. func (f TraverseMessage) Traverse(ctx context.Context, q ent.Query) error {
  177. if q, ok := q.(*ent.MessageQuery); ok {
  178. return f(ctx, q)
  179. }
  180. return fmt.Errorf("unexpected query type %T. expect *ent.MessageQuery", q)
  181. }
  182. // The MessageRecordsFunc type is an adapter to allow the use of ordinary function as a Querier.
  183. type MessageRecordsFunc func(context.Context, *ent.MessageRecordsQuery) (ent.Value, error)
  184. // Query calls f(ctx, q).
  185. func (f MessageRecordsFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  186. if q, ok := q.(*ent.MessageRecordsQuery); ok {
  187. return f(ctx, q)
  188. }
  189. return nil, fmt.Errorf("unexpected query type %T. expect *ent.MessageRecordsQuery", q)
  190. }
  191. // The TraverseMessageRecords type is an adapter to allow the use of ordinary function as Traverser.
  192. type TraverseMessageRecords func(context.Context, *ent.MessageRecordsQuery) error
  193. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  194. func (f TraverseMessageRecords) Intercept(next ent.Querier) ent.Querier {
  195. return next
  196. }
  197. // Traverse calls f(ctx, q).
  198. func (f TraverseMessageRecords) Traverse(ctx context.Context, q ent.Query) error {
  199. if q, ok := q.(*ent.MessageRecordsQuery); ok {
  200. return f(ctx, q)
  201. }
  202. return fmt.Errorf("unexpected query type %T. expect *ent.MessageRecordsQuery", q)
  203. }
  204. // The MsgFunc type is an adapter to allow the use of ordinary function as a Querier.
  205. type MsgFunc func(context.Context, *ent.MsgQuery) (ent.Value, error)
  206. // Query calls f(ctx, q).
  207. func (f MsgFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  208. if q, ok := q.(*ent.MsgQuery); ok {
  209. return f(ctx, q)
  210. }
  211. return nil, fmt.Errorf("unexpected query type %T. expect *ent.MsgQuery", q)
  212. }
  213. // The TraverseMsg type is an adapter to allow the use of ordinary function as Traverser.
  214. type TraverseMsg func(context.Context, *ent.MsgQuery) error
  215. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  216. func (f TraverseMsg) Intercept(next ent.Querier) ent.Querier {
  217. return next
  218. }
  219. // Traverse calls f(ctx, q).
  220. func (f TraverseMsg) Traverse(ctx context.Context, q ent.Query) error {
  221. if q, ok := q.(*ent.MsgQuery); ok {
  222. return f(ctx, q)
  223. }
  224. return fmt.Errorf("unexpected query type %T. expect *ent.MsgQuery", q)
  225. }
  226. // The ServerFunc type is an adapter to allow the use of ordinary function as a Querier.
  227. type ServerFunc func(context.Context, *ent.ServerQuery) (ent.Value, error)
  228. // Query calls f(ctx, q).
  229. func (f ServerFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  230. if q, ok := q.(*ent.ServerQuery); ok {
  231. return f(ctx, q)
  232. }
  233. return nil, fmt.Errorf("unexpected query type %T. expect *ent.ServerQuery", q)
  234. }
  235. // The TraverseServer type is an adapter to allow the use of ordinary function as Traverser.
  236. type TraverseServer func(context.Context, *ent.ServerQuery) error
  237. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  238. func (f TraverseServer) Intercept(next ent.Querier) ent.Querier {
  239. return next
  240. }
  241. // Traverse calls f(ctx, q).
  242. func (f TraverseServer) Traverse(ctx context.Context, q ent.Query) error {
  243. if q, ok := q.(*ent.ServerQuery); ok {
  244. return f(ctx, q)
  245. }
  246. return fmt.Errorf("unexpected query type %T. expect *ent.ServerQuery", q)
  247. }
  248. // The SopNodeFunc type is an adapter to allow the use of ordinary function as a Querier.
  249. type SopNodeFunc func(context.Context, *ent.SopNodeQuery) (ent.Value, error)
  250. // Query calls f(ctx, q).
  251. func (f SopNodeFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  252. if q, ok := q.(*ent.SopNodeQuery); ok {
  253. return f(ctx, q)
  254. }
  255. return nil, fmt.Errorf("unexpected query type %T. expect *ent.SopNodeQuery", q)
  256. }
  257. // The TraverseSopNode type is an adapter to allow the use of ordinary function as Traverser.
  258. type TraverseSopNode func(context.Context, *ent.SopNodeQuery) error
  259. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  260. func (f TraverseSopNode) Intercept(next ent.Querier) ent.Querier {
  261. return next
  262. }
  263. // Traverse calls f(ctx, q).
  264. func (f TraverseSopNode) Traverse(ctx context.Context, q ent.Query) error {
  265. if q, ok := q.(*ent.SopNodeQuery); ok {
  266. return f(ctx, q)
  267. }
  268. return fmt.Errorf("unexpected query type %T. expect *ent.SopNodeQuery", q)
  269. }
  270. // The SopStageFunc type is an adapter to allow the use of ordinary function as a Querier.
  271. type SopStageFunc func(context.Context, *ent.SopStageQuery) (ent.Value, error)
  272. // Query calls f(ctx, q).
  273. func (f SopStageFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  274. if q, ok := q.(*ent.SopStageQuery); ok {
  275. return f(ctx, q)
  276. }
  277. return nil, fmt.Errorf("unexpected query type %T. expect *ent.SopStageQuery", q)
  278. }
  279. // The TraverseSopStage type is an adapter to allow the use of ordinary function as Traverser.
  280. type TraverseSopStage func(context.Context, *ent.SopStageQuery) error
  281. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  282. func (f TraverseSopStage) Intercept(next ent.Querier) ent.Querier {
  283. return next
  284. }
  285. // Traverse calls f(ctx, q).
  286. func (f TraverseSopStage) Traverse(ctx context.Context, q ent.Query) error {
  287. if q, ok := q.(*ent.SopStageQuery); ok {
  288. return f(ctx, q)
  289. }
  290. return fmt.Errorf("unexpected query type %T. expect *ent.SopStageQuery", q)
  291. }
  292. // The SopTaskFunc type is an adapter to allow the use of ordinary function as a Querier.
  293. type SopTaskFunc func(context.Context, *ent.SopTaskQuery) (ent.Value, error)
  294. // Query calls f(ctx, q).
  295. func (f SopTaskFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  296. if q, ok := q.(*ent.SopTaskQuery); ok {
  297. return f(ctx, q)
  298. }
  299. return nil, fmt.Errorf("unexpected query type %T. expect *ent.SopTaskQuery", q)
  300. }
  301. // The TraverseSopTask type is an adapter to allow the use of ordinary function as Traverser.
  302. type TraverseSopTask func(context.Context, *ent.SopTaskQuery) error
  303. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  304. func (f TraverseSopTask) Intercept(next ent.Querier) ent.Querier {
  305. return next
  306. }
  307. // Traverse calls f(ctx, q).
  308. func (f TraverseSopTask) Traverse(ctx context.Context, q ent.Query) error {
  309. if q, ok := q.(*ent.SopTaskQuery); ok {
  310. return f(ctx, q)
  311. }
  312. return fmt.Errorf("unexpected query type %T. expect *ent.SopTaskQuery", q)
  313. }
  314. // The WxFunc type is an adapter to allow the use of ordinary function as a Querier.
  315. type WxFunc func(context.Context, *ent.WxQuery) (ent.Value, error)
  316. // Query calls f(ctx, q).
  317. func (f WxFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  318. if q, ok := q.(*ent.WxQuery); ok {
  319. return f(ctx, q)
  320. }
  321. return nil, fmt.Errorf("unexpected query type %T. expect *ent.WxQuery", q)
  322. }
  323. // The TraverseWx type is an adapter to allow the use of ordinary function as Traverser.
  324. type TraverseWx func(context.Context, *ent.WxQuery) error
  325. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  326. func (f TraverseWx) Intercept(next ent.Querier) ent.Querier {
  327. return next
  328. }
  329. // Traverse calls f(ctx, q).
  330. func (f TraverseWx) Traverse(ctx context.Context, q ent.Query) error {
  331. if q, ok := q.(*ent.WxQuery); ok {
  332. return f(ctx, q)
  333. }
  334. return fmt.Errorf("unexpected query type %T. expect *ent.WxQuery", q)
  335. }
  336. // NewQuery returns the generic Query interface for the given typed query.
  337. func NewQuery(q ent.Query) (Query, error) {
  338. switch q := q.(type) {
  339. case *ent.BatchMsgQuery:
  340. return &query[*ent.BatchMsgQuery, predicate.BatchMsg, batchmsg.OrderOption]{typ: ent.TypeBatchMsg, tq: q}, nil
  341. case *ent.ContactQuery:
  342. return &query[*ent.ContactQuery, predicate.Contact, contact.OrderOption]{typ: ent.TypeContact, tq: q}, nil
  343. case *ent.LabelQuery:
  344. return &query[*ent.LabelQuery, predicate.Label, label.OrderOption]{typ: ent.TypeLabel, tq: q}, nil
  345. case *ent.LabelRelationshipQuery:
  346. return &query[*ent.LabelRelationshipQuery, predicate.LabelRelationship, labelrelationship.OrderOption]{typ: ent.TypeLabelRelationship, tq: q}, nil
  347. case *ent.MessageQuery:
  348. return &query[*ent.MessageQuery, predicate.Message, message.OrderOption]{typ: ent.TypeMessage, tq: q}, nil
  349. case *ent.MessageRecordsQuery:
  350. return &query[*ent.MessageRecordsQuery, predicate.MessageRecords, messagerecords.OrderOption]{typ: ent.TypeMessageRecords, tq: q}, nil
  351. case *ent.MsgQuery:
  352. return &query[*ent.MsgQuery, predicate.Msg, msg.OrderOption]{typ: ent.TypeMsg, tq: q}, nil
  353. case *ent.ServerQuery:
  354. return &query[*ent.ServerQuery, predicate.Server, server.OrderOption]{typ: ent.TypeServer, tq: q}, nil
  355. case *ent.SopNodeQuery:
  356. return &query[*ent.SopNodeQuery, predicate.SopNode, sopnode.OrderOption]{typ: ent.TypeSopNode, tq: q}, nil
  357. case *ent.SopStageQuery:
  358. return &query[*ent.SopStageQuery, predicate.SopStage, sopstage.OrderOption]{typ: ent.TypeSopStage, tq: q}, nil
  359. case *ent.SopTaskQuery:
  360. return &query[*ent.SopTaskQuery, predicate.SopTask, soptask.OrderOption]{typ: ent.TypeSopTask, tq: q}, nil
  361. case *ent.WxQuery:
  362. return &query[*ent.WxQuery, predicate.Wx, wx.OrderOption]{typ: ent.TypeWx, tq: q}, nil
  363. default:
  364. return nil, fmt.Errorf("unknown query type %T", q)
  365. }
  366. }
  367. type query[T any, P ~func(*sql.Selector), R ~func(*sql.Selector)] struct {
  368. typ string
  369. tq interface {
  370. Limit(int) T
  371. Offset(int) T
  372. Unique(bool) T
  373. Order(...R) T
  374. Where(...P) T
  375. }
  376. }
  377. func (q query[T, P, R]) Type() string {
  378. return q.typ
  379. }
  380. func (q query[T, P, R]) Limit(limit int) {
  381. q.tq.Limit(limit)
  382. }
  383. func (q query[T, P, R]) Offset(offset int) {
  384. q.tq.Offset(offset)
  385. }
  386. func (q query[T, P, R]) Unique(unique bool) {
  387. q.tq.Unique(unique)
  388. }
  389. func (q query[T, P, R]) Order(orders ...func(*sql.Selector)) {
  390. rs := make([]R, len(orders))
  391. for i := range orders {
  392. rs[i] = orders[i]
  393. }
  394. q.tq.Order(rs...)
  395. }
  396. func (q query[T, P, R]) WhereP(ps ...func(*sql.Selector)) {
  397. p := make([]P, len(ps))
  398. for i := range ps {
  399. p[i] = ps[i]
  400. }
  401. q.tq.Where(p...)
  402. }