intercept.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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/agent"
  8. "wechat-api/ent/batchmsg"
  9. "wechat-api/ent/contact"
  10. "wechat-api/ent/employee"
  11. "wechat-api/ent/label"
  12. "wechat-api/ent/labelrelationship"
  13. "wechat-api/ent/message"
  14. "wechat-api/ent/messagerecords"
  15. "wechat-api/ent/msg"
  16. "wechat-api/ent/predicate"
  17. "wechat-api/ent/server"
  18. "wechat-api/ent/sopnode"
  19. "wechat-api/ent/sopstage"
  20. "wechat-api/ent/soptask"
  21. "wechat-api/ent/token"
  22. "wechat-api/ent/tutorial"
  23. "wechat-api/ent/workexperience"
  24. "wechat-api/ent/wx"
  25. "entgo.io/ent/dialect/sql"
  26. )
  27. // The Query interface represents an operation that queries a graph.
  28. // By using this interface, users can write generic code that manipulates
  29. // query builders of different types.
  30. type Query interface {
  31. // Type returns the string representation of the query type.
  32. Type() string
  33. // Limit the number of records to be returned by this query.
  34. Limit(int)
  35. // Offset to start from.
  36. Offset(int)
  37. // Unique configures the query builder to filter duplicate records.
  38. Unique(bool)
  39. // Order specifies how the records should be ordered.
  40. Order(...func(*sql.Selector))
  41. // WhereP appends storage-level predicates to the query builder. Using this method, users
  42. // can use type-assertion to append predicates that do not depend on any generated package.
  43. WhereP(...func(*sql.Selector))
  44. }
  45. // The Func type is an adapter that allows ordinary functions to be used as interceptors.
  46. // Unlike traversal functions, interceptors are skipped during graph traversals. Note that the
  47. // implementation of Func is different from the one defined in entgo.io/ent.InterceptFunc.
  48. type Func func(context.Context, Query) error
  49. // Intercept calls f(ctx, q) and then applied the next Querier.
  50. func (f Func) Intercept(next ent.Querier) ent.Querier {
  51. return ent.QuerierFunc(func(ctx context.Context, q ent.Query) (ent.Value, error) {
  52. query, err := NewQuery(q)
  53. if err != nil {
  54. return nil, err
  55. }
  56. if err := f(ctx, query); err != nil {
  57. return nil, err
  58. }
  59. return next.Query(ctx, q)
  60. })
  61. }
  62. // The TraverseFunc type is an adapter to allow the use of ordinary function as Traverser.
  63. // If f is a function with the appropriate signature, TraverseFunc(f) is a Traverser that calls f.
  64. type TraverseFunc func(context.Context, Query) error
  65. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  66. func (f TraverseFunc) Intercept(next ent.Querier) ent.Querier {
  67. return next
  68. }
  69. // Traverse calls f(ctx, q).
  70. func (f TraverseFunc) Traverse(ctx context.Context, q ent.Query) error {
  71. query, err := NewQuery(q)
  72. if err != nil {
  73. return err
  74. }
  75. return f(ctx, query)
  76. }
  77. // The AgentFunc type is an adapter to allow the use of ordinary function as a Querier.
  78. type AgentFunc func(context.Context, *ent.AgentQuery) (ent.Value, error)
  79. // Query calls f(ctx, q).
  80. func (f AgentFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  81. if q, ok := q.(*ent.AgentQuery); ok {
  82. return f(ctx, q)
  83. }
  84. return nil, fmt.Errorf("unexpected query type %T. expect *ent.AgentQuery", q)
  85. }
  86. // The TraverseAgent type is an adapter to allow the use of ordinary function as Traverser.
  87. type TraverseAgent func(context.Context, *ent.AgentQuery) error
  88. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  89. func (f TraverseAgent) Intercept(next ent.Querier) ent.Querier {
  90. return next
  91. }
  92. // Traverse calls f(ctx, q).
  93. func (f TraverseAgent) Traverse(ctx context.Context, q ent.Query) error {
  94. if q, ok := q.(*ent.AgentQuery); ok {
  95. return f(ctx, q)
  96. }
  97. return fmt.Errorf("unexpected query type %T. expect *ent.AgentQuery", q)
  98. }
  99. // The BatchMsgFunc type is an adapter to allow the use of ordinary function as a Querier.
  100. type BatchMsgFunc func(context.Context, *ent.BatchMsgQuery) (ent.Value, error)
  101. // Query calls f(ctx, q).
  102. func (f BatchMsgFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  103. if q, ok := q.(*ent.BatchMsgQuery); ok {
  104. return f(ctx, q)
  105. }
  106. return nil, fmt.Errorf("unexpected query type %T. expect *ent.BatchMsgQuery", q)
  107. }
  108. // The TraverseBatchMsg type is an adapter to allow the use of ordinary function as Traverser.
  109. type TraverseBatchMsg func(context.Context, *ent.BatchMsgQuery) error
  110. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  111. func (f TraverseBatchMsg) Intercept(next ent.Querier) ent.Querier {
  112. return next
  113. }
  114. // Traverse calls f(ctx, q).
  115. func (f TraverseBatchMsg) Traverse(ctx context.Context, q ent.Query) error {
  116. if q, ok := q.(*ent.BatchMsgQuery); ok {
  117. return f(ctx, q)
  118. }
  119. return fmt.Errorf("unexpected query type %T. expect *ent.BatchMsgQuery", q)
  120. }
  121. // The ContactFunc type is an adapter to allow the use of ordinary function as a Querier.
  122. type ContactFunc func(context.Context, *ent.ContactQuery) (ent.Value, error)
  123. // Query calls f(ctx, q).
  124. func (f ContactFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  125. if q, ok := q.(*ent.ContactQuery); ok {
  126. return f(ctx, q)
  127. }
  128. return nil, fmt.Errorf("unexpected query type %T. expect *ent.ContactQuery", q)
  129. }
  130. // The TraverseContact type is an adapter to allow the use of ordinary function as Traverser.
  131. type TraverseContact func(context.Context, *ent.ContactQuery) error
  132. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  133. func (f TraverseContact) Intercept(next ent.Querier) ent.Querier {
  134. return next
  135. }
  136. // Traverse calls f(ctx, q).
  137. func (f TraverseContact) Traverse(ctx context.Context, q ent.Query) error {
  138. if q, ok := q.(*ent.ContactQuery); ok {
  139. return f(ctx, q)
  140. }
  141. return fmt.Errorf("unexpected query type %T. expect *ent.ContactQuery", q)
  142. }
  143. // The EmployeeFunc type is an adapter to allow the use of ordinary function as a Querier.
  144. type EmployeeFunc func(context.Context, *ent.EmployeeQuery) (ent.Value, error)
  145. // Query calls f(ctx, q).
  146. func (f EmployeeFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  147. if q, ok := q.(*ent.EmployeeQuery); ok {
  148. return f(ctx, q)
  149. }
  150. return nil, fmt.Errorf("unexpected query type %T. expect *ent.EmployeeQuery", q)
  151. }
  152. // The TraverseEmployee type is an adapter to allow the use of ordinary function as Traverser.
  153. type TraverseEmployee func(context.Context, *ent.EmployeeQuery) error
  154. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  155. func (f TraverseEmployee) Intercept(next ent.Querier) ent.Querier {
  156. return next
  157. }
  158. // Traverse calls f(ctx, q).
  159. func (f TraverseEmployee) Traverse(ctx context.Context, q ent.Query) error {
  160. if q, ok := q.(*ent.EmployeeQuery); ok {
  161. return f(ctx, q)
  162. }
  163. return fmt.Errorf("unexpected query type %T. expect *ent.EmployeeQuery", q)
  164. }
  165. // The LabelFunc type is an adapter to allow the use of ordinary function as a Querier.
  166. type LabelFunc func(context.Context, *ent.LabelQuery) (ent.Value, error)
  167. // Query calls f(ctx, q).
  168. func (f LabelFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  169. if q, ok := q.(*ent.LabelQuery); ok {
  170. return f(ctx, q)
  171. }
  172. return nil, fmt.Errorf("unexpected query type %T. expect *ent.LabelQuery", q)
  173. }
  174. // The TraverseLabel type is an adapter to allow the use of ordinary function as Traverser.
  175. type TraverseLabel func(context.Context, *ent.LabelQuery) error
  176. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  177. func (f TraverseLabel) Intercept(next ent.Querier) ent.Querier {
  178. return next
  179. }
  180. // Traverse calls f(ctx, q).
  181. func (f TraverseLabel) Traverse(ctx context.Context, q ent.Query) error {
  182. if q, ok := q.(*ent.LabelQuery); ok {
  183. return f(ctx, q)
  184. }
  185. return fmt.Errorf("unexpected query type %T. expect *ent.LabelQuery", q)
  186. }
  187. // The LabelRelationshipFunc type is an adapter to allow the use of ordinary function as a Querier.
  188. type LabelRelationshipFunc func(context.Context, *ent.LabelRelationshipQuery) (ent.Value, error)
  189. // Query calls f(ctx, q).
  190. func (f LabelRelationshipFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  191. if q, ok := q.(*ent.LabelRelationshipQuery); ok {
  192. return f(ctx, q)
  193. }
  194. return nil, fmt.Errorf("unexpected query type %T. expect *ent.LabelRelationshipQuery", q)
  195. }
  196. // The TraverseLabelRelationship type is an adapter to allow the use of ordinary function as Traverser.
  197. type TraverseLabelRelationship func(context.Context, *ent.LabelRelationshipQuery) error
  198. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  199. func (f TraverseLabelRelationship) Intercept(next ent.Querier) ent.Querier {
  200. return next
  201. }
  202. // Traverse calls f(ctx, q).
  203. func (f TraverseLabelRelationship) Traverse(ctx context.Context, q ent.Query) error {
  204. if q, ok := q.(*ent.LabelRelationshipQuery); ok {
  205. return f(ctx, q)
  206. }
  207. return fmt.Errorf("unexpected query type %T. expect *ent.LabelRelationshipQuery", q)
  208. }
  209. // The MessageFunc type is an adapter to allow the use of ordinary function as a Querier.
  210. type MessageFunc func(context.Context, *ent.MessageQuery) (ent.Value, error)
  211. // Query calls f(ctx, q).
  212. func (f MessageFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  213. if q, ok := q.(*ent.MessageQuery); ok {
  214. return f(ctx, q)
  215. }
  216. return nil, fmt.Errorf("unexpected query type %T. expect *ent.MessageQuery", q)
  217. }
  218. // The TraverseMessage type is an adapter to allow the use of ordinary function as Traverser.
  219. type TraverseMessage func(context.Context, *ent.MessageQuery) error
  220. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  221. func (f TraverseMessage) Intercept(next ent.Querier) ent.Querier {
  222. return next
  223. }
  224. // Traverse calls f(ctx, q).
  225. func (f TraverseMessage) Traverse(ctx context.Context, q ent.Query) error {
  226. if q, ok := q.(*ent.MessageQuery); ok {
  227. return f(ctx, q)
  228. }
  229. return fmt.Errorf("unexpected query type %T. expect *ent.MessageQuery", q)
  230. }
  231. // The MessageRecordsFunc type is an adapter to allow the use of ordinary function as a Querier.
  232. type MessageRecordsFunc func(context.Context, *ent.MessageRecordsQuery) (ent.Value, error)
  233. // Query calls f(ctx, q).
  234. func (f MessageRecordsFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  235. if q, ok := q.(*ent.MessageRecordsQuery); ok {
  236. return f(ctx, q)
  237. }
  238. return nil, fmt.Errorf("unexpected query type %T. expect *ent.MessageRecordsQuery", q)
  239. }
  240. // The TraverseMessageRecords type is an adapter to allow the use of ordinary function as Traverser.
  241. type TraverseMessageRecords func(context.Context, *ent.MessageRecordsQuery) error
  242. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  243. func (f TraverseMessageRecords) Intercept(next ent.Querier) ent.Querier {
  244. return next
  245. }
  246. // Traverse calls f(ctx, q).
  247. func (f TraverseMessageRecords) Traverse(ctx context.Context, q ent.Query) error {
  248. if q, ok := q.(*ent.MessageRecordsQuery); ok {
  249. return f(ctx, q)
  250. }
  251. return fmt.Errorf("unexpected query type %T. expect *ent.MessageRecordsQuery", q)
  252. }
  253. // The MsgFunc type is an adapter to allow the use of ordinary function as a Querier.
  254. type MsgFunc func(context.Context, *ent.MsgQuery) (ent.Value, error)
  255. // Query calls f(ctx, q).
  256. func (f MsgFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  257. if q, ok := q.(*ent.MsgQuery); ok {
  258. return f(ctx, q)
  259. }
  260. return nil, fmt.Errorf("unexpected query type %T. expect *ent.MsgQuery", q)
  261. }
  262. // The TraverseMsg type is an adapter to allow the use of ordinary function as Traverser.
  263. type TraverseMsg func(context.Context, *ent.MsgQuery) error
  264. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  265. func (f TraverseMsg) Intercept(next ent.Querier) ent.Querier {
  266. return next
  267. }
  268. // Traverse calls f(ctx, q).
  269. func (f TraverseMsg) Traverse(ctx context.Context, q ent.Query) error {
  270. if q, ok := q.(*ent.MsgQuery); ok {
  271. return f(ctx, q)
  272. }
  273. return fmt.Errorf("unexpected query type %T. expect *ent.MsgQuery", q)
  274. }
  275. // The ServerFunc type is an adapter to allow the use of ordinary function as a Querier.
  276. type ServerFunc func(context.Context, *ent.ServerQuery) (ent.Value, error)
  277. // Query calls f(ctx, q).
  278. func (f ServerFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  279. if q, ok := q.(*ent.ServerQuery); ok {
  280. return f(ctx, q)
  281. }
  282. return nil, fmt.Errorf("unexpected query type %T. expect *ent.ServerQuery", q)
  283. }
  284. // The TraverseServer type is an adapter to allow the use of ordinary function as Traverser.
  285. type TraverseServer func(context.Context, *ent.ServerQuery) error
  286. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  287. func (f TraverseServer) Intercept(next ent.Querier) ent.Querier {
  288. return next
  289. }
  290. // Traverse calls f(ctx, q).
  291. func (f TraverseServer) Traverse(ctx context.Context, q ent.Query) error {
  292. if q, ok := q.(*ent.ServerQuery); ok {
  293. return f(ctx, q)
  294. }
  295. return fmt.Errorf("unexpected query type %T. expect *ent.ServerQuery", q)
  296. }
  297. // The SopNodeFunc type is an adapter to allow the use of ordinary function as a Querier.
  298. type SopNodeFunc func(context.Context, *ent.SopNodeQuery) (ent.Value, error)
  299. // Query calls f(ctx, q).
  300. func (f SopNodeFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  301. if q, ok := q.(*ent.SopNodeQuery); ok {
  302. return f(ctx, q)
  303. }
  304. return nil, fmt.Errorf("unexpected query type %T. expect *ent.SopNodeQuery", q)
  305. }
  306. // The TraverseSopNode type is an adapter to allow the use of ordinary function as Traverser.
  307. type TraverseSopNode func(context.Context, *ent.SopNodeQuery) error
  308. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  309. func (f TraverseSopNode) Intercept(next ent.Querier) ent.Querier {
  310. return next
  311. }
  312. // Traverse calls f(ctx, q).
  313. func (f TraverseSopNode) Traverse(ctx context.Context, q ent.Query) error {
  314. if q, ok := q.(*ent.SopNodeQuery); ok {
  315. return f(ctx, q)
  316. }
  317. return fmt.Errorf("unexpected query type %T. expect *ent.SopNodeQuery", q)
  318. }
  319. // The SopStageFunc type is an adapter to allow the use of ordinary function as a Querier.
  320. type SopStageFunc func(context.Context, *ent.SopStageQuery) (ent.Value, error)
  321. // Query calls f(ctx, q).
  322. func (f SopStageFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  323. if q, ok := q.(*ent.SopStageQuery); ok {
  324. return f(ctx, q)
  325. }
  326. return nil, fmt.Errorf("unexpected query type %T. expect *ent.SopStageQuery", q)
  327. }
  328. // The TraverseSopStage type is an adapter to allow the use of ordinary function as Traverser.
  329. type TraverseSopStage func(context.Context, *ent.SopStageQuery) error
  330. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  331. func (f TraverseSopStage) Intercept(next ent.Querier) ent.Querier {
  332. return next
  333. }
  334. // Traverse calls f(ctx, q).
  335. func (f TraverseSopStage) Traverse(ctx context.Context, q ent.Query) error {
  336. if q, ok := q.(*ent.SopStageQuery); ok {
  337. return f(ctx, q)
  338. }
  339. return fmt.Errorf("unexpected query type %T. expect *ent.SopStageQuery", q)
  340. }
  341. // The SopTaskFunc type is an adapter to allow the use of ordinary function as a Querier.
  342. type SopTaskFunc func(context.Context, *ent.SopTaskQuery) (ent.Value, error)
  343. // Query calls f(ctx, q).
  344. func (f SopTaskFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  345. if q, ok := q.(*ent.SopTaskQuery); ok {
  346. return f(ctx, q)
  347. }
  348. return nil, fmt.Errorf("unexpected query type %T. expect *ent.SopTaskQuery", q)
  349. }
  350. // The TraverseSopTask type is an adapter to allow the use of ordinary function as Traverser.
  351. type TraverseSopTask func(context.Context, *ent.SopTaskQuery) error
  352. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  353. func (f TraverseSopTask) Intercept(next ent.Querier) ent.Querier {
  354. return next
  355. }
  356. // Traverse calls f(ctx, q).
  357. func (f TraverseSopTask) Traverse(ctx context.Context, q ent.Query) error {
  358. if q, ok := q.(*ent.SopTaskQuery); ok {
  359. return f(ctx, q)
  360. }
  361. return fmt.Errorf("unexpected query type %T. expect *ent.SopTaskQuery", q)
  362. }
  363. // The TokenFunc type is an adapter to allow the use of ordinary function as a Querier.
  364. type TokenFunc func(context.Context, *ent.TokenQuery) (ent.Value, error)
  365. // Query calls f(ctx, q).
  366. func (f TokenFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  367. if q, ok := q.(*ent.TokenQuery); ok {
  368. return f(ctx, q)
  369. }
  370. return nil, fmt.Errorf("unexpected query type %T. expect *ent.TokenQuery", q)
  371. }
  372. // The TraverseToken type is an adapter to allow the use of ordinary function as Traverser.
  373. type TraverseToken func(context.Context, *ent.TokenQuery) error
  374. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  375. func (f TraverseToken) Intercept(next ent.Querier) ent.Querier {
  376. return next
  377. }
  378. // Traverse calls f(ctx, q).
  379. func (f TraverseToken) Traverse(ctx context.Context, q ent.Query) error {
  380. if q, ok := q.(*ent.TokenQuery); ok {
  381. return f(ctx, q)
  382. }
  383. return fmt.Errorf("unexpected query type %T. expect *ent.TokenQuery", q)
  384. }
  385. // The TutorialFunc type is an adapter to allow the use of ordinary function as a Querier.
  386. type TutorialFunc func(context.Context, *ent.TutorialQuery) (ent.Value, error)
  387. // Query calls f(ctx, q).
  388. func (f TutorialFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  389. if q, ok := q.(*ent.TutorialQuery); ok {
  390. return f(ctx, q)
  391. }
  392. return nil, fmt.Errorf("unexpected query type %T. expect *ent.TutorialQuery", q)
  393. }
  394. // The TraverseTutorial type is an adapter to allow the use of ordinary function as Traverser.
  395. type TraverseTutorial func(context.Context, *ent.TutorialQuery) error
  396. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  397. func (f TraverseTutorial) Intercept(next ent.Querier) ent.Querier {
  398. return next
  399. }
  400. // Traverse calls f(ctx, q).
  401. func (f TraverseTutorial) Traverse(ctx context.Context, q ent.Query) error {
  402. if q, ok := q.(*ent.TutorialQuery); ok {
  403. return f(ctx, q)
  404. }
  405. return fmt.Errorf("unexpected query type %T. expect *ent.TutorialQuery", q)
  406. }
  407. // The WorkExperienceFunc type is an adapter to allow the use of ordinary function as a Querier.
  408. type WorkExperienceFunc func(context.Context, *ent.WorkExperienceQuery) (ent.Value, error)
  409. // Query calls f(ctx, q).
  410. func (f WorkExperienceFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  411. if q, ok := q.(*ent.WorkExperienceQuery); ok {
  412. return f(ctx, q)
  413. }
  414. return nil, fmt.Errorf("unexpected query type %T. expect *ent.WorkExperienceQuery", q)
  415. }
  416. // The TraverseWorkExperience type is an adapter to allow the use of ordinary function as Traverser.
  417. type TraverseWorkExperience func(context.Context, *ent.WorkExperienceQuery) error
  418. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  419. func (f TraverseWorkExperience) Intercept(next ent.Querier) ent.Querier {
  420. return next
  421. }
  422. // Traverse calls f(ctx, q).
  423. func (f TraverseWorkExperience) Traverse(ctx context.Context, q ent.Query) error {
  424. if q, ok := q.(*ent.WorkExperienceQuery); ok {
  425. return f(ctx, q)
  426. }
  427. return fmt.Errorf("unexpected query type %T. expect *ent.WorkExperienceQuery", q)
  428. }
  429. // The WxFunc type is an adapter to allow the use of ordinary function as a Querier.
  430. type WxFunc func(context.Context, *ent.WxQuery) (ent.Value, error)
  431. // Query calls f(ctx, q).
  432. func (f WxFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
  433. if q, ok := q.(*ent.WxQuery); ok {
  434. return f(ctx, q)
  435. }
  436. return nil, fmt.Errorf("unexpected query type %T. expect *ent.WxQuery", q)
  437. }
  438. // The TraverseWx type is an adapter to allow the use of ordinary function as Traverser.
  439. type TraverseWx func(context.Context, *ent.WxQuery) error
  440. // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
  441. func (f TraverseWx) Intercept(next ent.Querier) ent.Querier {
  442. return next
  443. }
  444. // Traverse calls f(ctx, q).
  445. func (f TraverseWx) Traverse(ctx context.Context, q ent.Query) error {
  446. if q, ok := q.(*ent.WxQuery); ok {
  447. return f(ctx, q)
  448. }
  449. return fmt.Errorf("unexpected query type %T. expect *ent.WxQuery", q)
  450. }
  451. // NewQuery returns the generic Query interface for the given typed query.
  452. func NewQuery(q ent.Query) (Query, error) {
  453. switch q := q.(type) {
  454. case *ent.AgentQuery:
  455. return &query[*ent.AgentQuery, predicate.Agent, agent.OrderOption]{typ: ent.TypeAgent, tq: q}, nil
  456. case *ent.BatchMsgQuery:
  457. return &query[*ent.BatchMsgQuery, predicate.BatchMsg, batchmsg.OrderOption]{typ: ent.TypeBatchMsg, tq: q}, nil
  458. case *ent.ContactQuery:
  459. return &query[*ent.ContactQuery, predicate.Contact, contact.OrderOption]{typ: ent.TypeContact, tq: q}, nil
  460. case *ent.EmployeeQuery:
  461. return &query[*ent.EmployeeQuery, predicate.Employee, employee.OrderOption]{typ: ent.TypeEmployee, tq: q}, nil
  462. case *ent.LabelQuery:
  463. return &query[*ent.LabelQuery, predicate.Label, label.OrderOption]{typ: ent.TypeLabel, tq: q}, nil
  464. case *ent.LabelRelationshipQuery:
  465. return &query[*ent.LabelRelationshipQuery, predicate.LabelRelationship, labelrelationship.OrderOption]{typ: ent.TypeLabelRelationship, tq: q}, nil
  466. case *ent.MessageQuery:
  467. return &query[*ent.MessageQuery, predicate.Message, message.OrderOption]{typ: ent.TypeMessage, tq: q}, nil
  468. case *ent.MessageRecordsQuery:
  469. return &query[*ent.MessageRecordsQuery, predicate.MessageRecords, messagerecords.OrderOption]{typ: ent.TypeMessageRecords, tq: q}, nil
  470. case *ent.MsgQuery:
  471. return &query[*ent.MsgQuery, predicate.Msg, msg.OrderOption]{typ: ent.TypeMsg, tq: q}, nil
  472. case *ent.ServerQuery:
  473. return &query[*ent.ServerQuery, predicate.Server, server.OrderOption]{typ: ent.TypeServer, tq: q}, nil
  474. case *ent.SopNodeQuery:
  475. return &query[*ent.SopNodeQuery, predicate.SopNode, sopnode.OrderOption]{typ: ent.TypeSopNode, tq: q}, nil
  476. case *ent.SopStageQuery:
  477. return &query[*ent.SopStageQuery, predicate.SopStage, sopstage.OrderOption]{typ: ent.TypeSopStage, tq: q}, nil
  478. case *ent.SopTaskQuery:
  479. return &query[*ent.SopTaskQuery, predicate.SopTask, soptask.OrderOption]{typ: ent.TypeSopTask, tq: q}, nil
  480. case *ent.TokenQuery:
  481. return &query[*ent.TokenQuery, predicate.Token, token.OrderOption]{typ: ent.TypeToken, tq: q}, nil
  482. case *ent.TutorialQuery:
  483. return &query[*ent.TutorialQuery, predicate.Tutorial, tutorial.OrderOption]{typ: ent.TypeTutorial, tq: q}, nil
  484. case *ent.WorkExperienceQuery:
  485. return &query[*ent.WorkExperienceQuery, predicate.WorkExperience, workexperience.OrderOption]{typ: ent.TypeWorkExperience, tq: q}, nil
  486. case *ent.WxQuery:
  487. return &query[*ent.WxQuery, predicate.Wx, wx.OrderOption]{typ: ent.TypeWx, tq: q}, nil
  488. default:
  489. return nil, fmt.Errorf("unknown query type %T", q)
  490. }
  491. }
  492. type query[T any, P ~func(*sql.Selector), R ~func(*sql.Selector)] struct {
  493. typ string
  494. tq interface {
  495. Limit(int) T
  496. Offset(int) T
  497. Unique(bool) T
  498. Order(...R) T
  499. Where(...P) T
  500. }
  501. }
  502. func (q query[T, P, R]) Type() string {
  503. return q.typ
  504. }
  505. func (q query[T, P, R]) Limit(limit int) {
  506. q.tq.Limit(limit)
  507. }
  508. func (q query[T, P, R]) Offset(offset int) {
  509. q.tq.Offset(offset)
  510. }
  511. func (q query[T, P, R]) Unique(unique bool) {
  512. q.tq.Unique(unique)
  513. }
  514. func (q query[T, P, R]) Order(orders ...func(*sql.Selector)) {
  515. rs := make([]R, len(orders))
  516. for i := range orders {
  517. rs[i] = orders[i]
  518. }
  519. q.tq.Order(rs...)
  520. }
  521. func (q query[T, P, R]) WhereP(ps ...func(*sql.Selector)) {
  522. p := make([]P, len(ps))
  523. for i := range ps {
  524. p[i] = ps[i]
  525. }
  526. q.tq.Where(p...)
  527. }