intercept.go 27 KB

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