client.go 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "log"
  8. "reflect"
  9. "wechat-api/ent/migrate"
  10. "wechat-api/ent/agent"
  11. "wechat-api/ent/batchmsg"
  12. "wechat-api/ent/contact"
  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/server"
  19. "wechat-api/ent/sopnode"
  20. "wechat-api/ent/sopstage"
  21. "wechat-api/ent/soptask"
  22. "wechat-api/ent/wx"
  23. "entgo.io/ent"
  24. "entgo.io/ent/dialect"
  25. "entgo.io/ent/dialect/sql"
  26. "entgo.io/ent/dialect/sql/sqlgraph"
  27. stdsql "database/sql"
  28. )
  29. // Client is the client that holds all ent builders.
  30. type Client struct {
  31. config
  32. // Schema is the client for creating, migrating and dropping schema.
  33. Schema *migrate.Schema
  34. // Agent is the client for interacting with the Agent builders.
  35. Agent *AgentClient
  36. // BatchMsg is the client for interacting with the BatchMsg builders.
  37. BatchMsg *BatchMsgClient
  38. // Contact is the client for interacting with the Contact builders.
  39. Contact *ContactClient
  40. // Label is the client for interacting with the Label builders.
  41. Label *LabelClient
  42. // LabelRelationship is the client for interacting with the LabelRelationship builders.
  43. LabelRelationship *LabelRelationshipClient
  44. // Message is the client for interacting with the Message builders.
  45. Message *MessageClient
  46. // MessageRecords is the client for interacting with the MessageRecords builders.
  47. MessageRecords *MessageRecordsClient
  48. // Msg is the client for interacting with the Msg builders.
  49. Msg *MsgClient
  50. // Server is the client for interacting with the Server builders.
  51. Server *ServerClient
  52. // SopNode is the client for interacting with the SopNode builders.
  53. SopNode *SopNodeClient
  54. // SopStage is the client for interacting with the SopStage builders.
  55. SopStage *SopStageClient
  56. // SopTask is the client for interacting with the SopTask builders.
  57. SopTask *SopTaskClient
  58. // Wx is the client for interacting with the Wx builders.
  59. Wx *WxClient
  60. }
  61. // NewClient creates a new client configured with the given options.
  62. func NewClient(opts ...Option) *Client {
  63. client := &Client{config: newConfig(opts...)}
  64. client.init()
  65. return client
  66. }
  67. func (c *Client) init() {
  68. c.Schema = migrate.NewSchema(c.driver)
  69. c.Agent = NewAgentClient(c.config)
  70. c.BatchMsg = NewBatchMsgClient(c.config)
  71. c.Contact = NewContactClient(c.config)
  72. c.Label = NewLabelClient(c.config)
  73. c.LabelRelationship = NewLabelRelationshipClient(c.config)
  74. c.Message = NewMessageClient(c.config)
  75. c.MessageRecords = NewMessageRecordsClient(c.config)
  76. c.Msg = NewMsgClient(c.config)
  77. c.Server = NewServerClient(c.config)
  78. c.SopNode = NewSopNodeClient(c.config)
  79. c.SopStage = NewSopStageClient(c.config)
  80. c.SopTask = NewSopTaskClient(c.config)
  81. c.Wx = NewWxClient(c.config)
  82. }
  83. type (
  84. // config is the configuration for the client and its builder.
  85. config struct {
  86. // driver used for executing database requests.
  87. driver dialect.Driver
  88. // debug enable a debug logging.
  89. debug bool
  90. // log used for logging on debug mode.
  91. log func(...any)
  92. // hooks to execute on mutations.
  93. hooks *hooks
  94. // interceptors to execute on queries.
  95. inters *inters
  96. }
  97. // Option function to configure the client.
  98. Option func(*config)
  99. )
  100. // newConfig creates a new config for the client.
  101. func newConfig(opts ...Option) config {
  102. cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
  103. cfg.options(opts...)
  104. return cfg
  105. }
  106. // options applies the options on the config object.
  107. func (c *config) options(opts ...Option) {
  108. for _, opt := range opts {
  109. opt(c)
  110. }
  111. if c.debug {
  112. c.driver = dialect.Debug(c.driver, c.log)
  113. }
  114. }
  115. // Debug enables debug logging on the ent.Driver.
  116. func Debug() Option {
  117. return func(c *config) {
  118. c.debug = true
  119. }
  120. }
  121. // Log sets the logging function for debug mode.
  122. func Log(fn func(...any)) Option {
  123. return func(c *config) {
  124. c.log = fn
  125. }
  126. }
  127. // Driver configures the client driver.
  128. func Driver(driver dialect.Driver) Option {
  129. return func(c *config) {
  130. c.driver = driver
  131. }
  132. }
  133. // Open opens a database/sql.DB specified by the driver name and
  134. // the data source name, and returns a new client attached to it.
  135. // Optional parameters can be added for configuring the client.
  136. func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
  137. switch driverName {
  138. case dialect.MySQL, dialect.Postgres, dialect.SQLite:
  139. drv, err := sql.Open(driverName, dataSourceName)
  140. if err != nil {
  141. return nil, err
  142. }
  143. return NewClient(append(options, Driver(drv))...), nil
  144. default:
  145. return nil, fmt.Errorf("unsupported driver: %q", driverName)
  146. }
  147. }
  148. // ErrTxStarted is returned when trying to start a new transaction from a transactional client.
  149. var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction")
  150. // Tx returns a new transactional client. The provided context
  151. // is used until the transaction is committed or rolled back.
  152. func (c *Client) Tx(ctx context.Context) (*Tx, error) {
  153. if _, ok := c.driver.(*txDriver); ok {
  154. return nil, ErrTxStarted
  155. }
  156. tx, err := newTx(ctx, c.driver)
  157. if err != nil {
  158. return nil, fmt.Errorf("ent: starting a transaction: %w", err)
  159. }
  160. cfg := c.config
  161. cfg.driver = tx
  162. return &Tx{
  163. ctx: ctx,
  164. config: cfg,
  165. Agent: NewAgentClient(cfg),
  166. BatchMsg: NewBatchMsgClient(cfg),
  167. Contact: NewContactClient(cfg),
  168. Label: NewLabelClient(cfg),
  169. LabelRelationship: NewLabelRelationshipClient(cfg),
  170. Message: NewMessageClient(cfg),
  171. MessageRecords: NewMessageRecordsClient(cfg),
  172. Msg: NewMsgClient(cfg),
  173. Server: NewServerClient(cfg),
  174. SopNode: NewSopNodeClient(cfg),
  175. SopStage: NewSopStageClient(cfg),
  176. SopTask: NewSopTaskClient(cfg),
  177. Wx: NewWxClient(cfg),
  178. }, nil
  179. }
  180. // BeginTx returns a transactional client with specified options.
  181. func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
  182. if _, ok := c.driver.(*txDriver); ok {
  183. return nil, errors.New("ent: cannot start a transaction within a transaction")
  184. }
  185. tx, err := c.driver.(interface {
  186. BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)
  187. }).BeginTx(ctx, opts)
  188. if err != nil {
  189. return nil, fmt.Errorf("ent: starting a transaction: %w", err)
  190. }
  191. cfg := c.config
  192. cfg.driver = &txDriver{tx: tx, drv: c.driver}
  193. return &Tx{
  194. ctx: ctx,
  195. config: cfg,
  196. Agent: NewAgentClient(cfg),
  197. BatchMsg: NewBatchMsgClient(cfg),
  198. Contact: NewContactClient(cfg),
  199. Label: NewLabelClient(cfg),
  200. LabelRelationship: NewLabelRelationshipClient(cfg),
  201. Message: NewMessageClient(cfg),
  202. MessageRecords: NewMessageRecordsClient(cfg),
  203. Msg: NewMsgClient(cfg),
  204. Server: NewServerClient(cfg),
  205. SopNode: NewSopNodeClient(cfg),
  206. SopStage: NewSopStageClient(cfg),
  207. SopTask: NewSopTaskClient(cfg),
  208. Wx: NewWxClient(cfg),
  209. }, nil
  210. }
  211. // Debug returns a new debug-client. It's used to get verbose logging on specific operations.
  212. //
  213. // client.Debug().
  214. // Agent.
  215. // Query().
  216. // Count(ctx)
  217. func (c *Client) Debug() *Client {
  218. if c.debug {
  219. return c
  220. }
  221. cfg := c.config
  222. cfg.driver = dialect.Debug(c.driver, c.log)
  223. client := &Client{config: cfg}
  224. client.init()
  225. return client
  226. }
  227. // Close closes the database connection and prevents new queries from starting.
  228. func (c *Client) Close() error {
  229. return c.driver.Close()
  230. }
  231. // Use adds the mutation hooks to all the entity clients.
  232. // In order to add hooks to a specific client, call: `client.Node.Use(...)`.
  233. func (c *Client) Use(hooks ...Hook) {
  234. for _, n := range []interface{ Use(...Hook) }{
  235. c.Agent, c.BatchMsg, c.Contact, c.Label, c.LabelRelationship, c.Message,
  236. c.MessageRecords, c.Msg, c.Server, c.SopNode, c.SopStage, c.SopTask, c.Wx,
  237. } {
  238. n.Use(hooks...)
  239. }
  240. }
  241. // Intercept adds the query interceptors to all the entity clients.
  242. // In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
  243. func (c *Client) Intercept(interceptors ...Interceptor) {
  244. for _, n := range []interface{ Intercept(...Interceptor) }{
  245. c.Agent, c.BatchMsg, c.Contact, c.Label, c.LabelRelationship, c.Message,
  246. c.MessageRecords, c.Msg, c.Server, c.SopNode, c.SopStage, c.SopTask, c.Wx,
  247. } {
  248. n.Intercept(interceptors...)
  249. }
  250. }
  251. // Mutate implements the ent.Mutator interface.
  252. func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
  253. switch m := m.(type) {
  254. case *AgentMutation:
  255. return c.Agent.mutate(ctx, m)
  256. case *BatchMsgMutation:
  257. return c.BatchMsg.mutate(ctx, m)
  258. case *ContactMutation:
  259. return c.Contact.mutate(ctx, m)
  260. case *LabelMutation:
  261. return c.Label.mutate(ctx, m)
  262. case *LabelRelationshipMutation:
  263. return c.LabelRelationship.mutate(ctx, m)
  264. case *MessageMutation:
  265. return c.Message.mutate(ctx, m)
  266. case *MessageRecordsMutation:
  267. return c.MessageRecords.mutate(ctx, m)
  268. case *MsgMutation:
  269. return c.Msg.mutate(ctx, m)
  270. case *ServerMutation:
  271. return c.Server.mutate(ctx, m)
  272. case *SopNodeMutation:
  273. return c.SopNode.mutate(ctx, m)
  274. case *SopStageMutation:
  275. return c.SopStage.mutate(ctx, m)
  276. case *SopTaskMutation:
  277. return c.SopTask.mutate(ctx, m)
  278. case *WxMutation:
  279. return c.Wx.mutate(ctx, m)
  280. default:
  281. return nil, fmt.Errorf("ent: unknown mutation type %T", m)
  282. }
  283. }
  284. // AgentClient is a client for the Agent schema.
  285. type AgentClient struct {
  286. config
  287. }
  288. // NewAgentClient returns a client for the Agent from the given config.
  289. func NewAgentClient(c config) *AgentClient {
  290. return &AgentClient{config: c}
  291. }
  292. // Use adds a list of mutation hooks to the hooks stack.
  293. // A call to `Use(f, g, h)` equals to `agent.Hooks(f(g(h())))`.
  294. func (c *AgentClient) Use(hooks ...Hook) {
  295. c.hooks.Agent = append(c.hooks.Agent, hooks...)
  296. }
  297. // Intercept adds a list of query interceptors to the interceptors stack.
  298. // A call to `Intercept(f, g, h)` equals to `agent.Intercept(f(g(h())))`.
  299. func (c *AgentClient) Intercept(interceptors ...Interceptor) {
  300. c.inters.Agent = append(c.inters.Agent, interceptors...)
  301. }
  302. // Create returns a builder for creating a Agent entity.
  303. func (c *AgentClient) Create() *AgentCreate {
  304. mutation := newAgentMutation(c.config, OpCreate)
  305. return &AgentCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  306. }
  307. // CreateBulk returns a builder for creating a bulk of Agent entities.
  308. func (c *AgentClient) CreateBulk(builders ...*AgentCreate) *AgentCreateBulk {
  309. return &AgentCreateBulk{config: c.config, builders: builders}
  310. }
  311. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  312. // a builder and applies setFunc on it.
  313. func (c *AgentClient) MapCreateBulk(slice any, setFunc func(*AgentCreate, int)) *AgentCreateBulk {
  314. rv := reflect.ValueOf(slice)
  315. if rv.Kind() != reflect.Slice {
  316. return &AgentCreateBulk{err: fmt.Errorf("calling to AgentClient.MapCreateBulk with wrong type %T, need slice", slice)}
  317. }
  318. builders := make([]*AgentCreate, rv.Len())
  319. for i := 0; i < rv.Len(); i++ {
  320. builders[i] = c.Create()
  321. setFunc(builders[i], i)
  322. }
  323. return &AgentCreateBulk{config: c.config, builders: builders}
  324. }
  325. // Update returns an update builder for Agent.
  326. func (c *AgentClient) Update() *AgentUpdate {
  327. mutation := newAgentMutation(c.config, OpUpdate)
  328. return &AgentUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  329. }
  330. // UpdateOne returns an update builder for the given entity.
  331. func (c *AgentClient) UpdateOne(a *Agent) *AgentUpdateOne {
  332. mutation := newAgentMutation(c.config, OpUpdateOne, withAgent(a))
  333. return &AgentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  334. }
  335. // UpdateOneID returns an update builder for the given id.
  336. func (c *AgentClient) UpdateOneID(id uint64) *AgentUpdateOne {
  337. mutation := newAgentMutation(c.config, OpUpdateOne, withAgentID(id))
  338. return &AgentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  339. }
  340. // Delete returns a delete builder for Agent.
  341. func (c *AgentClient) Delete() *AgentDelete {
  342. mutation := newAgentMutation(c.config, OpDelete)
  343. return &AgentDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  344. }
  345. // DeleteOne returns a builder for deleting the given entity.
  346. func (c *AgentClient) DeleteOne(a *Agent) *AgentDeleteOne {
  347. return c.DeleteOneID(a.ID)
  348. }
  349. // DeleteOneID returns a builder for deleting the given entity by its id.
  350. func (c *AgentClient) DeleteOneID(id uint64) *AgentDeleteOne {
  351. builder := c.Delete().Where(agent.ID(id))
  352. builder.mutation.id = &id
  353. builder.mutation.op = OpDeleteOne
  354. return &AgentDeleteOne{builder}
  355. }
  356. // Query returns a query builder for Agent.
  357. func (c *AgentClient) Query() *AgentQuery {
  358. return &AgentQuery{
  359. config: c.config,
  360. ctx: &QueryContext{Type: TypeAgent},
  361. inters: c.Interceptors(),
  362. }
  363. }
  364. // Get returns a Agent entity by its id.
  365. func (c *AgentClient) Get(ctx context.Context, id uint64) (*Agent, error) {
  366. return c.Query().Where(agent.ID(id)).Only(ctx)
  367. }
  368. // GetX is like Get, but panics if an error occurs.
  369. func (c *AgentClient) GetX(ctx context.Context, id uint64) *Agent {
  370. obj, err := c.Get(ctx, id)
  371. if err != nil {
  372. panic(err)
  373. }
  374. return obj
  375. }
  376. // Hooks returns the client hooks.
  377. func (c *AgentClient) Hooks() []Hook {
  378. hooks := c.hooks.Agent
  379. return append(hooks[:len(hooks):len(hooks)], agent.Hooks[:]...)
  380. }
  381. // Interceptors returns the client interceptors.
  382. func (c *AgentClient) Interceptors() []Interceptor {
  383. inters := c.inters.Agent
  384. return append(inters[:len(inters):len(inters)], agent.Interceptors[:]...)
  385. }
  386. func (c *AgentClient) mutate(ctx context.Context, m *AgentMutation) (Value, error) {
  387. switch m.Op() {
  388. case OpCreate:
  389. return (&AgentCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  390. case OpUpdate:
  391. return (&AgentUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  392. case OpUpdateOne:
  393. return (&AgentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  394. case OpDelete, OpDeleteOne:
  395. return (&AgentDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  396. default:
  397. return nil, fmt.Errorf("ent: unknown Agent mutation op: %q", m.Op())
  398. }
  399. }
  400. // BatchMsgClient is a client for the BatchMsg schema.
  401. type BatchMsgClient struct {
  402. config
  403. }
  404. // NewBatchMsgClient returns a client for the BatchMsg from the given config.
  405. func NewBatchMsgClient(c config) *BatchMsgClient {
  406. return &BatchMsgClient{config: c}
  407. }
  408. // Use adds a list of mutation hooks to the hooks stack.
  409. // A call to `Use(f, g, h)` equals to `batchmsg.Hooks(f(g(h())))`.
  410. func (c *BatchMsgClient) Use(hooks ...Hook) {
  411. c.hooks.BatchMsg = append(c.hooks.BatchMsg, hooks...)
  412. }
  413. // Intercept adds a list of query interceptors to the interceptors stack.
  414. // A call to `Intercept(f, g, h)` equals to `batchmsg.Intercept(f(g(h())))`.
  415. func (c *BatchMsgClient) Intercept(interceptors ...Interceptor) {
  416. c.inters.BatchMsg = append(c.inters.BatchMsg, interceptors...)
  417. }
  418. // Create returns a builder for creating a BatchMsg entity.
  419. func (c *BatchMsgClient) Create() *BatchMsgCreate {
  420. mutation := newBatchMsgMutation(c.config, OpCreate)
  421. return &BatchMsgCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  422. }
  423. // CreateBulk returns a builder for creating a bulk of BatchMsg entities.
  424. func (c *BatchMsgClient) CreateBulk(builders ...*BatchMsgCreate) *BatchMsgCreateBulk {
  425. return &BatchMsgCreateBulk{config: c.config, builders: builders}
  426. }
  427. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  428. // a builder and applies setFunc on it.
  429. func (c *BatchMsgClient) MapCreateBulk(slice any, setFunc func(*BatchMsgCreate, int)) *BatchMsgCreateBulk {
  430. rv := reflect.ValueOf(slice)
  431. if rv.Kind() != reflect.Slice {
  432. return &BatchMsgCreateBulk{err: fmt.Errorf("calling to BatchMsgClient.MapCreateBulk with wrong type %T, need slice", slice)}
  433. }
  434. builders := make([]*BatchMsgCreate, rv.Len())
  435. for i := 0; i < rv.Len(); i++ {
  436. builders[i] = c.Create()
  437. setFunc(builders[i], i)
  438. }
  439. return &BatchMsgCreateBulk{config: c.config, builders: builders}
  440. }
  441. // Update returns an update builder for BatchMsg.
  442. func (c *BatchMsgClient) Update() *BatchMsgUpdate {
  443. mutation := newBatchMsgMutation(c.config, OpUpdate)
  444. return &BatchMsgUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  445. }
  446. // UpdateOne returns an update builder for the given entity.
  447. func (c *BatchMsgClient) UpdateOne(bm *BatchMsg) *BatchMsgUpdateOne {
  448. mutation := newBatchMsgMutation(c.config, OpUpdateOne, withBatchMsg(bm))
  449. return &BatchMsgUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  450. }
  451. // UpdateOneID returns an update builder for the given id.
  452. func (c *BatchMsgClient) UpdateOneID(id uint64) *BatchMsgUpdateOne {
  453. mutation := newBatchMsgMutation(c.config, OpUpdateOne, withBatchMsgID(id))
  454. return &BatchMsgUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  455. }
  456. // Delete returns a delete builder for BatchMsg.
  457. func (c *BatchMsgClient) Delete() *BatchMsgDelete {
  458. mutation := newBatchMsgMutation(c.config, OpDelete)
  459. return &BatchMsgDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  460. }
  461. // DeleteOne returns a builder for deleting the given entity.
  462. func (c *BatchMsgClient) DeleteOne(bm *BatchMsg) *BatchMsgDeleteOne {
  463. return c.DeleteOneID(bm.ID)
  464. }
  465. // DeleteOneID returns a builder for deleting the given entity by its id.
  466. func (c *BatchMsgClient) DeleteOneID(id uint64) *BatchMsgDeleteOne {
  467. builder := c.Delete().Where(batchmsg.ID(id))
  468. builder.mutation.id = &id
  469. builder.mutation.op = OpDeleteOne
  470. return &BatchMsgDeleteOne{builder}
  471. }
  472. // Query returns a query builder for BatchMsg.
  473. func (c *BatchMsgClient) Query() *BatchMsgQuery {
  474. return &BatchMsgQuery{
  475. config: c.config,
  476. ctx: &QueryContext{Type: TypeBatchMsg},
  477. inters: c.Interceptors(),
  478. }
  479. }
  480. // Get returns a BatchMsg entity by its id.
  481. func (c *BatchMsgClient) Get(ctx context.Context, id uint64) (*BatchMsg, error) {
  482. return c.Query().Where(batchmsg.ID(id)).Only(ctx)
  483. }
  484. // GetX is like Get, but panics if an error occurs.
  485. func (c *BatchMsgClient) GetX(ctx context.Context, id uint64) *BatchMsg {
  486. obj, err := c.Get(ctx, id)
  487. if err != nil {
  488. panic(err)
  489. }
  490. return obj
  491. }
  492. // Hooks returns the client hooks.
  493. func (c *BatchMsgClient) Hooks() []Hook {
  494. hooks := c.hooks.BatchMsg
  495. return append(hooks[:len(hooks):len(hooks)], batchmsg.Hooks[:]...)
  496. }
  497. // Interceptors returns the client interceptors.
  498. func (c *BatchMsgClient) Interceptors() []Interceptor {
  499. inters := c.inters.BatchMsg
  500. return append(inters[:len(inters):len(inters)], batchmsg.Interceptors[:]...)
  501. }
  502. func (c *BatchMsgClient) mutate(ctx context.Context, m *BatchMsgMutation) (Value, error) {
  503. switch m.Op() {
  504. case OpCreate:
  505. return (&BatchMsgCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  506. case OpUpdate:
  507. return (&BatchMsgUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  508. case OpUpdateOne:
  509. return (&BatchMsgUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  510. case OpDelete, OpDeleteOne:
  511. return (&BatchMsgDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  512. default:
  513. return nil, fmt.Errorf("ent: unknown BatchMsg mutation op: %q", m.Op())
  514. }
  515. }
  516. // ContactClient is a client for the Contact schema.
  517. type ContactClient struct {
  518. config
  519. }
  520. // NewContactClient returns a client for the Contact from the given config.
  521. func NewContactClient(c config) *ContactClient {
  522. return &ContactClient{config: c}
  523. }
  524. // Use adds a list of mutation hooks to the hooks stack.
  525. // A call to `Use(f, g, h)` equals to `contact.Hooks(f(g(h())))`.
  526. func (c *ContactClient) Use(hooks ...Hook) {
  527. c.hooks.Contact = append(c.hooks.Contact, hooks...)
  528. }
  529. // Intercept adds a list of query interceptors to the interceptors stack.
  530. // A call to `Intercept(f, g, h)` equals to `contact.Intercept(f(g(h())))`.
  531. func (c *ContactClient) Intercept(interceptors ...Interceptor) {
  532. c.inters.Contact = append(c.inters.Contact, interceptors...)
  533. }
  534. // Create returns a builder for creating a Contact entity.
  535. func (c *ContactClient) Create() *ContactCreate {
  536. mutation := newContactMutation(c.config, OpCreate)
  537. return &ContactCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  538. }
  539. // CreateBulk returns a builder for creating a bulk of Contact entities.
  540. func (c *ContactClient) CreateBulk(builders ...*ContactCreate) *ContactCreateBulk {
  541. return &ContactCreateBulk{config: c.config, builders: builders}
  542. }
  543. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  544. // a builder and applies setFunc on it.
  545. func (c *ContactClient) MapCreateBulk(slice any, setFunc func(*ContactCreate, int)) *ContactCreateBulk {
  546. rv := reflect.ValueOf(slice)
  547. if rv.Kind() != reflect.Slice {
  548. return &ContactCreateBulk{err: fmt.Errorf("calling to ContactClient.MapCreateBulk with wrong type %T, need slice", slice)}
  549. }
  550. builders := make([]*ContactCreate, rv.Len())
  551. for i := 0; i < rv.Len(); i++ {
  552. builders[i] = c.Create()
  553. setFunc(builders[i], i)
  554. }
  555. return &ContactCreateBulk{config: c.config, builders: builders}
  556. }
  557. // Update returns an update builder for Contact.
  558. func (c *ContactClient) Update() *ContactUpdate {
  559. mutation := newContactMutation(c.config, OpUpdate)
  560. return &ContactUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  561. }
  562. // UpdateOne returns an update builder for the given entity.
  563. func (c *ContactClient) UpdateOne(co *Contact) *ContactUpdateOne {
  564. mutation := newContactMutation(c.config, OpUpdateOne, withContact(co))
  565. return &ContactUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  566. }
  567. // UpdateOneID returns an update builder for the given id.
  568. func (c *ContactClient) UpdateOneID(id uint64) *ContactUpdateOne {
  569. mutation := newContactMutation(c.config, OpUpdateOne, withContactID(id))
  570. return &ContactUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  571. }
  572. // Delete returns a delete builder for Contact.
  573. func (c *ContactClient) Delete() *ContactDelete {
  574. mutation := newContactMutation(c.config, OpDelete)
  575. return &ContactDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  576. }
  577. // DeleteOne returns a builder for deleting the given entity.
  578. func (c *ContactClient) DeleteOne(co *Contact) *ContactDeleteOne {
  579. return c.DeleteOneID(co.ID)
  580. }
  581. // DeleteOneID returns a builder for deleting the given entity by its id.
  582. func (c *ContactClient) DeleteOneID(id uint64) *ContactDeleteOne {
  583. builder := c.Delete().Where(contact.ID(id))
  584. builder.mutation.id = &id
  585. builder.mutation.op = OpDeleteOne
  586. return &ContactDeleteOne{builder}
  587. }
  588. // Query returns a query builder for Contact.
  589. func (c *ContactClient) Query() *ContactQuery {
  590. return &ContactQuery{
  591. config: c.config,
  592. ctx: &QueryContext{Type: TypeContact},
  593. inters: c.Interceptors(),
  594. }
  595. }
  596. // Get returns a Contact entity by its id.
  597. func (c *ContactClient) Get(ctx context.Context, id uint64) (*Contact, error) {
  598. return c.Query().Where(contact.ID(id)).Only(ctx)
  599. }
  600. // GetX is like Get, but panics if an error occurs.
  601. func (c *ContactClient) GetX(ctx context.Context, id uint64) *Contact {
  602. obj, err := c.Get(ctx, id)
  603. if err != nil {
  604. panic(err)
  605. }
  606. return obj
  607. }
  608. // QueryContactRelationships queries the contact_relationships edge of a Contact.
  609. func (c *ContactClient) QueryContactRelationships(co *Contact) *LabelRelationshipQuery {
  610. query := (&LabelRelationshipClient{config: c.config}).Query()
  611. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  612. id := co.ID
  613. step := sqlgraph.NewStep(
  614. sqlgraph.From(contact.Table, contact.FieldID, id),
  615. sqlgraph.To(labelrelationship.Table, labelrelationship.FieldID),
  616. sqlgraph.Edge(sqlgraph.O2M, false, contact.ContactRelationshipsTable, contact.ContactRelationshipsColumn),
  617. )
  618. fromV = sqlgraph.Neighbors(co.driver.Dialect(), step)
  619. return fromV, nil
  620. }
  621. return query
  622. }
  623. // QueryContactMessages queries the contact_messages edge of a Contact.
  624. func (c *ContactClient) QueryContactMessages(co *Contact) *MessageRecordsQuery {
  625. query := (&MessageRecordsClient{config: c.config}).Query()
  626. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  627. id := co.ID
  628. step := sqlgraph.NewStep(
  629. sqlgraph.From(contact.Table, contact.FieldID, id),
  630. sqlgraph.To(messagerecords.Table, messagerecords.FieldID),
  631. sqlgraph.Edge(sqlgraph.O2M, false, contact.ContactMessagesTable, contact.ContactMessagesColumn),
  632. )
  633. fromV = sqlgraph.Neighbors(co.driver.Dialect(), step)
  634. return fromV, nil
  635. }
  636. return query
  637. }
  638. // Hooks returns the client hooks.
  639. func (c *ContactClient) Hooks() []Hook {
  640. hooks := c.hooks.Contact
  641. return append(hooks[:len(hooks):len(hooks)], contact.Hooks[:]...)
  642. }
  643. // Interceptors returns the client interceptors.
  644. func (c *ContactClient) Interceptors() []Interceptor {
  645. inters := c.inters.Contact
  646. return append(inters[:len(inters):len(inters)], contact.Interceptors[:]...)
  647. }
  648. func (c *ContactClient) mutate(ctx context.Context, m *ContactMutation) (Value, error) {
  649. switch m.Op() {
  650. case OpCreate:
  651. return (&ContactCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  652. case OpUpdate:
  653. return (&ContactUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  654. case OpUpdateOne:
  655. return (&ContactUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  656. case OpDelete, OpDeleteOne:
  657. return (&ContactDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  658. default:
  659. return nil, fmt.Errorf("ent: unknown Contact mutation op: %q", m.Op())
  660. }
  661. }
  662. // LabelClient is a client for the Label schema.
  663. type LabelClient struct {
  664. config
  665. }
  666. // NewLabelClient returns a client for the Label from the given config.
  667. func NewLabelClient(c config) *LabelClient {
  668. return &LabelClient{config: c}
  669. }
  670. // Use adds a list of mutation hooks to the hooks stack.
  671. // A call to `Use(f, g, h)` equals to `label.Hooks(f(g(h())))`.
  672. func (c *LabelClient) Use(hooks ...Hook) {
  673. c.hooks.Label = append(c.hooks.Label, hooks...)
  674. }
  675. // Intercept adds a list of query interceptors to the interceptors stack.
  676. // A call to `Intercept(f, g, h)` equals to `label.Intercept(f(g(h())))`.
  677. func (c *LabelClient) Intercept(interceptors ...Interceptor) {
  678. c.inters.Label = append(c.inters.Label, interceptors...)
  679. }
  680. // Create returns a builder for creating a Label entity.
  681. func (c *LabelClient) Create() *LabelCreate {
  682. mutation := newLabelMutation(c.config, OpCreate)
  683. return &LabelCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  684. }
  685. // CreateBulk returns a builder for creating a bulk of Label entities.
  686. func (c *LabelClient) CreateBulk(builders ...*LabelCreate) *LabelCreateBulk {
  687. return &LabelCreateBulk{config: c.config, builders: builders}
  688. }
  689. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  690. // a builder and applies setFunc on it.
  691. func (c *LabelClient) MapCreateBulk(slice any, setFunc func(*LabelCreate, int)) *LabelCreateBulk {
  692. rv := reflect.ValueOf(slice)
  693. if rv.Kind() != reflect.Slice {
  694. return &LabelCreateBulk{err: fmt.Errorf("calling to LabelClient.MapCreateBulk with wrong type %T, need slice", slice)}
  695. }
  696. builders := make([]*LabelCreate, rv.Len())
  697. for i := 0; i < rv.Len(); i++ {
  698. builders[i] = c.Create()
  699. setFunc(builders[i], i)
  700. }
  701. return &LabelCreateBulk{config: c.config, builders: builders}
  702. }
  703. // Update returns an update builder for Label.
  704. func (c *LabelClient) Update() *LabelUpdate {
  705. mutation := newLabelMutation(c.config, OpUpdate)
  706. return &LabelUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  707. }
  708. // UpdateOne returns an update builder for the given entity.
  709. func (c *LabelClient) UpdateOne(l *Label) *LabelUpdateOne {
  710. mutation := newLabelMutation(c.config, OpUpdateOne, withLabel(l))
  711. return &LabelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  712. }
  713. // UpdateOneID returns an update builder for the given id.
  714. func (c *LabelClient) UpdateOneID(id uint64) *LabelUpdateOne {
  715. mutation := newLabelMutation(c.config, OpUpdateOne, withLabelID(id))
  716. return &LabelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  717. }
  718. // Delete returns a delete builder for Label.
  719. func (c *LabelClient) Delete() *LabelDelete {
  720. mutation := newLabelMutation(c.config, OpDelete)
  721. return &LabelDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  722. }
  723. // DeleteOne returns a builder for deleting the given entity.
  724. func (c *LabelClient) DeleteOne(l *Label) *LabelDeleteOne {
  725. return c.DeleteOneID(l.ID)
  726. }
  727. // DeleteOneID returns a builder for deleting the given entity by its id.
  728. func (c *LabelClient) DeleteOneID(id uint64) *LabelDeleteOne {
  729. builder := c.Delete().Where(label.ID(id))
  730. builder.mutation.id = &id
  731. builder.mutation.op = OpDeleteOne
  732. return &LabelDeleteOne{builder}
  733. }
  734. // Query returns a query builder for Label.
  735. func (c *LabelClient) Query() *LabelQuery {
  736. return &LabelQuery{
  737. config: c.config,
  738. ctx: &QueryContext{Type: TypeLabel},
  739. inters: c.Interceptors(),
  740. }
  741. }
  742. // Get returns a Label entity by its id.
  743. func (c *LabelClient) Get(ctx context.Context, id uint64) (*Label, error) {
  744. return c.Query().Where(label.ID(id)).Only(ctx)
  745. }
  746. // GetX is like Get, but panics if an error occurs.
  747. func (c *LabelClient) GetX(ctx context.Context, id uint64) *Label {
  748. obj, err := c.Get(ctx, id)
  749. if err != nil {
  750. panic(err)
  751. }
  752. return obj
  753. }
  754. // QueryLabelRelationships queries the label_relationships edge of a Label.
  755. func (c *LabelClient) QueryLabelRelationships(l *Label) *LabelRelationshipQuery {
  756. query := (&LabelRelationshipClient{config: c.config}).Query()
  757. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  758. id := l.ID
  759. step := sqlgraph.NewStep(
  760. sqlgraph.From(label.Table, label.FieldID, id),
  761. sqlgraph.To(labelrelationship.Table, labelrelationship.FieldID),
  762. sqlgraph.Edge(sqlgraph.O2M, false, label.LabelRelationshipsTable, label.LabelRelationshipsColumn),
  763. )
  764. fromV = sqlgraph.Neighbors(l.driver.Dialect(), step)
  765. return fromV, nil
  766. }
  767. return query
  768. }
  769. // Hooks returns the client hooks.
  770. func (c *LabelClient) Hooks() []Hook {
  771. return c.hooks.Label
  772. }
  773. // Interceptors returns the client interceptors.
  774. func (c *LabelClient) Interceptors() []Interceptor {
  775. return c.inters.Label
  776. }
  777. func (c *LabelClient) mutate(ctx context.Context, m *LabelMutation) (Value, error) {
  778. switch m.Op() {
  779. case OpCreate:
  780. return (&LabelCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  781. case OpUpdate:
  782. return (&LabelUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  783. case OpUpdateOne:
  784. return (&LabelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  785. case OpDelete, OpDeleteOne:
  786. return (&LabelDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  787. default:
  788. return nil, fmt.Errorf("ent: unknown Label mutation op: %q", m.Op())
  789. }
  790. }
  791. // LabelRelationshipClient is a client for the LabelRelationship schema.
  792. type LabelRelationshipClient struct {
  793. config
  794. }
  795. // NewLabelRelationshipClient returns a client for the LabelRelationship from the given config.
  796. func NewLabelRelationshipClient(c config) *LabelRelationshipClient {
  797. return &LabelRelationshipClient{config: c}
  798. }
  799. // Use adds a list of mutation hooks to the hooks stack.
  800. // A call to `Use(f, g, h)` equals to `labelrelationship.Hooks(f(g(h())))`.
  801. func (c *LabelRelationshipClient) Use(hooks ...Hook) {
  802. c.hooks.LabelRelationship = append(c.hooks.LabelRelationship, hooks...)
  803. }
  804. // Intercept adds a list of query interceptors to the interceptors stack.
  805. // A call to `Intercept(f, g, h)` equals to `labelrelationship.Intercept(f(g(h())))`.
  806. func (c *LabelRelationshipClient) Intercept(interceptors ...Interceptor) {
  807. c.inters.LabelRelationship = append(c.inters.LabelRelationship, interceptors...)
  808. }
  809. // Create returns a builder for creating a LabelRelationship entity.
  810. func (c *LabelRelationshipClient) Create() *LabelRelationshipCreate {
  811. mutation := newLabelRelationshipMutation(c.config, OpCreate)
  812. return &LabelRelationshipCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  813. }
  814. // CreateBulk returns a builder for creating a bulk of LabelRelationship entities.
  815. func (c *LabelRelationshipClient) CreateBulk(builders ...*LabelRelationshipCreate) *LabelRelationshipCreateBulk {
  816. return &LabelRelationshipCreateBulk{config: c.config, builders: builders}
  817. }
  818. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  819. // a builder and applies setFunc on it.
  820. func (c *LabelRelationshipClient) MapCreateBulk(slice any, setFunc func(*LabelRelationshipCreate, int)) *LabelRelationshipCreateBulk {
  821. rv := reflect.ValueOf(slice)
  822. if rv.Kind() != reflect.Slice {
  823. return &LabelRelationshipCreateBulk{err: fmt.Errorf("calling to LabelRelationshipClient.MapCreateBulk with wrong type %T, need slice", slice)}
  824. }
  825. builders := make([]*LabelRelationshipCreate, rv.Len())
  826. for i := 0; i < rv.Len(); i++ {
  827. builders[i] = c.Create()
  828. setFunc(builders[i], i)
  829. }
  830. return &LabelRelationshipCreateBulk{config: c.config, builders: builders}
  831. }
  832. // Update returns an update builder for LabelRelationship.
  833. func (c *LabelRelationshipClient) Update() *LabelRelationshipUpdate {
  834. mutation := newLabelRelationshipMutation(c.config, OpUpdate)
  835. return &LabelRelationshipUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  836. }
  837. // UpdateOne returns an update builder for the given entity.
  838. func (c *LabelRelationshipClient) UpdateOne(lr *LabelRelationship) *LabelRelationshipUpdateOne {
  839. mutation := newLabelRelationshipMutation(c.config, OpUpdateOne, withLabelRelationship(lr))
  840. return &LabelRelationshipUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  841. }
  842. // UpdateOneID returns an update builder for the given id.
  843. func (c *LabelRelationshipClient) UpdateOneID(id uint64) *LabelRelationshipUpdateOne {
  844. mutation := newLabelRelationshipMutation(c.config, OpUpdateOne, withLabelRelationshipID(id))
  845. return &LabelRelationshipUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  846. }
  847. // Delete returns a delete builder for LabelRelationship.
  848. func (c *LabelRelationshipClient) Delete() *LabelRelationshipDelete {
  849. mutation := newLabelRelationshipMutation(c.config, OpDelete)
  850. return &LabelRelationshipDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  851. }
  852. // DeleteOne returns a builder for deleting the given entity.
  853. func (c *LabelRelationshipClient) DeleteOne(lr *LabelRelationship) *LabelRelationshipDeleteOne {
  854. return c.DeleteOneID(lr.ID)
  855. }
  856. // DeleteOneID returns a builder for deleting the given entity by its id.
  857. func (c *LabelRelationshipClient) DeleteOneID(id uint64) *LabelRelationshipDeleteOne {
  858. builder := c.Delete().Where(labelrelationship.ID(id))
  859. builder.mutation.id = &id
  860. builder.mutation.op = OpDeleteOne
  861. return &LabelRelationshipDeleteOne{builder}
  862. }
  863. // Query returns a query builder for LabelRelationship.
  864. func (c *LabelRelationshipClient) Query() *LabelRelationshipQuery {
  865. return &LabelRelationshipQuery{
  866. config: c.config,
  867. ctx: &QueryContext{Type: TypeLabelRelationship},
  868. inters: c.Interceptors(),
  869. }
  870. }
  871. // Get returns a LabelRelationship entity by its id.
  872. func (c *LabelRelationshipClient) Get(ctx context.Context, id uint64) (*LabelRelationship, error) {
  873. return c.Query().Where(labelrelationship.ID(id)).Only(ctx)
  874. }
  875. // GetX is like Get, but panics if an error occurs.
  876. func (c *LabelRelationshipClient) GetX(ctx context.Context, id uint64) *LabelRelationship {
  877. obj, err := c.Get(ctx, id)
  878. if err != nil {
  879. panic(err)
  880. }
  881. return obj
  882. }
  883. // QueryContacts queries the contacts edge of a LabelRelationship.
  884. func (c *LabelRelationshipClient) QueryContacts(lr *LabelRelationship) *ContactQuery {
  885. query := (&ContactClient{config: c.config}).Query()
  886. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  887. id := lr.ID
  888. step := sqlgraph.NewStep(
  889. sqlgraph.From(labelrelationship.Table, labelrelationship.FieldID, id),
  890. sqlgraph.To(contact.Table, contact.FieldID),
  891. sqlgraph.Edge(sqlgraph.M2O, true, labelrelationship.ContactsTable, labelrelationship.ContactsColumn),
  892. )
  893. fromV = sqlgraph.Neighbors(lr.driver.Dialect(), step)
  894. return fromV, nil
  895. }
  896. return query
  897. }
  898. // QueryLabels queries the labels edge of a LabelRelationship.
  899. func (c *LabelRelationshipClient) QueryLabels(lr *LabelRelationship) *LabelQuery {
  900. query := (&LabelClient{config: c.config}).Query()
  901. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  902. id := lr.ID
  903. step := sqlgraph.NewStep(
  904. sqlgraph.From(labelrelationship.Table, labelrelationship.FieldID, id),
  905. sqlgraph.To(label.Table, label.FieldID),
  906. sqlgraph.Edge(sqlgraph.M2O, true, labelrelationship.LabelsTable, labelrelationship.LabelsColumn),
  907. )
  908. fromV = sqlgraph.Neighbors(lr.driver.Dialect(), step)
  909. return fromV, nil
  910. }
  911. return query
  912. }
  913. // Hooks returns the client hooks.
  914. func (c *LabelRelationshipClient) Hooks() []Hook {
  915. hooks := c.hooks.LabelRelationship
  916. return append(hooks[:len(hooks):len(hooks)], labelrelationship.Hooks[:]...)
  917. }
  918. // Interceptors returns the client interceptors.
  919. func (c *LabelRelationshipClient) Interceptors() []Interceptor {
  920. inters := c.inters.LabelRelationship
  921. return append(inters[:len(inters):len(inters)], labelrelationship.Interceptors[:]...)
  922. }
  923. func (c *LabelRelationshipClient) mutate(ctx context.Context, m *LabelRelationshipMutation) (Value, error) {
  924. switch m.Op() {
  925. case OpCreate:
  926. return (&LabelRelationshipCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  927. case OpUpdate:
  928. return (&LabelRelationshipUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  929. case OpUpdateOne:
  930. return (&LabelRelationshipUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  931. case OpDelete, OpDeleteOne:
  932. return (&LabelRelationshipDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  933. default:
  934. return nil, fmt.Errorf("ent: unknown LabelRelationship mutation op: %q", m.Op())
  935. }
  936. }
  937. // MessageClient is a client for the Message schema.
  938. type MessageClient struct {
  939. config
  940. }
  941. // NewMessageClient returns a client for the Message from the given config.
  942. func NewMessageClient(c config) *MessageClient {
  943. return &MessageClient{config: c}
  944. }
  945. // Use adds a list of mutation hooks to the hooks stack.
  946. // A call to `Use(f, g, h)` equals to `message.Hooks(f(g(h())))`.
  947. func (c *MessageClient) Use(hooks ...Hook) {
  948. c.hooks.Message = append(c.hooks.Message, hooks...)
  949. }
  950. // Intercept adds a list of query interceptors to the interceptors stack.
  951. // A call to `Intercept(f, g, h)` equals to `message.Intercept(f(g(h())))`.
  952. func (c *MessageClient) Intercept(interceptors ...Interceptor) {
  953. c.inters.Message = append(c.inters.Message, interceptors...)
  954. }
  955. // Create returns a builder for creating a Message entity.
  956. func (c *MessageClient) Create() *MessageCreate {
  957. mutation := newMessageMutation(c.config, OpCreate)
  958. return &MessageCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  959. }
  960. // CreateBulk returns a builder for creating a bulk of Message entities.
  961. func (c *MessageClient) CreateBulk(builders ...*MessageCreate) *MessageCreateBulk {
  962. return &MessageCreateBulk{config: c.config, builders: builders}
  963. }
  964. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  965. // a builder and applies setFunc on it.
  966. func (c *MessageClient) MapCreateBulk(slice any, setFunc func(*MessageCreate, int)) *MessageCreateBulk {
  967. rv := reflect.ValueOf(slice)
  968. if rv.Kind() != reflect.Slice {
  969. return &MessageCreateBulk{err: fmt.Errorf("calling to MessageClient.MapCreateBulk with wrong type %T, need slice", slice)}
  970. }
  971. builders := make([]*MessageCreate, rv.Len())
  972. for i := 0; i < rv.Len(); i++ {
  973. builders[i] = c.Create()
  974. setFunc(builders[i], i)
  975. }
  976. return &MessageCreateBulk{config: c.config, builders: builders}
  977. }
  978. // Update returns an update builder for Message.
  979. func (c *MessageClient) Update() *MessageUpdate {
  980. mutation := newMessageMutation(c.config, OpUpdate)
  981. return &MessageUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  982. }
  983. // UpdateOne returns an update builder for the given entity.
  984. func (c *MessageClient) UpdateOne(m *Message) *MessageUpdateOne {
  985. mutation := newMessageMutation(c.config, OpUpdateOne, withMessage(m))
  986. return &MessageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  987. }
  988. // UpdateOneID returns an update builder for the given id.
  989. func (c *MessageClient) UpdateOneID(id int) *MessageUpdateOne {
  990. mutation := newMessageMutation(c.config, OpUpdateOne, withMessageID(id))
  991. return &MessageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  992. }
  993. // Delete returns a delete builder for Message.
  994. func (c *MessageClient) Delete() *MessageDelete {
  995. mutation := newMessageMutation(c.config, OpDelete)
  996. return &MessageDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  997. }
  998. // DeleteOne returns a builder for deleting the given entity.
  999. func (c *MessageClient) DeleteOne(m *Message) *MessageDeleteOne {
  1000. return c.DeleteOneID(m.ID)
  1001. }
  1002. // DeleteOneID returns a builder for deleting the given entity by its id.
  1003. func (c *MessageClient) DeleteOneID(id int) *MessageDeleteOne {
  1004. builder := c.Delete().Where(message.ID(id))
  1005. builder.mutation.id = &id
  1006. builder.mutation.op = OpDeleteOne
  1007. return &MessageDeleteOne{builder}
  1008. }
  1009. // Query returns a query builder for Message.
  1010. func (c *MessageClient) Query() *MessageQuery {
  1011. return &MessageQuery{
  1012. config: c.config,
  1013. ctx: &QueryContext{Type: TypeMessage},
  1014. inters: c.Interceptors(),
  1015. }
  1016. }
  1017. // Get returns a Message entity by its id.
  1018. func (c *MessageClient) Get(ctx context.Context, id int) (*Message, error) {
  1019. return c.Query().Where(message.ID(id)).Only(ctx)
  1020. }
  1021. // GetX is like Get, but panics if an error occurs.
  1022. func (c *MessageClient) GetX(ctx context.Context, id int) *Message {
  1023. obj, err := c.Get(ctx, id)
  1024. if err != nil {
  1025. panic(err)
  1026. }
  1027. return obj
  1028. }
  1029. // Hooks returns the client hooks.
  1030. func (c *MessageClient) Hooks() []Hook {
  1031. return c.hooks.Message
  1032. }
  1033. // Interceptors returns the client interceptors.
  1034. func (c *MessageClient) Interceptors() []Interceptor {
  1035. return c.inters.Message
  1036. }
  1037. func (c *MessageClient) mutate(ctx context.Context, m *MessageMutation) (Value, error) {
  1038. switch m.Op() {
  1039. case OpCreate:
  1040. return (&MessageCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1041. case OpUpdate:
  1042. return (&MessageUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1043. case OpUpdateOne:
  1044. return (&MessageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1045. case OpDelete, OpDeleteOne:
  1046. return (&MessageDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1047. default:
  1048. return nil, fmt.Errorf("ent: unknown Message mutation op: %q", m.Op())
  1049. }
  1050. }
  1051. // MessageRecordsClient is a client for the MessageRecords schema.
  1052. type MessageRecordsClient struct {
  1053. config
  1054. }
  1055. // NewMessageRecordsClient returns a client for the MessageRecords from the given config.
  1056. func NewMessageRecordsClient(c config) *MessageRecordsClient {
  1057. return &MessageRecordsClient{config: c}
  1058. }
  1059. // Use adds a list of mutation hooks to the hooks stack.
  1060. // A call to `Use(f, g, h)` equals to `messagerecords.Hooks(f(g(h())))`.
  1061. func (c *MessageRecordsClient) Use(hooks ...Hook) {
  1062. c.hooks.MessageRecords = append(c.hooks.MessageRecords, hooks...)
  1063. }
  1064. // Intercept adds a list of query interceptors to the interceptors stack.
  1065. // A call to `Intercept(f, g, h)` equals to `messagerecords.Intercept(f(g(h())))`.
  1066. func (c *MessageRecordsClient) Intercept(interceptors ...Interceptor) {
  1067. c.inters.MessageRecords = append(c.inters.MessageRecords, interceptors...)
  1068. }
  1069. // Create returns a builder for creating a MessageRecords entity.
  1070. func (c *MessageRecordsClient) Create() *MessageRecordsCreate {
  1071. mutation := newMessageRecordsMutation(c.config, OpCreate)
  1072. return &MessageRecordsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1073. }
  1074. // CreateBulk returns a builder for creating a bulk of MessageRecords entities.
  1075. func (c *MessageRecordsClient) CreateBulk(builders ...*MessageRecordsCreate) *MessageRecordsCreateBulk {
  1076. return &MessageRecordsCreateBulk{config: c.config, builders: builders}
  1077. }
  1078. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1079. // a builder and applies setFunc on it.
  1080. func (c *MessageRecordsClient) MapCreateBulk(slice any, setFunc func(*MessageRecordsCreate, int)) *MessageRecordsCreateBulk {
  1081. rv := reflect.ValueOf(slice)
  1082. if rv.Kind() != reflect.Slice {
  1083. return &MessageRecordsCreateBulk{err: fmt.Errorf("calling to MessageRecordsClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1084. }
  1085. builders := make([]*MessageRecordsCreate, rv.Len())
  1086. for i := 0; i < rv.Len(); i++ {
  1087. builders[i] = c.Create()
  1088. setFunc(builders[i], i)
  1089. }
  1090. return &MessageRecordsCreateBulk{config: c.config, builders: builders}
  1091. }
  1092. // Update returns an update builder for MessageRecords.
  1093. func (c *MessageRecordsClient) Update() *MessageRecordsUpdate {
  1094. mutation := newMessageRecordsMutation(c.config, OpUpdate)
  1095. return &MessageRecordsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1096. }
  1097. // UpdateOne returns an update builder for the given entity.
  1098. func (c *MessageRecordsClient) UpdateOne(mr *MessageRecords) *MessageRecordsUpdateOne {
  1099. mutation := newMessageRecordsMutation(c.config, OpUpdateOne, withMessageRecords(mr))
  1100. return &MessageRecordsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1101. }
  1102. // UpdateOneID returns an update builder for the given id.
  1103. func (c *MessageRecordsClient) UpdateOneID(id uint64) *MessageRecordsUpdateOne {
  1104. mutation := newMessageRecordsMutation(c.config, OpUpdateOne, withMessageRecordsID(id))
  1105. return &MessageRecordsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1106. }
  1107. // Delete returns a delete builder for MessageRecords.
  1108. func (c *MessageRecordsClient) Delete() *MessageRecordsDelete {
  1109. mutation := newMessageRecordsMutation(c.config, OpDelete)
  1110. return &MessageRecordsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1111. }
  1112. // DeleteOne returns a builder for deleting the given entity.
  1113. func (c *MessageRecordsClient) DeleteOne(mr *MessageRecords) *MessageRecordsDeleteOne {
  1114. return c.DeleteOneID(mr.ID)
  1115. }
  1116. // DeleteOneID returns a builder for deleting the given entity by its id.
  1117. func (c *MessageRecordsClient) DeleteOneID(id uint64) *MessageRecordsDeleteOne {
  1118. builder := c.Delete().Where(messagerecords.ID(id))
  1119. builder.mutation.id = &id
  1120. builder.mutation.op = OpDeleteOne
  1121. return &MessageRecordsDeleteOne{builder}
  1122. }
  1123. // Query returns a query builder for MessageRecords.
  1124. func (c *MessageRecordsClient) Query() *MessageRecordsQuery {
  1125. return &MessageRecordsQuery{
  1126. config: c.config,
  1127. ctx: &QueryContext{Type: TypeMessageRecords},
  1128. inters: c.Interceptors(),
  1129. }
  1130. }
  1131. // Get returns a MessageRecords entity by its id.
  1132. func (c *MessageRecordsClient) Get(ctx context.Context, id uint64) (*MessageRecords, error) {
  1133. return c.Query().Where(messagerecords.ID(id)).Only(ctx)
  1134. }
  1135. // GetX is like Get, but panics if an error occurs.
  1136. func (c *MessageRecordsClient) GetX(ctx context.Context, id uint64) *MessageRecords {
  1137. obj, err := c.Get(ctx, id)
  1138. if err != nil {
  1139. panic(err)
  1140. }
  1141. return obj
  1142. }
  1143. // QuerySopStage queries the sop_stage edge of a MessageRecords.
  1144. func (c *MessageRecordsClient) QuerySopStage(mr *MessageRecords) *SopStageQuery {
  1145. query := (&SopStageClient{config: c.config}).Query()
  1146. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1147. id := mr.ID
  1148. step := sqlgraph.NewStep(
  1149. sqlgraph.From(messagerecords.Table, messagerecords.FieldID, id),
  1150. sqlgraph.To(sopstage.Table, sopstage.FieldID),
  1151. sqlgraph.Edge(sqlgraph.M2O, true, messagerecords.SopStageTable, messagerecords.SopStageColumn),
  1152. )
  1153. fromV = sqlgraph.Neighbors(mr.driver.Dialect(), step)
  1154. return fromV, nil
  1155. }
  1156. return query
  1157. }
  1158. // QuerySopNode queries the sop_node edge of a MessageRecords.
  1159. func (c *MessageRecordsClient) QuerySopNode(mr *MessageRecords) *SopNodeQuery {
  1160. query := (&SopNodeClient{config: c.config}).Query()
  1161. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1162. id := mr.ID
  1163. step := sqlgraph.NewStep(
  1164. sqlgraph.From(messagerecords.Table, messagerecords.FieldID, id),
  1165. sqlgraph.To(sopnode.Table, sopnode.FieldID),
  1166. sqlgraph.Edge(sqlgraph.M2O, true, messagerecords.SopNodeTable, messagerecords.SopNodeColumn),
  1167. )
  1168. fromV = sqlgraph.Neighbors(mr.driver.Dialect(), step)
  1169. return fromV, nil
  1170. }
  1171. return query
  1172. }
  1173. // QueryMessageContact queries the message_contact edge of a MessageRecords.
  1174. func (c *MessageRecordsClient) QueryMessageContact(mr *MessageRecords) *ContactQuery {
  1175. query := (&ContactClient{config: c.config}).Query()
  1176. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1177. id := mr.ID
  1178. step := sqlgraph.NewStep(
  1179. sqlgraph.From(messagerecords.Table, messagerecords.FieldID, id),
  1180. sqlgraph.To(contact.Table, contact.FieldID),
  1181. sqlgraph.Edge(sqlgraph.M2O, true, messagerecords.MessageContactTable, messagerecords.MessageContactColumn),
  1182. )
  1183. fromV = sqlgraph.Neighbors(mr.driver.Dialect(), step)
  1184. return fromV, nil
  1185. }
  1186. return query
  1187. }
  1188. // Hooks returns the client hooks.
  1189. func (c *MessageRecordsClient) Hooks() []Hook {
  1190. hooks := c.hooks.MessageRecords
  1191. return append(hooks[:len(hooks):len(hooks)], messagerecords.Hooks[:]...)
  1192. }
  1193. // Interceptors returns the client interceptors.
  1194. func (c *MessageRecordsClient) Interceptors() []Interceptor {
  1195. inters := c.inters.MessageRecords
  1196. return append(inters[:len(inters):len(inters)], messagerecords.Interceptors[:]...)
  1197. }
  1198. func (c *MessageRecordsClient) mutate(ctx context.Context, m *MessageRecordsMutation) (Value, error) {
  1199. switch m.Op() {
  1200. case OpCreate:
  1201. return (&MessageRecordsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1202. case OpUpdate:
  1203. return (&MessageRecordsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1204. case OpUpdateOne:
  1205. return (&MessageRecordsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1206. case OpDelete, OpDeleteOne:
  1207. return (&MessageRecordsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1208. default:
  1209. return nil, fmt.Errorf("ent: unknown MessageRecords mutation op: %q", m.Op())
  1210. }
  1211. }
  1212. // MsgClient is a client for the Msg schema.
  1213. type MsgClient struct {
  1214. config
  1215. }
  1216. // NewMsgClient returns a client for the Msg from the given config.
  1217. func NewMsgClient(c config) *MsgClient {
  1218. return &MsgClient{config: c}
  1219. }
  1220. // Use adds a list of mutation hooks to the hooks stack.
  1221. // A call to `Use(f, g, h)` equals to `msg.Hooks(f(g(h())))`.
  1222. func (c *MsgClient) Use(hooks ...Hook) {
  1223. c.hooks.Msg = append(c.hooks.Msg, hooks...)
  1224. }
  1225. // Intercept adds a list of query interceptors to the interceptors stack.
  1226. // A call to `Intercept(f, g, h)` equals to `msg.Intercept(f(g(h())))`.
  1227. func (c *MsgClient) Intercept(interceptors ...Interceptor) {
  1228. c.inters.Msg = append(c.inters.Msg, interceptors...)
  1229. }
  1230. // Create returns a builder for creating a Msg entity.
  1231. func (c *MsgClient) Create() *MsgCreate {
  1232. mutation := newMsgMutation(c.config, OpCreate)
  1233. return &MsgCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1234. }
  1235. // CreateBulk returns a builder for creating a bulk of Msg entities.
  1236. func (c *MsgClient) CreateBulk(builders ...*MsgCreate) *MsgCreateBulk {
  1237. return &MsgCreateBulk{config: c.config, builders: builders}
  1238. }
  1239. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1240. // a builder and applies setFunc on it.
  1241. func (c *MsgClient) MapCreateBulk(slice any, setFunc func(*MsgCreate, int)) *MsgCreateBulk {
  1242. rv := reflect.ValueOf(slice)
  1243. if rv.Kind() != reflect.Slice {
  1244. return &MsgCreateBulk{err: fmt.Errorf("calling to MsgClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1245. }
  1246. builders := make([]*MsgCreate, rv.Len())
  1247. for i := 0; i < rv.Len(); i++ {
  1248. builders[i] = c.Create()
  1249. setFunc(builders[i], i)
  1250. }
  1251. return &MsgCreateBulk{config: c.config, builders: builders}
  1252. }
  1253. // Update returns an update builder for Msg.
  1254. func (c *MsgClient) Update() *MsgUpdate {
  1255. mutation := newMsgMutation(c.config, OpUpdate)
  1256. return &MsgUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1257. }
  1258. // UpdateOne returns an update builder for the given entity.
  1259. func (c *MsgClient) UpdateOne(m *Msg) *MsgUpdateOne {
  1260. mutation := newMsgMutation(c.config, OpUpdateOne, withMsg(m))
  1261. return &MsgUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1262. }
  1263. // UpdateOneID returns an update builder for the given id.
  1264. func (c *MsgClient) UpdateOneID(id uint64) *MsgUpdateOne {
  1265. mutation := newMsgMutation(c.config, OpUpdateOne, withMsgID(id))
  1266. return &MsgUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1267. }
  1268. // Delete returns a delete builder for Msg.
  1269. func (c *MsgClient) Delete() *MsgDelete {
  1270. mutation := newMsgMutation(c.config, OpDelete)
  1271. return &MsgDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1272. }
  1273. // DeleteOne returns a builder for deleting the given entity.
  1274. func (c *MsgClient) DeleteOne(m *Msg) *MsgDeleteOne {
  1275. return c.DeleteOneID(m.ID)
  1276. }
  1277. // DeleteOneID returns a builder for deleting the given entity by its id.
  1278. func (c *MsgClient) DeleteOneID(id uint64) *MsgDeleteOne {
  1279. builder := c.Delete().Where(msg.ID(id))
  1280. builder.mutation.id = &id
  1281. builder.mutation.op = OpDeleteOne
  1282. return &MsgDeleteOne{builder}
  1283. }
  1284. // Query returns a query builder for Msg.
  1285. func (c *MsgClient) Query() *MsgQuery {
  1286. return &MsgQuery{
  1287. config: c.config,
  1288. ctx: &QueryContext{Type: TypeMsg},
  1289. inters: c.Interceptors(),
  1290. }
  1291. }
  1292. // Get returns a Msg entity by its id.
  1293. func (c *MsgClient) Get(ctx context.Context, id uint64) (*Msg, error) {
  1294. return c.Query().Where(msg.ID(id)).Only(ctx)
  1295. }
  1296. // GetX is like Get, but panics if an error occurs.
  1297. func (c *MsgClient) GetX(ctx context.Context, id uint64) *Msg {
  1298. obj, err := c.Get(ctx, id)
  1299. if err != nil {
  1300. panic(err)
  1301. }
  1302. return obj
  1303. }
  1304. // Hooks returns the client hooks.
  1305. func (c *MsgClient) Hooks() []Hook {
  1306. hooks := c.hooks.Msg
  1307. return append(hooks[:len(hooks):len(hooks)], msg.Hooks[:]...)
  1308. }
  1309. // Interceptors returns the client interceptors.
  1310. func (c *MsgClient) Interceptors() []Interceptor {
  1311. inters := c.inters.Msg
  1312. return append(inters[:len(inters):len(inters)], msg.Interceptors[:]...)
  1313. }
  1314. func (c *MsgClient) mutate(ctx context.Context, m *MsgMutation) (Value, error) {
  1315. switch m.Op() {
  1316. case OpCreate:
  1317. return (&MsgCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1318. case OpUpdate:
  1319. return (&MsgUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1320. case OpUpdateOne:
  1321. return (&MsgUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1322. case OpDelete, OpDeleteOne:
  1323. return (&MsgDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1324. default:
  1325. return nil, fmt.Errorf("ent: unknown Msg mutation op: %q", m.Op())
  1326. }
  1327. }
  1328. // ServerClient is a client for the Server schema.
  1329. type ServerClient struct {
  1330. config
  1331. }
  1332. // NewServerClient returns a client for the Server from the given config.
  1333. func NewServerClient(c config) *ServerClient {
  1334. return &ServerClient{config: c}
  1335. }
  1336. // Use adds a list of mutation hooks to the hooks stack.
  1337. // A call to `Use(f, g, h)` equals to `server.Hooks(f(g(h())))`.
  1338. func (c *ServerClient) Use(hooks ...Hook) {
  1339. c.hooks.Server = append(c.hooks.Server, hooks...)
  1340. }
  1341. // Intercept adds a list of query interceptors to the interceptors stack.
  1342. // A call to `Intercept(f, g, h)` equals to `server.Intercept(f(g(h())))`.
  1343. func (c *ServerClient) Intercept(interceptors ...Interceptor) {
  1344. c.inters.Server = append(c.inters.Server, interceptors...)
  1345. }
  1346. // Create returns a builder for creating a Server entity.
  1347. func (c *ServerClient) Create() *ServerCreate {
  1348. mutation := newServerMutation(c.config, OpCreate)
  1349. return &ServerCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1350. }
  1351. // CreateBulk returns a builder for creating a bulk of Server entities.
  1352. func (c *ServerClient) CreateBulk(builders ...*ServerCreate) *ServerCreateBulk {
  1353. return &ServerCreateBulk{config: c.config, builders: builders}
  1354. }
  1355. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1356. // a builder and applies setFunc on it.
  1357. func (c *ServerClient) MapCreateBulk(slice any, setFunc func(*ServerCreate, int)) *ServerCreateBulk {
  1358. rv := reflect.ValueOf(slice)
  1359. if rv.Kind() != reflect.Slice {
  1360. return &ServerCreateBulk{err: fmt.Errorf("calling to ServerClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1361. }
  1362. builders := make([]*ServerCreate, rv.Len())
  1363. for i := 0; i < rv.Len(); i++ {
  1364. builders[i] = c.Create()
  1365. setFunc(builders[i], i)
  1366. }
  1367. return &ServerCreateBulk{config: c.config, builders: builders}
  1368. }
  1369. // Update returns an update builder for Server.
  1370. func (c *ServerClient) Update() *ServerUpdate {
  1371. mutation := newServerMutation(c.config, OpUpdate)
  1372. return &ServerUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1373. }
  1374. // UpdateOne returns an update builder for the given entity.
  1375. func (c *ServerClient) UpdateOne(s *Server) *ServerUpdateOne {
  1376. mutation := newServerMutation(c.config, OpUpdateOne, withServer(s))
  1377. return &ServerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1378. }
  1379. // UpdateOneID returns an update builder for the given id.
  1380. func (c *ServerClient) UpdateOneID(id uint64) *ServerUpdateOne {
  1381. mutation := newServerMutation(c.config, OpUpdateOne, withServerID(id))
  1382. return &ServerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1383. }
  1384. // Delete returns a delete builder for Server.
  1385. func (c *ServerClient) Delete() *ServerDelete {
  1386. mutation := newServerMutation(c.config, OpDelete)
  1387. return &ServerDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1388. }
  1389. // DeleteOne returns a builder for deleting the given entity.
  1390. func (c *ServerClient) DeleteOne(s *Server) *ServerDeleteOne {
  1391. return c.DeleteOneID(s.ID)
  1392. }
  1393. // DeleteOneID returns a builder for deleting the given entity by its id.
  1394. func (c *ServerClient) DeleteOneID(id uint64) *ServerDeleteOne {
  1395. builder := c.Delete().Where(server.ID(id))
  1396. builder.mutation.id = &id
  1397. builder.mutation.op = OpDeleteOne
  1398. return &ServerDeleteOne{builder}
  1399. }
  1400. // Query returns a query builder for Server.
  1401. func (c *ServerClient) Query() *ServerQuery {
  1402. return &ServerQuery{
  1403. config: c.config,
  1404. ctx: &QueryContext{Type: TypeServer},
  1405. inters: c.Interceptors(),
  1406. }
  1407. }
  1408. // Get returns a Server entity by its id.
  1409. func (c *ServerClient) Get(ctx context.Context, id uint64) (*Server, error) {
  1410. return c.Query().Where(server.ID(id)).Only(ctx)
  1411. }
  1412. // GetX is like Get, but panics if an error occurs.
  1413. func (c *ServerClient) GetX(ctx context.Context, id uint64) *Server {
  1414. obj, err := c.Get(ctx, id)
  1415. if err != nil {
  1416. panic(err)
  1417. }
  1418. return obj
  1419. }
  1420. // QueryWxs queries the wxs edge of a Server.
  1421. func (c *ServerClient) QueryWxs(s *Server) *WxQuery {
  1422. query := (&WxClient{config: c.config}).Query()
  1423. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1424. id := s.ID
  1425. step := sqlgraph.NewStep(
  1426. sqlgraph.From(server.Table, server.FieldID, id),
  1427. sqlgraph.To(wx.Table, wx.FieldID),
  1428. sqlgraph.Edge(sqlgraph.O2M, false, server.WxsTable, server.WxsColumn),
  1429. )
  1430. fromV = sqlgraph.Neighbors(s.driver.Dialect(), step)
  1431. return fromV, nil
  1432. }
  1433. return query
  1434. }
  1435. // Hooks returns the client hooks.
  1436. func (c *ServerClient) Hooks() []Hook {
  1437. hooks := c.hooks.Server
  1438. return append(hooks[:len(hooks):len(hooks)], server.Hooks[:]...)
  1439. }
  1440. // Interceptors returns the client interceptors.
  1441. func (c *ServerClient) Interceptors() []Interceptor {
  1442. inters := c.inters.Server
  1443. return append(inters[:len(inters):len(inters)], server.Interceptors[:]...)
  1444. }
  1445. func (c *ServerClient) mutate(ctx context.Context, m *ServerMutation) (Value, error) {
  1446. switch m.Op() {
  1447. case OpCreate:
  1448. return (&ServerCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1449. case OpUpdate:
  1450. return (&ServerUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1451. case OpUpdateOne:
  1452. return (&ServerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1453. case OpDelete, OpDeleteOne:
  1454. return (&ServerDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1455. default:
  1456. return nil, fmt.Errorf("ent: unknown Server mutation op: %q", m.Op())
  1457. }
  1458. }
  1459. // SopNodeClient is a client for the SopNode schema.
  1460. type SopNodeClient struct {
  1461. config
  1462. }
  1463. // NewSopNodeClient returns a client for the SopNode from the given config.
  1464. func NewSopNodeClient(c config) *SopNodeClient {
  1465. return &SopNodeClient{config: c}
  1466. }
  1467. // Use adds a list of mutation hooks to the hooks stack.
  1468. // A call to `Use(f, g, h)` equals to `sopnode.Hooks(f(g(h())))`.
  1469. func (c *SopNodeClient) Use(hooks ...Hook) {
  1470. c.hooks.SopNode = append(c.hooks.SopNode, hooks...)
  1471. }
  1472. // Intercept adds a list of query interceptors to the interceptors stack.
  1473. // A call to `Intercept(f, g, h)` equals to `sopnode.Intercept(f(g(h())))`.
  1474. func (c *SopNodeClient) Intercept(interceptors ...Interceptor) {
  1475. c.inters.SopNode = append(c.inters.SopNode, interceptors...)
  1476. }
  1477. // Create returns a builder for creating a SopNode entity.
  1478. func (c *SopNodeClient) Create() *SopNodeCreate {
  1479. mutation := newSopNodeMutation(c.config, OpCreate)
  1480. return &SopNodeCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1481. }
  1482. // CreateBulk returns a builder for creating a bulk of SopNode entities.
  1483. func (c *SopNodeClient) CreateBulk(builders ...*SopNodeCreate) *SopNodeCreateBulk {
  1484. return &SopNodeCreateBulk{config: c.config, builders: builders}
  1485. }
  1486. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1487. // a builder and applies setFunc on it.
  1488. func (c *SopNodeClient) MapCreateBulk(slice any, setFunc func(*SopNodeCreate, int)) *SopNodeCreateBulk {
  1489. rv := reflect.ValueOf(slice)
  1490. if rv.Kind() != reflect.Slice {
  1491. return &SopNodeCreateBulk{err: fmt.Errorf("calling to SopNodeClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1492. }
  1493. builders := make([]*SopNodeCreate, rv.Len())
  1494. for i := 0; i < rv.Len(); i++ {
  1495. builders[i] = c.Create()
  1496. setFunc(builders[i], i)
  1497. }
  1498. return &SopNodeCreateBulk{config: c.config, builders: builders}
  1499. }
  1500. // Update returns an update builder for SopNode.
  1501. func (c *SopNodeClient) Update() *SopNodeUpdate {
  1502. mutation := newSopNodeMutation(c.config, OpUpdate)
  1503. return &SopNodeUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1504. }
  1505. // UpdateOne returns an update builder for the given entity.
  1506. func (c *SopNodeClient) UpdateOne(sn *SopNode) *SopNodeUpdateOne {
  1507. mutation := newSopNodeMutation(c.config, OpUpdateOne, withSopNode(sn))
  1508. return &SopNodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1509. }
  1510. // UpdateOneID returns an update builder for the given id.
  1511. func (c *SopNodeClient) UpdateOneID(id uint64) *SopNodeUpdateOne {
  1512. mutation := newSopNodeMutation(c.config, OpUpdateOne, withSopNodeID(id))
  1513. return &SopNodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1514. }
  1515. // Delete returns a delete builder for SopNode.
  1516. func (c *SopNodeClient) Delete() *SopNodeDelete {
  1517. mutation := newSopNodeMutation(c.config, OpDelete)
  1518. return &SopNodeDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1519. }
  1520. // DeleteOne returns a builder for deleting the given entity.
  1521. func (c *SopNodeClient) DeleteOne(sn *SopNode) *SopNodeDeleteOne {
  1522. return c.DeleteOneID(sn.ID)
  1523. }
  1524. // DeleteOneID returns a builder for deleting the given entity by its id.
  1525. func (c *SopNodeClient) DeleteOneID(id uint64) *SopNodeDeleteOne {
  1526. builder := c.Delete().Where(sopnode.ID(id))
  1527. builder.mutation.id = &id
  1528. builder.mutation.op = OpDeleteOne
  1529. return &SopNodeDeleteOne{builder}
  1530. }
  1531. // Query returns a query builder for SopNode.
  1532. func (c *SopNodeClient) Query() *SopNodeQuery {
  1533. return &SopNodeQuery{
  1534. config: c.config,
  1535. ctx: &QueryContext{Type: TypeSopNode},
  1536. inters: c.Interceptors(),
  1537. }
  1538. }
  1539. // Get returns a SopNode entity by its id.
  1540. func (c *SopNodeClient) Get(ctx context.Context, id uint64) (*SopNode, error) {
  1541. return c.Query().Where(sopnode.ID(id)).Only(ctx)
  1542. }
  1543. // GetX is like Get, but panics if an error occurs.
  1544. func (c *SopNodeClient) GetX(ctx context.Context, id uint64) *SopNode {
  1545. obj, err := c.Get(ctx, id)
  1546. if err != nil {
  1547. panic(err)
  1548. }
  1549. return obj
  1550. }
  1551. // QuerySopStage queries the sop_stage edge of a SopNode.
  1552. func (c *SopNodeClient) QuerySopStage(sn *SopNode) *SopStageQuery {
  1553. query := (&SopStageClient{config: c.config}).Query()
  1554. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1555. id := sn.ID
  1556. step := sqlgraph.NewStep(
  1557. sqlgraph.From(sopnode.Table, sopnode.FieldID, id),
  1558. sqlgraph.To(sopstage.Table, sopstage.FieldID),
  1559. sqlgraph.Edge(sqlgraph.M2O, true, sopnode.SopStageTable, sopnode.SopStageColumn),
  1560. )
  1561. fromV = sqlgraph.Neighbors(sn.driver.Dialect(), step)
  1562. return fromV, nil
  1563. }
  1564. return query
  1565. }
  1566. // QueryNodeMessages queries the node_messages edge of a SopNode.
  1567. func (c *SopNodeClient) QueryNodeMessages(sn *SopNode) *MessageRecordsQuery {
  1568. query := (&MessageRecordsClient{config: c.config}).Query()
  1569. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1570. id := sn.ID
  1571. step := sqlgraph.NewStep(
  1572. sqlgraph.From(sopnode.Table, sopnode.FieldID, id),
  1573. sqlgraph.To(messagerecords.Table, messagerecords.FieldID),
  1574. sqlgraph.Edge(sqlgraph.O2M, false, sopnode.NodeMessagesTable, sopnode.NodeMessagesColumn),
  1575. )
  1576. fromV = sqlgraph.Neighbors(sn.driver.Dialect(), step)
  1577. return fromV, nil
  1578. }
  1579. return query
  1580. }
  1581. // Hooks returns the client hooks.
  1582. func (c *SopNodeClient) Hooks() []Hook {
  1583. hooks := c.hooks.SopNode
  1584. return append(hooks[:len(hooks):len(hooks)], sopnode.Hooks[:]...)
  1585. }
  1586. // Interceptors returns the client interceptors.
  1587. func (c *SopNodeClient) Interceptors() []Interceptor {
  1588. inters := c.inters.SopNode
  1589. return append(inters[:len(inters):len(inters)], sopnode.Interceptors[:]...)
  1590. }
  1591. func (c *SopNodeClient) mutate(ctx context.Context, m *SopNodeMutation) (Value, error) {
  1592. switch m.Op() {
  1593. case OpCreate:
  1594. return (&SopNodeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1595. case OpUpdate:
  1596. return (&SopNodeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1597. case OpUpdateOne:
  1598. return (&SopNodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1599. case OpDelete, OpDeleteOne:
  1600. return (&SopNodeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1601. default:
  1602. return nil, fmt.Errorf("ent: unknown SopNode mutation op: %q", m.Op())
  1603. }
  1604. }
  1605. // SopStageClient is a client for the SopStage schema.
  1606. type SopStageClient struct {
  1607. config
  1608. }
  1609. // NewSopStageClient returns a client for the SopStage from the given config.
  1610. func NewSopStageClient(c config) *SopStageClient {
  1611. return &SopStageClient{config: c}
  1612. }
  1613. // Use adds a list of mutation hooks to the hooks stack.
  1614. // A call to `Use(f, g, h)` equals to `sopstage.Hooks(f(g(h())))`.
  1615. func (c *SopStageClient) Use(hooks ...Hook) {
  1616. c.hooks.SopStage = append(c.hooks.SopStage, hooks...)
  1617. }
  1618. // Intercept adds a list of query interceptors to the interceptors stack.
  1619. // A call to `Intercept(f, g, h)` equals to `sopstage.Intercept(f(g(h())))`.
  1620. func (c *SopStageClient) Intercept(interceptors ...Interceptor) {
  1621. c.inters.SopStage = append(c.inters.SopStage, interceptors...)
  1622. }
  1623. // Create returns a builder for creating a SopStage entity.
  1624. func (c *SopStageClient) Create() *SopStageCreate {
  1625. mutation := newSopStageMutation(c.config, OpCreate)
  1626. return &SopStageCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1627. }
  1628. // CreateBulk returns a builder for creating a bulk of SopStage entities.
  1629. func (c *SopStageClient) CreateBulk(builders ...*SopStageCreate) *SopStageCreateBulk {
  1630. return &SopStageCreateBulk{config: c.config, builders: builders}
  1631. }
  1632. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1633. // a builder and applies setFunc on it.
  1634. func (c *SopStageClient) MapCreateBulk(slice any, setFunc func(*SopStageCreate, int)) *SopStageCreateBulk {
  1635. rv := reflect.ValueOf(slice)
  1636. if rv.Kind() != reflect.Slice {
  1637. return &SopStageCreateBulk{err: fmt.Errorf("calling to SopStageClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1638. }
  1639. builders := make([]*SopStageCreate, rv.Len())
  1640. for i := 0; i < rv.Len(); i++ {
  1641. builders[i] = c.Create()
  1642. setFunc(builders[i], i)
  1643. }
  1644. return &SopStageCreateBulk{config: c.config, builders: builders}
  1645. }
  1646. // Update returns an update builder for SopStage.
  1647. func (c *SopStageClient) Update() *SopStageUpdate {
  1648. mutation := newSopStageMutation(c.config, OpUpdate)
  1649. return &SopStageUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1650. }
  1651. // UpdateOne returns an update builder for the given entity.
  1652. func (c *SopStageClient) UpdateOne(ss *SopStage) *SopStageUpdateOne {
  1653. mutation := newSopStageMutation(c.config, OpUpdateOne, withSopStage(ss))
  1654. return &SopStageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1655. }
  1656. // UpdateOneID returns an update builder for the given id.
  1657. func (c *SopStageClient) UpdateOneID(id uint64) *SopStageUpdateOne {
  1658. mutation := newSopStageMutation(c.config, OpUpdateOne, withSopStageID(id))
  1659. return &SopStageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1660. }
  1661. // Delete returns a delete builder for SopStage.
  1662. func (c *SopStageClient) Delete() *SopStageDelete {
  1663. mutation := newSopStageMutation(c.config, OpDelete)
  1664. return &SopStageDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1665. }
  1666. // DeleteOne returns a builder for deleting the given entity.
  1667. func (c *SopStageClient) DeleteOne(ss *SopStage) *SopStageDeleteOne {
  1668. return c.DeleteOneID(ss.ID)
  1669. }
  1670. // DeleteOneID returns a builder for deleting the given entity by its id.
  1671. func (c *SopStageClient) DeleteOneID(id uint64) *SopStageDeleteOne {
  1672. builder := c.Delete().Where(sopstage.ID(id))
  1673. builder.mutation.id = &id
  1674. builder.mutation.op = OpDeleteOne
  1675. return &SopStageDeleteOne{builder}
  1676. }
  1677. // Query returns a query builder for SopStage.
  1678. func (c *SopStageClient) Query() *SopStageQuery {
  1679. return &SopStageQuery{
  1680. config: c.config,
  1681. ctx: &QueryContext{Type: TypeSopStage},
  1682. inters: c.Interceptors(),
  1683. }
  1684. }
  1685. // Get returns a SopStage entity by its id.
  1686. func (c *SopStageClient) Get(ctx context.Context, id uint64) (*SopStage, error) {
  1687. return c.Query().Where(sopstage.ID(id)).Only(ctx)
  1688. }
  1689. // GetX is like Get, but panics if an error occurs.
  1690. func (c *SopStageClient) GetX(ctx context.Context, id uint64) *SopStage {
  1691. obj, err := c.Get(ctx, id)
  1692. if err != nil {
  1693. panic(err)
  1694. }
  1695. return obj
  1696. }
  1697. // QuerySopTask queries the sop_task edge of a SopStage.
  1698. func (c *SopStageClient) QuerySopTask(ss *SopStage) *SopTaskQuery {
  1699. query := (&SopTaskClient{config: c.config}).Query()
  1700. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1701. id := ss.ID
  1702. step := sqlgraph.NewStep(
  1703. sqlgraph.From(sopstage.Table, sopstage.FieldID, id),
  1704. sqlgraph.To(soptask.Table, soptask.FieldID),
  1705. sqlgraph.Edge(sqlgraph.M2O, true, sopstage.SopTaskTable, sopstage.SopTaskColumn),
  1706. )
  1707. fromV = sqlgraph.Neighbors(ss.driver.Dialect(), step)
  1708. return fromV, nil
  1709. }
  1710. return query
  1711. }
  1712. // QueryStageNodes queries the stage_nodes edge of a SopStage.
  1713. func (c *SopStageClient) QueryStageNodes(ss *SopStage) *SopNodeQuery {
  1714. query := (&SopNodeClient{config: c.config}).Query()
  1715. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1716. id := ss.ID
  1717. step := sqlgraph.NewStep(
  1718. sqlgraph.From(sopstage.Table, sopstage.FieldID, id),
  1719. sqlgraph.To(sopnode.Table, sopnode.FieldID),
  1720. sqlgraph.Edge(sqlgraph.O2M, false, sopstage.StageNodesTable, sopstage.StageNodesColumn),
  1721. )
  1722. fromV = sqlgraph.Neighbors(ss.driver.Dialect(), step)
  1723. return fromV, nil
  1724. }
  1725. return query
  1726. }
  1727. // QueryStageMessages queries the stage_messages edge of a SopStage.
  1728. func (c *SopStageClient) QueryStageMessages(ss *SopStage) *MessageRecordsQuery {
  1729. query := (&MessageRecordsClient{config: c.config}).Query()
  1730. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1731. id := ss.ID
  1732. step := sqlgraph.NewStep(
  1733. sqlgraph.From(sopstage.Table, sopstage.FieldID, id),
  1734. sqlgraph.To(messagerecords.Table, messagerecords.FieldID),
  1735. sqlgraph.Edge(sqlgraph.O2M, false, sopstage.StageMessagesTable, sopstage.StageMessagesColumn),
  1736. )
  1737. fromV = sqlgraph.Neighbors(ss.driver.Dialect(), step)
  1738. return fromV, nil
  1739. }
  1740. return query
  1741. }
  1742. // Hooks returns the client hooks.
  1743. func (c *SopStageClient) Hooks() []Hook {
  1744. hooks := c.hooks.SopStage
  1745. return append(hooks[:len(hooks):len(hooks)], sopstage.Hooks[:]...)
  1746. }
  1747. // Interceptors returns the client interceptors.
  1748. func (c *SopStageClient) Interceptors() []Interceptor {
  1749. inters := c.inters.SopStage
  1750. return append(inters[:len(inters):len(inters)], sopstage.Interceptors[:]...)
  1751. }
  1752. func (c *SopStageClient) mutate(ctx context.Context, m *SopStageMutation) (Value, error) {
  1753. switch m.Op() {
  1754. case OpCreate:
  1755. return (&SopStageCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1756. case OpUpdate:
  1757. return (&SopStageUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1758. case OpUpdateOne:
  1759. return (&SopStageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1760. case OpDelete, OpDeleteOne:
  1761. return (&SopStageDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1762. default:
  1763. return nil, fmt.Errorf("ent: unknown SopStage mutation op: %q", m.Op())
  1764. }
  1765. }
  1766. // SopTaskClient is a client for the SopTask schema.
  1767. type SopTaskClient struct {
  1768. config
  1769. }
  1770. // NewSopTaskClient returns a client for the SopTask from the given config.
  1771. func NewSopTaskClient(c config) *SopTaskClient {
  1772. return &SopTaskClient{config: c}
  1773. }
  1774. // Use adds a list of mutation hooks to the hooks stack.
  1775. // A call to `Use(f, g, h)` equals to `soptask.Hooks(f(g(h())))`.
  1776. func (c *SopTaskClient) Use(hooks ...Hook) {
  1777. c.hooks.SopTask = append(c.hooks.SopTask, hooks...)
  1778. }
  1779. // Intercept adds a list of query interceptors to the interceptors stack.
  1780. // A call to `Intercept(f, g, h)` equals to `soptask.Intercept(f(g(h())))`.
  1781. func (c *SopTaskClient) Intercept(interceptors ...Interceptor) {
  1782. c.inters.SopTask = append(c.inters.SopTask, interceptors...)
  1783. }
  1784. // Create returns a builder for creating a SopTask entity.
  1785. func (c *SopTaskClient) Create() *SopTaskCreate {
  1786. mutation := newSopTaskMutation(c.config, OpCreate)
  1787. return &SopTaskCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1788. }
  1789. // CreateBulk returns a builder for creating a bulk of SopTask entities.
  1790. func (c *SopTaskClient) CreateBulk(builders ...*SopTaskCreate) *SopTaskCreateBulk {
  1791. return &SopTaskCreateBulk{config: c.config, builders: builders}
  1792. }
  1793. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1794. // a builder and applies setFunc on it.
  1795. func (c *SopTaskClient) MapCreateBulk(slice any, setFunc func(*SopTaskCreate, int)) *SopTaskCreateBulk {
  1796. rv := reflect.ValueOf(slice)
  1797. if rv.Kind() != reflect.Slice {
  1798. return &SopTaskCreateBulk{err: fmt.Errorf("calling to SopTaskClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1799. }
  1800. builders := make([]*SopTaskCreate, rv.Len())
  1801. for i := 0; i < rv.Len(); i++ {
  1802. builders[i] = c.Create()
  1803. setFunc(builders[i], i)
  1804. }
  1805. return &SopTaskCreateBulk{config: c.config, builders: builders}
  1806. }
  1807. // Update returns an update builder for SopTask.
  1808. func (c *SopTaskClient) Update() *SopTaskUpdate {
  1809. mutation := newSopTaskMutation(c.config, OpUpdate)
  1810. return &SopTaskUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1811. }
  1812. // UpdateOne returns an update builder for the given entity.
  1813. func (c *SopTaskClient) UpdateOne(st *SopTask) *SopTaskUpdateOne {
  1814. mutation := newSopTaskMutation(c.config, OpUpdateOne, withSopTask(st))
  1815. return &SopTaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1816. }
  1817. // UpdateOneID returns an update builder for the given id.
  1818. func (c *SopTaskClient) UpdateOneID(id uint64) *SopTaskUpdateOne {
  1819. mutation := newSopTaskMutation(c.config, OpUpdateOne, withSopTaskID(id))
  1820. return &SopTaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1821. }
  1822. // Delete returns a delete builder for SopTask.
  1823. func (c *SopTaskClient) Delete() *SopTaskDelete {
  1824. mutation := newSopTaskMutation(c.config, OpDelete)
  1825. return &SopTaskDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1826. }
  1827. // DeleteOne returns a builder for deleting the given entity.
  1828. func (c *SopTaskClient) DeleteOne(st *SopTask) *SopTaskDeleteOne {
  1829. return c.DeleteOneID(st.ID)
  1830. }
  1831. // DeleteOneID returns a builder for deleting the given entity by its id.
  1832. func (c *SopTaskClient) DeleteOneID(id uint64) *SopTaskDeleteOne {
  1833. builder := c.Delete().Where(soptask.ID(id))
  1834. builder.mutation.id = &id
  1835. builder.mutation.op = OpDeleteOne
  1836. return &SopTaskDeleteOne{builder}
  1837. }
  1838. // Query returns a query builder for SopTask.
  1839. func (c *SopTaskClient) Query() *SopTaskQuery {
  1840. return &SopTaskQuery{
  1841. config: c.config,
  1842. ctx: &QueryContext{Type: TypeSopTask},
  1843. inters: c.Interceptors(),
  1844. }
  1845. }
  1846. // Get returns a SopTask entity by its id.
  1847. func (c *SopTaskClient) Get(ctx context.Context, id uint64) (*SopTask, error) {
  1848. return c.Query().Where(soptask.ID(id)).Only(ctx)
  1849. }
  1850. // GetX is like Get, but panics if an error occurs.
  1851. func (c *SopTaskClient) GetX(ctx context.Context, id uint64) *SopTask {
  1852. obj, err := c.Get(ctx, id)
  1853. if err != nil {
  1854. panic(err)
  1855. }
  1856. return obj
  1857. }
  1858. // QueryTaskStages queries the task_stages edge of a SopTask.
  1859. func (c *SopTaskClient) QueryTaskStages(st *SopTask) *SopStageQuery {
  1860. query := (&SopStageClient{config: c.config}).Query()
  1861. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1862. id := st.ID
  1863. step := sqlgraph.NewStep(
  1864. sqlgraph.From(soptask.Table, soptask.FieldID, id),
  1865. sqlgraph.To(sopstage.Table, sopstage.FieldID),
  1866. sqlgraph.Edge(sqlgraph.O2M, false, soptask.TaskStagesTable, soptask.TaskStagesColumn),
  1867. )
  1868. fromV = sqlgraph.Neighbors(st.driver.Dialect(), step)
  1869. return fromV, nil
  1870. }
  1871. return query
  1872. }
  1873. // Hooks returns the client hooks.
  1874. func (c *SopTaskClient) Hooks() []Hook {
  1875. hooks := c.hooks.SopTask
  1876. return append(hooks[:len(hooks):len(hooks)], soptask.Hooks[:]...)
  1877. }
  1878. // Interceptors returns the client interceptors.
  1879. func (c *SopTaskClient) Interceptors() []Interceptor {
  1880. inters := c.inters.SopTask
  1881. return append(inters[:len(inters):len(inters)], soptask.Interceptors[:]...)
  1882. }
  1883. func (c *SopTaskClient) mutate(ctx context.Context, m *SopTaskMutation) (Value, error) {
  1884. switch m.Op() {
  1885. case OpCreate:
  1886. return (&SopTaskCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1887. case OpUpdate:
  1888. return (&SopTaskUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1889. case OpUpdateOne:
  1890. return (&SopTaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1891. case OpDelete, OpDeleteOne:
  1892. return (&SopTaskDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1893. default:
  1894. return nil, fmt.Errorf("ent: unknown SopTask mutation op: %q", m.Op())
  1895. }
  1896. }
  1897. // WxClient is a client for the Wx schema.
  1898. type WxClient struct {
  1899. config
  1900. }
  1901. // NewWxClient returns a client for the Wx from the given config.
  1902. func NewWxClient(c config) *WxClient {
  1903. return &WxClient{config: c}
  1904. }
  1905. // Use adds a list of mutation hooks to the hooks stack.
  1906. // A call to `Use(f, g, h)` equals to `wx.Hooks(f(g(h())))`.
  1907. func (c *WxClient) Use(hooks ...Hook) {
  1908. c.hooks.Wx = append(c.hooks.Wx, hooks...)
  1909. }
  1910. // Intercept adds a list of query interceptors to the interceptors stack.
  1911. // A call to `Intercept(f, g, h)` equals to `wx.Intercept(f(g(h())))`.
  1912. func (c *WxClient) Intercept(interceptors ...Interceptor) {
  1913. c.inters.Wx = append(c.inters.Wx, interceptors...)
  1914. }
  1915. // Create returns a builder for creating a Wx entity.
  1916. func (c *WxClient) Create() *WxCreate {
  1917. mutation := newWxMutation(c.config, OpCreate)
  1918. return &WxCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1919. }
  1920. // CreateBulk returns a builder for creating a bulk of Wx entities.
  1921. func (c *WxClient) CreateBulk(builders ...*WxCreate) *WxCreateBulk {
  1922. return &WxCreateBulk{config: c.config, builders: builders}
  1923. }
  1924. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1925. // a builder and applies setFunc on it.
  1926. func (c *WxClient) MapCreateBulk(slice any, setFunc func(*WxCreate, int)) *WxCreateBulk {
  1927. rv := reflect.ValueOf(slice)
  1928. if rv.Kind() != reflect.Slice {
  1929. return &WxCreateBulk{err: fmt.Errorf("calling to WxClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1930. }
  1931. builders := make([]*WxCreate, rv.Len())
  1932. for i := 0; i < rv.Len(); i++ {
  1933. builders[i] = c.Create()
  1934. setFunc(builders[i], i)
  1935. }
  1936. return &WxCreateBulk{config: c.config, builders: builders}
  1937. }
  1938. // Update returns an update builder for Wx.
  1939. func (c *WxClient) Update() *WxUpdate {
  1940. mutation := newWxMutation(c.config, OpUpdate)
  1941. return &WxUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1942. }
  1943. // UpdateOne returns an update builder for the given entity.
  1944. func (c *WxClient) UpdateOne(w *Wx) *WxUpdateOne {
  1945. mutation := newWxMutation(c.config, OpUpdateOne, withWx(w))
  1946. return &WxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1947. }
  1948. // UpdateOneID returns an update builder for the given id.
  1949. func (c *WxClient) UpdateOneID(id uint64) *WxUpdateOne {
  1950. mutation := newWxMutation(c.config, OpUpdateOne, withWxID(id))
  1951. return &WxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1952. }
  1953. // Delete returns a delete builder for Wx.
  1954. func (c *WxClient) Delete() *WxDelete {
  1955. mutation := newWxMutation(c.config, OpDelete)
  1956. return &WxDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1957. }
  1958. // DeleteOne returns a builder for deleting the given entity.
  1959. func (c *WxClient) DeleteOne(w *Wx) *WxDeleteOne {
  1960. return c.DeleteOneID(w.ID)
  1961. }
  1962. // DeleteOneID returns a builder for deleting the given entity by its id.
  1963. func (c *WxClient) DeleteOneID(id uint64) *WxDeleteOne {
  1964. builder := c.Delete().Where(wx.ID(id))
  1965. builder.mutation.id = &id
  1966. builder.mutation.op = OpDeleteOne
  1967. return &WxDeleteOne{builder}
  1968. }
  1969. // Query returns a query builder for Wx.
  1970. func (c *WxClient) Query() *WxQuery {
  1971. return &WxQuery{
  1972. config: c.config,
  1973. ctx: &QueryContext{Type: TypeWx},
  1974. inters: c.Interceptors(),
  1975. }
  1976. }
  1977. // Get returns a Wx entity by its id.
  1978. func (c *WxClient) Get(ctx context.Context, id uint64) (*Wx, error) {
  1979. return c.Query().Where(wx.ID(id)).Only(ctx)
  1980. }
  1981. // GetX is like Get, but panics if an error occurs.
  1982. func (c *WxClient) GetX(ctx context.Context, id uint64) *Wx {
  1983. obj, err := c.Get(ctx, id)
  1984. if err != nil {
  1985. panic(err)
  1986. }
  1987. return obj
  1988. }
  1989. // QueryServer queries the server edge of a Wx.
  1990. func (c *WxClient) QueryServer(w *Wx) *ServerQuery {
  1991. query := (&ServerClient{config: c.config}).Query()
  1992. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1993. id := w.ID
  1994. step := sqlgraph.NewStep(
  1995. sqlgraph.From(wx.Table, wx.FieldID, id),
  1996. sqlgraph.To(server.Table, server.FieldID),
  1997. sqlgraph.Edge(sqlgraph.M2O, true, wx.ServerTable, wx.ServerColumn),
  1998. )
  1999. fromV = sqlgraph.Neighbors(w.driver.Dialect(), step)
  2000. return fromV, nil
  2001. }
  2002. return query
  2003. }
  2004. // Hooks returns the client hooks.
  2005. func (c *WxClient) Hooks() []Hook {
  2006. hooks := c.hooks.Wx
  2007. return append(hooks[:len(hooks):len(hooks)], wx.Hooks[:]...)
  2008. }
  2009. // Interceptors returns the client interceptors.
  2010. func (c *WxClient) Interceptors() []Interceptor {
  2011. inters := c.inters.Wx
  2012. return append(inters[:len(inters):len(inters)], wx.Interceptors[:]...)
  2013. }
  2014. func (c *WxClient) mutate(ctx context.Context, m *WxMutation) (Value, error) {
  2015. switch m.Op() {
  2016. case OpCreate:
  2017. return (&WxCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2018. case OpUpdate:
  2019. return (&WxUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2020. case OpUpdateOne:
  2021. return (&WxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2022. case OpDelete, OpDeleteOne:
  2023. return (&WxDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  2024. default:
  2025. return nil, fmt.Errorf("ent: unknown Wx mutation op: %q", m.Op())
  2026. }
  2027. }
  2028. // hooks and interceptors per client, for fast access.
  2029. type (
  2030. hooks struct {
  2031. Agent, BatchMsg, Contact, Label, LabelRelationship, Message, MessageRecords,
  2032. Msg, Server, SopNode, SopStage, SopTask, Wx []ent.Hook
  2033. }
  2034. inters struct {
  2035. Agent, BatchMsg, Contact, Label, LabelRelationship, Message, MessageRecords,
  2036. Msg, Server, SopNode, SopStage, SopTask, Wx []ent.Interceptor
  2037. }
  2038. )
  2039. // ExecContext allows calling the underlying ExecContext method of the driver if it is supported by it.
  2040. // See, database/sql#DB.ExecContext for more information.
  2041. func (c *config) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) {
  2042. ex, ok := c.driver.(interface {
  2043. ExecContext(context.Context, string, ...any) (stdsql.Result, error)
  2044. })
  2045. if !ok {
  2046. return nil, fmt.Errorf("Driver.ExecContext is not supported")
  2047. }
  2048. return ex.ExecContext(ctx, query, args...)
  2049. }
  2050. // QueryContext allows calling the underlying QueryContext method of the driver if it is supported by it.
  2051. // See, database/sql#DB.QueryContext for more information.
  2052. func (c *config) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) {
  2053. q, ok := c.driver.(interface {
  2054. QueryContext(context.Context, string, ...any) (*stdsql.Rows, error)
  2055. })
  2056. if !ok {
  2057. return nil, fmt.Errorf("Driver.QueryContext is not supported")
  2058. }
  2059. return q.QueryContext(ctx, query, args...)
  2060. }