intercept.go 25 KB

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