client.go 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382
  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. // QueryWxAgent queries the wx_agent edge of a Agent.
  377. func (c *AgentClient) QueryWxAgent(a *Agent) *WxQuery {
  378. query := (&WxClient{config: c.config}).Query()
  379. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  380. id := a.ID
  381. step := sqlgraph.NewStep(
  382. sqlgraph.From(agent.Table, agent.FieldID, id),
  383. sqlgraph.To(wx.Table, wx.FieldID),
  384. sqlgraph.Edge(sqlgraph.O2M, false, agent.WxAgentTable, agent.WxAgentColumn),
  385. )
  386. fromV = sqlgraph.Neighbors(a.driver.Dialect(), step)
  387. return fromV, nil
  388. }
  389. return query
  390. }
  391. // Hooks returns the client hooks.
  392. func (c *AgentClient) Hooks() []Hook {
  393. hooks := c.hooks.Agent
  394. return append(hooks[:len(hooks):len(hooks)], agent.Hooks[:]...)
  395. }
  396. // Interceptors returns the client interceptors.
  397. func (c *AgentClient) Interceptors() []Interceptor {
  398. inters := c.inters.Agent
  399. return append(inters[:len(inters):len(inters)], agent.Interceptors[:]...)
  400. }
  401. func (c *AgentClient) mutate(ctx context.Context, m *AgentMutation) (Value, error) {
  402. switch m.Op() {
  403. case OpCreate:
  404. return (&AgentCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  405. case OpUpdate:
  406. return (&AgentUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  407. case OpUpdateOne:
  408. return (&AgentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  409. case OpDelete, OpDeleteOne:
  410. return (&AgentDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  411. default:
  412. return nil, fmt.Errorf("ent: unknown Agent mutation op: %q", m.Op())
  413. }
  414. }
  415. // BatchMsgClient is a client for the BatchMsg schema.
  416. type BatchMsgClient struct {
  417. config
  418. }
  419. // NewBatchMsgClient returns a client for the BatchMsg from the given config.
  420. func NewBatchMsgClient(c config) *BatchMsgClient {
  421. return &BatchMsgClient{config: c}
  422. }
  423. // Use adds a list of mutation hooks to the hooks stack.
  424. // A call to `Use(f, g, h)` equals to `batchmsg.Hooks(f(g(h())))`.
  425. func (c *BatchMsgClient) Use(hooks ...Hook) {
  426. c.hooks.BatchMsg = append(c.hooks.BatchMsg, hooks...)
  427. }
  428. // Intercept adds a list of query interceptors to the interceptors stack.
  429. // A call to `Intercept(f, g, h)` equals to `batchmsg.Intercept(f(g(h())))`.
  430. func (c *BatchMsgClient) Intercept(interceptors ...Interceptor) {
  431. c.inters.BatchMsg = append(c.inters.BatchMsg, interceptors...)
  432. }
  433. // Create returns a builder for creating a BatchMsg entity.
  434. func (c *BatchMsgClient) Create() *BatchMsgCreate {
  435. mutation := newBatchMsgMutation(c.config, OpCreate)
  436. return &BatchMsgCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  437. }
  438. // CreateBulk returns a builder for creating a bulk of BatchMsg entities.
  439. func (c *BatchMsgClient) CreateBulk(builders ...*BatchMsgCreate) *BatchMsgCreateBulk {
  440. return &BatchMsgCreateBulk{config: c.config, builders: builders}
  441. }
  442. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  443. // a builder and applies setFunc on it.
  444. func (c *BatchMsgClient) MapCreateBulk(slice any, setFunc func(*BatchMsgCreate, int)) *BatchMsgCreateBulk {
  445. rv := reflect.ValueOf(slice)
  446. if rv.Kind() != reflect.Slice {
  447. return &BatchMsgCreateBulk{err: fmt.Errorf("calling to BatchMsgClient.MapCreateBulk with wrong type %T, need slice", slice)}
  448. }
  449. builders := make([]*BatchMsgCreate, rv.Len())
  450. for i := 0; i < rv.Len(); i++ {
  451. builders[i] = c.Create()
  452. setFunc(builders[i], i)
  453. }
  454. return &BatchMsgCreateBulk{config: c.config, builders: builders}
  455. }
  456. // Update returns an update builder for BatchMsg.
  457. func (c *BatchMsgClient) Update() *BatchMsgUpdate {
  458. mutation := newBatchMsgMutation(c.config, OpUpdate)
  459. return &BatchMsgUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  460. }
  461. // UpdateOne returns an update builder for the given entity.
  462. func (c *BatchMsgClient) UpdateOne(bm *BatchMsg) *BatchMsgUpdateOne {
  463. mutation := newBatchMsgMutation(c.config, OpUpdateOne, withBatchMsg(bm))
  464. return &BatchMsgUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  465. }
  466. // UpdateOneID returns an update builder for the given id.
  467. func (c *BatchMsgClient) UpdateOneID(id uint64) *BatchMsgUpdateOne {
  468. mutation := newBatchMsgMutation(c.config, OpUpdateOne, withBatchMsgID(id))
  469. return &BatchMsgUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  470. }
  471. // Delete returns a delete builder for BatchMsg.
  472. func (c *BatchMsgClient) Delete() *BatchMsgDelete {
  473. mutation := newBatchMsgMutation(c.config, OpDelete)
  474. return &BatchMsgDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  475. }
  476. // DeleteOne returns a builder for deleting the given entity.
  477. func (c *BatchMsgClient) DeleteOne(bm *BatchMsg) *BatchMsgDeleteOne {
  478. return c.DeleteOneID(bm.ID)
  479. }
  480. // DeleteOneID returns a builder for deleting the given entity by its id.
  481. func (c *BatchMsgClient) DeleteOneID(id uint64) *BatchMsgDeleteOne {
  482. builder := c.Delete().Where(batchmsg.ID(id))
  483. builder.mutation.id = &id
  484. builder.mutation.op = OpDeleteOne
  485. return &BatchMsgDeleteOne{builder}
  486. }
  487. // Query returns a query builder for BatchMsg.
  488. func (c *BatchMsgClient) Query() *BatchMsgQuery {
  489. return &BatchMsgQuery{
  490. config: c.config,
  491. ctx: &QueryContext{Type: TypeBatchMsg},
  492. inters: c.Interceptors(),
  493. }
  494. }
  495. // Get returns a BatchMsg entity by its id.
  496. func (c *BatchMsgClient) Get(ctx context.Context, id uint64) (*BatchMsg, error) {
  497. return c.Query().Where(batchmsg.ID(id)).Only(ctx)
  498. }
  499. // GetX is like Get, but panics if an error occurs.
  500. func (c *BatchMsgClient) GetX(ctx context.Context, id uint64) *BatchMsg {
  501. obj, err := c.Get(ctx, id)
  502. if err != nil {
  503. panic(err)
  504. }
  505. return obj
  506. }
  507. // Hooks returns the client hooks.
  508. func (c *BatchMsgClient) Hooks() []Hook {
  509. hooks := c.hooks.BatchMsg
  510. return append(hooks[:len(hooks):len(hooks)], batchmsg.Hooks[:]...)
  511. }
  512. // Interceptors returns the client interceptors.
  513. func (c *BatchMsgClient) Interceptors() []Interceptor {
  514. inters := c.inters.BatchMsg
  515. return append(inters[:len(inters):len(inters)], batchmsg.Interceptors[:]...)
  516. }
  517. func (c *BatchMsgClient) mutate(ctx context.Context, m *BatchMsgMutation) (Value, error) {
  518. switch m.Op() {
  519. case OpCreate:
  520. return (&BatchMsgCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  521. case OpUpdate:
  522. return (&BatchMsgUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  523. case OpUpdateOne:
  524. return (&BatchMsgUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  525. case OpDelete, OpDeleteOne:
  526. return (&BatchMsgDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  527. default:
  528. return nil, fmt.Errorf("ent: unknown BatchMsg mutation op: %q", m.Op())
  529. }
  530. }
  531. // ContactClient is a client for the Contact schema.
  532. type ContactClient struct {
  533. config
  534. }
  535. // NewContactClient returns a client for the Contact from the given config.
  536. func NewContactClient(c config) *ContactClient {
  537. return &ContactClient{config: c}
  538. }
  539. // Use adds a list of mutation hooks to the hooks stack.
  540. // A call to `Use(f, g, h)` equals to `contact.Hooks(f(g(h())))`.
  541. func (c *ContactClient) Use(hooks ...Hook) {
  542. c.hooks.Contact = append(c.hooks.Contact, hooks...)
  543. }
  544. // Intercept adds a list of query interceptors to the interceptors stack.
  545. // A call to `Intercept(f, g, h)` equals to `contact.Intercept(f(g(h())))`.
  546. func (c *ContactClient) Intercept(interceptors ...Interceptor) {
  547. c.inters.Contact = append(c.inters.Contact, interceptors...)
  548. }
  549. // Create returns a builder for creating a Contact entity.
  550. func (c *ContactClient) Create() *ContactCreate {
  551. mutation := newContactMutation(c.config, OpCreate)
  552. return &ContactCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  553. }
  554. // CreateBulk returns a builder for creating a bulk of Contact entities.
  555. func (c *ContactClient) CreateBulk(builders ...*ContactCreate) *ContactCreateBulk {
  556. return &ContactCreateBulk{config: c.config, builders: builders}
  557. }
  558. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  559. // a builder and applies setFunc on it.
  560. func (c *ContactClient) MapCreateBulk(slice any, setFunc func(*ContactCreate, int)) *ContactCreateBulk {
  561. rv := reflect.ValueOf(slice)
  562. if rv.Kind() != reflect.Slice {
  563. return &ContactCreateBulk{err: fmt.Errorf("calling to ContactClient.MapCreateBulk with wrong type %T, need slice", slice)}
  564. }
  565. builders := make([]*ContactCreate, rv.Len())
  566. for i := 0; i < rv.Len(); i++ {
  567. builders[i] = c.Create()
  568. setFunc(builders[i], i)
  569. }
  570. return &ContactCreateBulk{config: c.config, builders: builders}
  571. }
  572. // Update returns an update builder for Contact.
  573. func (c *ContactClient) Update() *ContactUpdate {
  574. mutation := newContactMutation(c.config, OpUpdate)
  575. return &ContactUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  576. }
  577. // UpdateOne returns an update builder for the given entity.
  578. func (c *ContactClient) UpdateOne(co *Contact) *ContactUpdateOne {
  579. mutation := newContactMutation(c.config, OpUpdateOne, withContact(co))
  580. return &ContactUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  581. }
  582. // UpdateOneID returns an update builder for the given id.
  583. func (c *ContactClient) UpdateOneID(id uint64) *ContactUpdateOne {
  584. mutation := newContactMutation(c.config, OpUpdateOne, withContactID(id))
  585. return &ContactUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  586. }
  587. // Delete returns a delete builder for Contact.
  588. func (c *ContactClient) Delete() *ContactDelete {
  589. mutation := newContactMutation(c.config, OpDelete)
  590. return &ContactDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  591. }
  592. // DeleteOne returns a builder for deleting the given entity.
  593. func (c *ContactClient) DeleteOne(co *Contact) *ContactDeleteOne {
  594. return c.DeleteOneID(co.ID)
  595. }
  596. // DeleteOneID returns a builder for deleting the given entity by its id.
  597. func (c *ContactClient) DeleteOneID(id uint64) *ContactDeleteOne {
  598. builder := c.Delete().Where(contact.ID(id))
  599. builder.mutation.id = &id
  600. builder.mutation.op = OpDeleteOne
  601. return &ContactDeleteOne{builder}
  602. }
  603. // Query returns a query builder for Contact.
  604. func (c *ContactClient) Query() *ContactQuery {
  605. return &ContactQuery{
  606. config: c.config,
  607. ctx: &QueryContext{Type: TypeContact},
  608. inters: c.Interceptors(),
  609. }
  610. }
  611. // Get returns a Contact entity by its id.
  612. func (c *ContactClient) Get(ctx context.Context, id uint64) (*Contact, error) {
  613. return c.Query().Where(contact.ID(id)).Only(ctx)
  614. }
  615. // GetX is like Get, but panics if an error occurs.
  616. func (c *ContactClient) GetX(ctx context.Context, id uint64) *Contact {
  617. obj, err := c.Get(ctx, id)
  618. if err != nil {
  619. panic(err)
  620. }
  621. return obj
  622. }
  623. // QueryContactRelationships queries the contact_relationships edge of a Contact.
  624. func (c *ContactClient) QueryContactRelationships(co *Contact) *LabelRelationshipQuery {
  625. query := (&LabelRelationshipClient{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(labelrelationship.Table, labelrelationship.FieldID),
  631. sqlgraph.Edge(sqlgraph.O2M, false, contact.ContactRelationshipsTable, contact.ContactRelationshipsColumn),
  632. )
  633. fromV = sqlgraph.Neighbors(co.driver.Dialect(), step)
  634. return fromV, nil
  635. }
  636. return query
  637. }
  638. // QueryContactMessages queries the contact_messages edge of a Contact.
  639. func (c *ContactClient) QueryContactMessages(co *Contact) *MessageRecordsQuery {
  640. query := (&MessageRecordsClient{config: c.config}).Query()
  641. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  642. id := co.ID
  643. step := sqlgraph.NewStep(
  644. sqlgraph.From(contact.Table, contact.FieldID, id),
  645. sqlgraph.To(messagerecords.Table, messagerecords.FieldID),
  646. sqlgraph.Edge(sqlgraph.O2M, false, contact.ContactMessagesTable, contact.ContactMessagesColumn),
  647. )
  648. fromV = sqlgraph.Neighbors(co.driver.Dialect(), step)
  649. return fromV, nil
  650. }
  651. return query
  652. }
  653. // Hooks returns the client hooks.
  654. func (c *ContactClient) Hooks() []Hook {
  655. hooks := c.hooks.Contact
  656. return append(hooks[:len(hooks):len(hooks)], contact.Hooks[:]...)
  657. }
  658. // Interceptors returns the client interceptors.
  659. func (c *ContactClient) Interceptors() []Interceptor {
  660. inters := c.inters.Contact
  661. return append(inters[:len(inters):len(inters)], contact.Interceptors[:]...)
  662. }
  663. func (c *ContactClient) mutate(ctx context.Context, m *ContactMutation) (Value, error) {
  664. switch m.Op() {
  665. case OpCreate:
  666. return (&ContactCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  667. case OpUpdate:
  668. return (&ContactUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  669. case OpUpdateOne:
  670. return (&ContactUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  671. case OpDelete, OpDeleteOne:
  672. return (&ContactDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  673. default:
  674. return nil, fmt.Errorf("ent: unknown Contact mutation op: %q", m.Op())
  675. }
  676. }
  677. // LabelClient is a client for the Label schema.
  678. type LabelClient struct {
  679. config
  680. }
  681. // NewLabelClient returns a client for the Label from the given config.
  682. func NewLabelClient(c config) *LabelClient {
  683. return &LabelClient{config: c}
  684. }
  685. // Use adds a list of mutation hooks to the hooks stack.
  686. // A call to `Use(f, g, h)` equals to `label.Hooks(f(g(h())))`.
  687. func (c *LabelClient) Use(hooks ...Hook) {
  688. c.hooks.Label = append(c.hooks.Label, hooks...)
  689. }
  690. // Intercept adds a list of query interceptors to the interceptors stack.
  691. // A call to `Intercept(f, g, h)` equals to `label.Intercept(f(g(h())))`.
  692. func (c *LabelClient) Intercept(interceptors ...Interceptor) {
  693. c.inters.Label = append(c.inters.Label, interceptors...)
  694. }
  695. // Create returns a builder for creating a Label entity.
  696. func (c *LabelClient) Create() *LabelCreate {
  697. mutation := newLabelMutation(c.config, OpCreate)
  698. return &LabelCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  699. }
  700. // CreateBulk returns a builder for creating a bulk of Label entities.
  701. func (c *LabelClient) CreateBulk(builders ...*LabelCreate) *LabelCreateBulk {
  702. return &LabelCreateBulk{config: c.config, builders: builders}
  703. }
  704. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  705. // a builder and applies setFunc on it.
  706. func (c *LabelClient) MapCreateBulk(slice any, setFunc func(*LabelCreate, int)) *LabelCreateBulk {
  707. rv := reflect.ValueOf(slice)
  708. if rv.Kind() != reflect.Slice {
  709. return &LabelCreateBulk{err: fmt.Errorf("calling to LabelClient.MapCreateBulk with wrong type %T, need slice", slice)}
  710. }
  711. builders := make([]*LabelCreate, rv.Len())
  712. for i := 0; i < rv.Len(); i++ {
  713. builders[i] = c.Create()
  714. setFunc(builders[i], i)
  715. }
  716. return &LabelCreateBulk{config: c.config, builders: builders}
  717. }
  718. // Update returns an update builder for Label.
  719. func (c *LabelClient) Update() *LabelUpdate {
  720. mutation := newLabelMutation(c.config, OpUpdate)
  721. return &LabelUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  722. }
  723. // UpdateOne returns an update builder for the given entity.
  724. func (c *LabelClient) UpdateOne(l *Label) *LabelUpdateOne {
  725. mutation := newLabelMutation(c.config, OpUpdateOne, withLabel(l))
  726. return &LabelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  727. }
  728. // UpdateOneID returns an update builder for the given id.
  729. func (c *LabelClient) UpdateOneID(id uint64) *LabelUpdateOne {
  730. mutation := newLabelMutation(c.config, OpUpdateOne, withLabelID(id))
  731. return &LabelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  732. }
  733. // Delete returns a delete builder for Label.
  734. func (c *LabelClient) Delete() *LabelDelete {
  735. mutation := newLabelMutation(c.config, OpDelete)
  736. return &LabelDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  737. }
  738. // DeleteOne returns a builder for deleting the given entity.
  739. func (c *LabelClient) DeleteOne(l *Label) *LabelDeleteOne {
  740. return c.DeleteOneID(l.ID)
  741. }
  742. // DeleteOneID returns a builder for deleting the given entity by its id.
  743. func (c *LabelClient) DeleteOneID(id uint64) *LabelDeleteOne {
  744. builder := c.Delete().Where(label.ID(id))
  745. builder.mutation.id = &id
  746. builder.mutation.op = OpDeleteOne
  747. return &LabelDeleteOne{builder}
  748. }
  749. // Query returns a query builder for Label.
  750. func (c *LabelClient) Query() *LabelQuery {
  751. return &LabelQuery{
  752. config: c.config,
  753. ctx: &QueryContext{Type: TypeLabel},
  754. inters: c.Interceptors(),
  755. }
  756. }
  757. // Get returns a Label entity by its id.
  758. func (c *LabelClient) Get(ctx context.Context, id uint64) (*Label, error) {
  759. return c.Query().Where(label.ID(id)).Only(ctx)
  760. }
  761. // GetX is like Get, but panics if an error occurs.
  762. func (c *LabelClient) GetX(ctx context.Context, id uint64) *Label {
  763. obj, err := c.Get(ctx, id)
  764. if err != nil {
  765. panic(err)
  766. }
  767. return obj
  768. }
  769. // QueryLabelRelationships queries the label_relationships edge of a Label.
  770. func (c *LabelClient) QueryLabelRelationships(l *Label) *LabelRelationshipQuery {
  771. query := (&LabelRelationshipClient{config: c.config}).Query()
  772. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  773. id := l.ID
  774. step := sqlgraph.NewStep(
  775. sqlgraph.From(label.Table, label.FieldID, id),
  776. sqlgraph.To(labelrelationship.Table, labelrelationship.FieldID),
  777. sqlgraph.Edge(sqlgraph.O2M, false, label.LabelRelationshipsTable, label.LabelRelationshipsColumn),
  778. )
  779. fromV = sqlgraph.Neighbors(l.driver.Dialect(), step)
  780. return fromV, nil
  781. }
  782. return query
  783. }
  784. // Hooks returns the client hooks.
  785. func (c *LabelClient) Hooks() []Hook {
  786. return c.hooks.Label
  787. }
  788. // Interceptors returns the client interceptors.
  789. func (c *LabelClient) Interceptors() []Interceptor {
  790. return c.inters.Label
  791. }
  792. func (c *LabelClient) mutate(ctx context.Context, m *LabelMutation) (Value, error) {
  793. switch m.Op() {
  794. case OpCreate:
  795. return (&LabelCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  796. case OpUpdate:
  797. return (&LabelUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  798. case OpUpdateOne:
  799. return (&LabelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  800. case OpDelete, OpDeleteOne:
  801. return (&LabelDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  802. default:
  803. return nil, fmt.Errorf("ent: unknown Label mutation op: %q", m.Op())
  804. }
  805. }
  806. // LabelRelationshipClient is a client for the LabelRelationship schema.
  807. type LabelRelationshipClient struct {
  808. config
  809. }
  810. // NewLabelRelationshipClient returns a client for the LabelRelationship from the given config.
  811. func NewLabelRelationshipClient(c config) *LabelRelationshipClient {
  812. return &LabelRelationshipClient{config: c}
  813. }
  814. // Use adds a list of mutation hooks to the hooks stack.
  815. // A call to `Use(f, g, h)` equals to `labelrelationship.Hooks(f(g(h())))`.
  816. func (c *LabelRelationshipClient) Use(hooks ...Hook) {
  817. c.hooks.LabelRelationship = append(c.hooks.LabelRelationship, hooks...)
  818. }
  819. // Intercept adds a list of query interceptors to the interceptors stack.
  820. // A call to `Intercept(f, g, h)` equals to `labelrelationship.Intercept(f(g(h())))`.
  821. func (c *LabelRelationshipClient) Intercept(interceptors ...Interceptor) {
  822. c.inters.LabelRelationship = append(c.inters.LabelRelationship, interceptors...)
  823. }
  824. // Create returns a builder for creating a LabelRelationship entity.
  825. func (c *LabelRelationshipClient) Create() *LabelRelationshipCreate {
  826. mutation := newLabelRelationshipMutation(c.config, OpCreate)
  827. return &LabelRelationshipCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  828. }
  829. // CreateBulk returns a builder for creating a bulk of LabelRelationship entities.
  830. func (c *LabelRelationshipClient) CreateBulk(builders ...*LabelRelationshipCreate) *LabelRelationshipCreateBulk {
  831. return &LabelRelationshipCreateBulk{config: c.config, builders: builders}
  832. }
  833. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  834. // a builder and applies setFunc on it.
  835. func (c *LabelRelationshipClient) MapCreateBulk(slice any, setFunc func(*LabelRelationshipCreate, int)) *LabelRelationshipCreateBulk {
  836. rv := reflect.ValueOf(slice)
  837. if rv.Kind() != reflect.Slice {
  838. return &LabelRelationshipCreateBulk{err: fmt.Errorf("calling to LabelRelationshipClient.MapCreateBulk with wrong type %T, need slice", slice)}
  839. }
  840. builders := make([]*LabelRelationshipCreate, rv.Len())
  841. for i := 0; i < rv.Len(); i++ {
  842. builders[i] = c.Create()
  843. setFunc(builders[i], i)
  844. }
  845. return &LabelRelationshipCreateBulk{config: c.config, builders: builders}
  846. }
  847. // Update returns an update builder for LabelRelationship.
  848. func (c *LabelRelationshipClient) Update() *LabelRelationshipUpdate {
  849. mutation := newLabelRelationshipMutation(c.config, OpUpdate)
  850. return &LabelRelationshipUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  851. }
  852. // UpdateOne returns an update builder for the given entity.
  853. func (c *LabelRelationshipClient) UpdateOne(lr *LabelRelationship) *LabelRelationshipUpdateOne {
  854. mutation := newLabelRelationshipMutation(c.config, OpUpdateOne, withLabelRelationship(lr))
  855. return &LabelRelationshipUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  856. }
  857. // UpdateOneID returns an update builder for the given id.
  858. func (c *LabelRelationshipClient) UpdateOneID(id uint64) *LabelRelationshipUpdateOne {
  859. mutation := newLabelRelationshipMutation(c.config, OpUpdateOne, withLabelRelationshipID(id))
  860. return &LabelRelationshipUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  861. }
  862. // Delete returns a delete builder for LabelRelationship.
  863. func (c *LabelRelationshipClient) Delete() *LabelRelationshipDelete {
  864. mutation := newLabelRelationshipMutation(c.config, OpDelete)
  865. return &LabelRelationshipDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  866. }
  867. // DeleteOne returns a builder for deleting the given entity.
  868. func (c *LabelRelationshipClient) DeleteOne(lr *LabelRelationship) *LabelRelationshipDeleteOne {
  869. return c.DeleteOneID(lr.ID)
  870. }
  871. // DeleteOneID returns a builder for deleting the given entity by its id.
  872. func (c *LabelRelationshipClient) DeleteOneID(id uint64) *LabelRelationshipDeleteOne {
  873. builder := c.Delete().Where(labelrelationship.ID(id))
  874. builder.mutation.id = &id
  875. builder.mutation.op = OpDeleteOne
  876. return &LabelRelationshipDeleteOne{builder}
  877. }
  878. // Query returns a query builder for LabelRelationship.
  879. func (c *LabelRelationshipClient) Query() *LabelRelationshipQuery {
  880. return &LabelRelationshipQuery{
  881. config: c.config,
  882. ctx: &QueryContext{Type: TypeLabelRelationship},
  883. inters: c.Interceptors(),
  884. }
  885. }
  886. // Get returns a LabelRelationship entity by its id.
  887. func (c *LabelRelationshipClient) Get(ctx context.Context, id uint64) (*LabelRelationship, error) {
  888. return c.Query().Where(labelrelationship.ID(id)).Only(ctx)
  889. }
  890. // GetX is like Get, but panics if an error occurs.
  891. func (c *LabelRelationshipClient) GetX(ctx context.Context, id uint64) *LabelRelationship {
  892. obj, err := c.Get(ctx, id)
  893. if err != nil {
  894. panic(err)
  895. }
  896. return obj
  897. }
  898. // QueryContacts queries the contacts edge of a LabelRelationship.
  899. func (c *LabelRelationshipClient) QueryContacts(lr *LabelRelationship) *ContactQuery {
  900. query := (&ContactClient{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(contact.Table, contact.FieldID),
  906. sqlgraph.Edge(sqlgraph.M2O, true, labelrelationship.ContactsTable, labelrelationship.ContactsColumn),
  907. )
  908. fromV = sqlgraph.Neighbors(lr.driver.Dialect(), step)
  909. return fromV, nil
  910. }
  911. return query
  912. }
  913. // QueryLabels queries the labels edge of a LabelRelationship.
  914. func (c *LabelRelationshipClient) QueryLabels(lr *LabelRelationship) *LabelQuery {
  915. query := (&LabelClient{config: c.config}).Query()
  916. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  917. id := lr.ID
  918. step := sqlgraph.NewStep(
  919. sqlgraph.From(labelrelationship.Table, labelrelationship.FieldID, id),
  920. sqlgraph.To(label.Table, label.FieldID),
  921. sqlgraph.Edge(sqlgraph.M2O, true, labelrelationship.LabelsTable, labelrelationship.LabelsColumn),
  922. )
  923. fromV = sqlgraph.Neighbors(lr.driver.Dialect(), step)
  924. return fromV, nil
  925. }
  926. return query
  927. }
  928. // Hooks returns the client hooks.
  929. func (c *LabelRelationshipClient) Hooks() []Hook {
  930. hooks := c.hooks.LabelRelationship
  931. return append(hooks[:len(hooks):len(hooks)], labelrelationship.Hooks[:]...)
  932. }
  933. // Interceptors returns the client interceptors.
  934. func (c *LabelRelationshipClient) Interceptors() []Interceptor {
  935. inters := c.inters.LabelRelationship
  936. return append(inters[:len(inters):len(inters)], labelrelationship.Interceptors[:]...)
  937. }
  938. func (c *LabelRelationshipClient) mutate(ctx context.Context, m *LabelRelationshipMutation) (Value, error) {
  939. switch m.Op() {
  940. case OpCreate:
  941. return (&LabelRelationshipCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  942. case OpUpdate:
  943. return (&LabelRelationshipUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  944. case OpUpdateOne:
  945. return (&LabelRelationshipUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  946. case OpDelete, OpDeleteOne:
  947. return (&LabelRelationshipDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  948. default:
  949. return nil, fmt.Errorf("ent: unknown LabelRelationship mutation op: %q", m.Op())
  950. }
  951. }
  952. // MessageClient is a client for the Message schema.
  953. type MessageClient struct {
  954. config
  955. }
  956. // NewMessageClient returns a client for the Message from the given config.
  957. func NewMessageClient(c config) *MessageClient {
  958. return &MessageClient{config: c}
  959. }
  960. // Use adds a list of mutation hooks to the hooks stack.
  961. // A call to `Use(f, g, h)` equals to `message.Hooks(f(g(h())))`.
  962. func (c *MessageClient) Use(hooks ...Hook) {
  963. c.hooks.Message = append(c.hooks.Message, hooks...)
  964. }
  965. // Intercept adds a list of query interceptors to the interceptors stack.
  966. // A call to `Intercept(f, g, h)` equals to `message.Intercept(f(g(h())))`.
  967. func (c *MessageClient) Intercept(interceptors ...Interceptor) {
  968. c.inters.Message = append(c.inters.Message, interceptors...)
  969. }
  970. // Create returns a builder for creating a Message entity.
  971. func (c *MessageClient) Create() *MessageCreate {
  972. mutation := newMessageMutation(c.config, OpCreate)
  973. return &MessageCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  974. }
  975. // CreateBulk returns a builder for creating a bulk of Message entities.
  976. func (c *MessageClient) CreateBulk(builders ...*MessageCreate) *MessageCreateBulk {
  977. return &MessageCreateBulk{config: c.config, builders: builders}
  978. }
  979. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  980. // a builder and applies setFunc on it.
  981. func (c *MessageClient) MapCreateBulk(slice any, setFunc func(*MessageCreate, int)) *MessageCreateBulk {
  982. rv := reflect.ValueOf(slice)
  983. if rv.Kind() != reflect.Slice {
  984. return &MessageCreateBulk{err: fmt.Errorf("calling to MessageClient.MapCreateBulk with wrong type %T, need slice", slice)}
  985. }
  986. builders := make([]*MessageCreate, rv.Len())
  987. for i := 0; i < rv.Len(); i++ {
  988. builders[i] = c.Create()
  989. setFunc(builders[i], i)
  990. }
  991. return &MessageCreateBulk{config: c.config, builders: builders}
  992. }
  993. // Update returns an update builder for Message.
  994. func (c *MessageClient) Update() *MessageUpdate {
  995. mutation := newMessageMutation(c.config, OpUpdate)
  996. return &MessageUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  997. }
  998. // UpdateOne returns an update builder for the given entity.
  999. func (c *MessageClient) UpdateOne(m *Message) *MessageUpdateOne {
  1000. mutation := newMessageMutation(c.config, OpUpdateOne, withMessage(m))
  1001. return &MessageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1002. }
  1003. // UpdateOneID returns an update builder for the given id.
  1004. func (c *MessageClient) UpdateOneID(id int) *MessageUpdateOne {
  1005. mutation := newMessageMutation(c.config, OpUpdateOne, withMessageID(id))
  1006. return &MessageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1007. }
  1008. // Delete returns a delete builder for Message.
  1009. func (c *MessageClient) Delete() *MessageDelete {
  1010. mutation := newMessageMutation(c.config, OpDelete)
  1011. return &MessageDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1012. }
  1013. // DeleteOne returns a builder for deleting the given entity.
  1014. func (c *MessageClient) DeleteOne(m *Message) *MessageDeleteOne {
  1015. return c.DeleteOneID(m.ID)
  1016. }
  1017. // DeleteOneID returns a builder for deleting the given entity by its id.
  1018. func (c *MessageClient) DeleteOneID(id int) *MessageDeleteOne {
  1019. builder := c.Delete().Where(message.ID(id))
  1020. builder.mutation.id = &id
  1021. builder.mutation.op = OpDeleteOne
  1022. return &MessageDeleteOne{builder}
  1023. }
  1024. // Query returns a query builder for Message.
  1025. func (c *MessageClient) Query() *MessageQuery {
  1026. return &MessageQuery{
  1027. config: c.config,
  1028. ctx: &QueryContext{Type: TypeMessage},
  1029. inters: c.Interceptors(),
  1030. }
  1031. }
  1032. // Get returns a Message entity by its id.
  1033. func (c *MessageClient) Get(ctx context.Context, id int) (*Message, error) {
  1034. return c.Query().Where(message.ID(id)).Only(ctx)
  1035. }
  1036. // GetX is like Get, but panics if an error occurs.
  1037. func (c *MessageClient) GetX(ctx context.Context, id int) *Message {
  1038. obj, err := c.Get(ctx, id)
  1039. if err != nil {
  1040. panic(err)
  1041. }
  1042. return obj
  1043. }
  1044. // Hooks returns the client hooks.
  1045. func (c *MessageClient) Hooks() []Hook {
  1046. return c.hooks.Message
  1047. }
  1048. // Interceptors returns the client interceptors.
  1049. func (c *MessageClient) Interceptors() []Interceptor {
  1050. return c.inters.Message
  1051. }
  1052. func (c *MessageClient) mutate(ctx context.Context, m *MessageMutation) (Value, error) {
  1053. switch m.Op() {
  1054. case OpCreate:
  1055. return (&MessageCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1056. case OpUpdate:
  1057. return (&MessageUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1058. case OpUpdateOne:
  1059. return (&MessageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1060. case OpDelete, OpDeleteOne:
  1061. return (&MessageDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1062. default:
  1063. return nil, fmt.Errorf("ent: unknown Message mutation op: %q", m.Op())
  1064. }
  1065. }
  1066. // MessageRecordsClient is a client for the MessageRecords schema.
  1067. type MessageRecordsClient struct {
  1068. config
  1069. }
  1070. // NewMessageRecordsClient returns a client for the MessageRecords from the given config.
  1071. func NewMessageRecordsClient(c config) *MessageRecordsClient {
  1072. return &MessageRecordsClient{config: c}
  1073. }
  1074. // Use adds a list of mutation hooks to the hooks stack.
  1075. // A call to `Use(f, g, h)` equals to `messagerecords.Hooks(f(g(h())))`.
  1076. func (c *MessageRecordsClient) Use(hooks ...Hook) {
  1077. c.hooks.MessageRecords = append(c.hooks.MessageRecords, hooks...)
  1078. }
  1079. // Intercept adds a list of query interceptors to the interceptors stack.
  1080. // A call to `Intercept(f, g, h)` equals to `messagerecords.Intercept(f(g(h())))`.
  1081. func (c *MessageRecordsClient) Intercept(interceptors ...Interceptor) {
  1082. c.inters.MessageRecords = append(c.inters.MessageRecords, interceptors...)
  1083. }
  1084. // Create returns a builder for creating a MessageRecords entity.
  1085. func (c *MessageRecordsClient) Create() *MessageRecordsCreate {
  1086. mutation := newMessageRecordsMutation(c.config, OpCreate)
  1087. return &MessageRecordsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1088. }
  1089. // CreateBulk returns a builder for creating a bulk of MessageRecords entities.
  1090. func (c *MessageRecordsClient) CreateBulk(builders ...*MessageRecordsCreate) *MessageRecordsCreateBulk {
  1091. return &MessageRecordsCreateBulk{config: c.config, builders: builders}
  1092. }
  1093. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1094. // a builder and applies setFunc on it.
  1095. func (c *MessageRecordsClient) MapCreateBulk(slice any, setFunc func(*MessageRecordsCreate, int)) *MessageRecordsCreateBulk {
  1096. rv := reflect.ValueOf(slice)
  1097. if rv.Kind() != reflect.Slice {
  1098. return &MessageRecordsCreateBulk{err: fmt.Errorf("calling to MessageRecordsClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1099. }
  1100. builders := make([]*MessageRecordsCreate, rv.Len())
  1101. for i := 0; i < rv.Len(); i++ {
  1102. builders[i] = c.Create()
  1103. setFunc(builders[i], i)
  1104. }
  1105. return &MessageRecordsCreateBulk{config: c.config, builders: builders}
  1106. }
  1107. // Update returns an update builder for MessageRecords.
  1108. func (c *MessageRecordsClient) Update() *MessageRecordsUpdate {
  1109. mutation := newMessageRecordsMutation(c.config, OpUpdate)
  1110. return &MessageRecordsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1111. }
  1112. // UpdateOne returns an update builder for the given entity.
  1113. func (c *MessageRecordsClient) UpdateOne(mr *MessageRecords) *MessageRecordsUpdateOne {
  1114. mutation := newMessageRecordsMutation(c.config, OpUpdateOne, withMessageRecords(mr))
  1115. return &MessageRecordsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1116. }
  1117. // UpdateOneID returns an update builder for the given id.
  1118. func (c *MessageRecordsClient) UpdateOneID(id uint64) *MessageRecordsUpdateOne {
  1119. mutation := newMessageRecordsMutation(c.config, OpUpdateOne, withMessageRecordsID(id))
  1120. return &MessageRecordsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1121. }
  1122. // Delete returns a delete builder for MessageRecords.
  1123. func (c *MessageRecordsClient) Delete() *MessageRecordsDelete {
  1124. mutation := newMessageRecordsMutation(c.config, OpDelete)
  1125. return &MessageRecordsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1126. }
  1127. // DeleteOne returns a builder for deleting the given entity.
  1128. func (c *MessageRecordsClient) DeleteOne(mr *MessageRecords) *MessageRecordsDeleteOne {
  1129. return c.DeleteOneID(mr.ID)
  1130. }
  1131. // DeleteOneID returns a builder for deleting the given entity by its id.
  1132. func (c *MessageRecordsClient) DeleteOneID(id uint64) *MessageRecordsDeleteOne {
  1133. builder := c.Delete().Where(messagerecords.ID(id))
  1134. builder.mutation.id = &id
  1135. builder.mutation.op = OpDeleteOne
  1136. return &MessageRecordsDeleteOne{builder}
  1137. }
  1138. // Query returns a query builder for MessageRecords.
  1139. func (c *MessageRecordsClient) Query() *MessageRecordsQuery {
  1140. return &MessageRecordsQuery{
  1141. config: c.config,
  1142. ctx: &QueryContext{Type: TypeMessageRecords},
  1143. inters: c.Interceptors(),
  1144. }
  1145. }
  1146. // Get returns a MessageRecords entity by its id.
  1147. func (c *MessageRecordsClient) Get(ctx context.Context, id uint64) (*MessageRecords, error) {
  1148. return c.Query().Where(messagerecords.ID(id)).Only(ctx)
  1149. }
  1150. // GetX is like Get, but panics if an error occurs.
  1151. func (c *MessageRecordsClient) GetX(ctx context.Context, id uint64) *MessageRecords {
  1152. obj, err := c.Get(ctx, id)
  1153. if err != nil {
  1154. panic(err)
  1155. }
  1156. return obj
  1157. }
  1158. // QuerySopStage queries the sop_stage edge of a MessageRecords.
  1159. func (c *MessageRecordsClient) QuerySopStage(mr *MessageRecords) *SopStageQuery {
  1160. query := (&SopStageClient{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(sopstage.Table, sopstage.FieldID),
  1166. sqlgraph.Edge(sqlgraph.M2O, true, messagerecords.SopStageTable, messagerecords.SopStageColumn),
  1167. )
  1168. fromV = sqlgraph.Neighbors(mr.driver.Dialect(), step)
  1169. return fromV, nil
  1170. }
  1171. return query
  1172. }
  1173. // QuerySopNode queries the sop_node edge of a MessageRecords.
  1174. func (c *MessageRecordsClient) QuerySopNode(mr *MessageRecords) *SopNodeQuery {
  1175. query := (&SopNodeClient{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(sopnode.Table, sopnode.FieldID),
  1181. sqlgraph.Edge(sqlgraph.M2O, true, messagerecords.SopNodeTable, messagerecords.SopNodeColumn),
  1182. )
  1183. fromV = sqlgraph.Neighbors(mr.driver.Dialect(), step)
  1184. return fromV, nil
  1185. }
  1186. return query
  1187. }
  1188. // QueryMessageContact queries the message_contact edge of a MessageRecords.
  1189. func (c *MessageRecordsClient) QueryMessageContact(mr *MessageRecords) *ContactQuery {
  1190. query := (&ContactClient{config: c.config}).Query()
  1191. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1192. id := mr.ID
  1193. step := sqlgraph.NewStep(
  1194. sqlgraph.From(messagerecords.Table, messagerecords.FieldID, id),
  1195. sqlgraph.To(contact.Table, contact.FieldID),
  1196. sqlgraph.Edge(sqlgraph.M2O, true, messagerecords.MessageContactTable, messagerecords.MessageContactColumn),
  1197. )
  1198. fromV = sqlgraph.Neighbors(mr.driver.Dialect(), step)
  1199. return fromV, nil
  1200. }
  1201. return query
  1202. }
  1203. // Hooks returns the client hooks.
  1204. func (c *MessageRecordsClient) Hooks() []Hook {
  1205. hooks := c.hooks.MessageRecords
  1206. return append(hooks[:len(hooks):len(hooks)], messagerecords.Hooks[:]...)
  1207. }
  1208. // Interceptors returns the client interceptors.
  1209. func (c *MessageRecordsClient) Interceptors() []Interceptor {
  1210. inters := c.inters.MessageRecords
  1211. return append(inters[:len(inters):len(inters)], messagerecords.Interceptors[:]...)
  1212. }
  1213. func (c *MessageRecordsClient) mutate(ctx context.Context, m *MessageRecordsMutation) (Value, error) {
  1214. switch m.Op() {
  1215. case OpCreate:
  1216. return (&MessageRecordsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1217. case OpUpdate:
  1218. return (&MessageRecordsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1219. case OpUpdateOne:
  1220. return (&MessageRecordsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1221. case OpDelete, OpDeleteOne:
  1222. return (&MessageRecordsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1223. default:
  1224. return nil, fmt.Errorf("ent: unknown MessageRecords mutation op: %q", m.Op())
  1225. }
  1226. }
  1227. // MsgClient is a client for the Msg schema.
  1228. type MsgClient struct {
  1229. config
  1230. }
  1231. // NewMsgClient returns a client for the Msg from the given config.
  1232. func NewMsgClient(c config) *MsgClient {
  1233. return &MsgClient{config: c}
  1234. }
  1235. // Use adds a list of mutation hooks to the hooks stack.
  1236. // A call to `Use(f, g, h)` equals to `msg.Hooks(f(g(h())))`.
  1237. func (c *MsgClient) Use(hooks ...Hook) {
  1238. c.hooks.Msg = append(c.hooks.Msg, hooks...)
  1239. }
  1240. // Intercept adds a list of query interceptors to the interceptors stack.
  1241. // A call to `Intercept(f, g, h)` equals to `msg.Intercept(f(g(h())))`.
  1242. func (c *MsgClient) Intercept(interceptors ...Interceptor) {
  1243. c.inters.Msg = append(c.inters.Msg, interceptors...)
  1244. }
  1245. // Create returns a builder for creating a Msg entity.
  1246. func (c *MsgClient) Create() *MsgCreate {
  1247. mutation := newMsgMutation(c.config, OpCreate)
  1248. return &MsgCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1249. }
  1250. // CreateBulk returns a builder for creating a bulk of Msg entities.
  1251. func (c *MsgClient) CreateBulk(builders ...*MsgCreate) *MsgCreateBulk {
  1252. return &MsgCreateBulk{config: c.config, builders: builders}
  1253. }
  1254. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1255. // a builder and applies setFunc on it.
  1256. func (c *MsgClient) MapCreateBulk(slice any, setFunc func(*MsgCreate, int)) *MsgCreateBulk {
  1257. rv := reflect.ValueOf(slice)
  1258. if rv.Kind() != reflect.Slice {
  1259. return &MsgCreateBulk{err: fmt.Errorf("calling to MsgClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1260. }
  1261. builders := make([]*MsgCreate, rv.Len())
  1262. for i := 0; i < rv.Len(); i++ {
  1263. builders[i] = c.Create()
  1264. setFunc(builders[i], i)
  1265. }
  1266. return &MsgCreateBulk{config: c.config, builders: builders}
  1267. }
  1268. // Update returns an update builder for Msg.
  1269. func (c *MsgClient) Update() *MsgUpdate {
  1270. mutation := newMsgMutation(c.config, OpUpdate)
  1271. return &MsgUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1272. }
  1273. // UpdateOne returns an update builder for the given entity.
  1274. func (c *MsgClient) UpdateOne(m *Msg) *MsgUpdateOne {
  1275. mutation := newMsgMutation(c.config, OpUpdateOne, withMsg(m))
  1276. return &MsgUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1277. }
  1278. // UpdateOneID returns an update builder for the given id.
  1279. func (c *MsgClient) UpdateOneID(id uint64) *MsgUpdateOne {
  1280. mutation := newMsgMutation(c.config, OpUpdateOne, withMsgID(id))
  1281. return &MsgUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1282. }
  1283. // Delete returns a delete builder for Msg.
  1284. func (c *MsgClient) Delete() *MsgDelete {
  1285. mutation := newMsgMutation(c.config, OpDelete)
  1286. return &MsgDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1287. }
  1288. // DeleteOne returns a builder for deleting the given entity.
  1289. func (c *MsgClient) DeleteOne(m *Msg) *MsgDeleteOne {
  1290. return c.DeleteOneID(m.ID)
  1291. }
  1292. // DeleteOneID returns a builder for deleting the given entity by its id.
  1293. func (c *MsgClient) DeleteOneID(id uint64) *MsgDeleteOne {
  1294. builder := c.Delete().Where(msg.ID(id))
  1295. builder.mutation.id = &id
  1296. builder.mutation.op = OpDeleteOne
  1297. return &MsgDeleteOne{builder}
  1298. }
  1299. // Query returns a query builder for Msg.
  1300. func (c *MsgClient) Query() *MsgQuery {
  1301. return &MsgQuery{
  1302. config: c.config,
  1303. ctx: &QueryContext{Type: TypeMsg},
  1304. inters: c.Interceptors(),
  1305. }
  1306. }
  1307. // Get returns a Msg entity by its id.
  1308. func (c *MsgClient) Get(ctx context.Context, id uint64) (*Msg, error) {
  1309. return c.Query().Where(msg.ID(id)).Only(ctx)
  1310. }
  1311. // GetX is like Get, but panics if an error occurs.
  1312. func (c *MsgClient) GetX(ctx context.Context, id uint64) *Msg {
  1313. obj, err := c.Get(ctx, id)
  1314. if err != nil {
  1315. panic(err)
  1316. }
  1317. return obj
  1318. }
  1319. // Hooks returns the client hooks.
  1320. func (c *MsgClient) Hooks() []Hook {
  1321. hooks := c.hooks.Msg
  1322. return append(hooks[:len(hooks):len(hooks)], msg.Hooks[:]...)
  1323. }
  1324. // Interceptors returns the client interceptors.
  1325. func (c *MsgClient) Interceptors() []Interceptor {
  1326. inters := c.inters.Msg
  1327. return append(inters[:len(inters):len(inters)], msg.Interceptors[:]...)
  1328. }
  1329. func (c *MsgClient) mutate(ctx context.Context, m *MsgMutation) (Value, error) {
  1330. switch m.Op() {
  1331. case OpCreate:
  1332. return (&MsgCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1333. case OpUpdate:
  1334. return (&MsgUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1335. case OpUpdateOne:
  1336. return (&MsgUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1337. case OpDelete, OpDeleteOne:
  1338. return (&MsgDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1339. default:
  1340. return nil, fmt.Errorf("ent: unknown Msg mutation op: %q", m.Op())
  1341. }
  1342. }
  1343. // ServerClient is a client for the Server schema.
  1344. type ServerClient struct {
  1345. config
  1346. }
  1347. // NewServerClient returns a client for the Server from the given config.
  1348. func NewServerClient(c config) *ServerClient {
  1349. return &ServerClient{config: c}
  1350. }
  1351. // Use adds a list of mutation hooks to the hooks stack.
  1352. // A call to `Use(f, g, h)` equals to `server.Hooks(f(g(h())))`.
  1353. func (c *ServerClient) Use(hooks ...Hook) {
  1354. c.hooks.Server = append(c.hooks.Server, hooks...)
  1355. }
  1356. // Intercept adds a list of query interceptors to the interceptors stack.
  1357. // A call to `Intercept(f, g, h)` equals to `server.Intercept(f(g(h())))`.
  1358. func (c *ServerClient) Intercept(interceptors ...Interceptor) {
  1359. c.inters.Server = append(c.inters.Server, interceptors...)
  1360. }
  1361. // Create returns a builder for creating a Server entity.
  1362. func (c *ServerClient) Create() *ServerCreate {
  1363. mutation := newServerMutation(c.config, OpCreate)
  1364. return &ServerCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1365. }
  1366. // CreateBulk returns a builder for creating a bulk of Server entities.
  1367. func (c *ServerClient) CreateBulk(builders ...*ServerCreate) *ServerCreateBulk {
  1368. return &ServerCreateBulk{config: c.config, builders: builders}
  1369. }
  1370. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1371. // a builder and applies setFunc on it.
  1372. func (c *ServerClient) MapCreateBulk(slice any, setFunc func(*ServerCreate, int)) *ServerCreateBulk {
  1373. rv := reflect.ValueOf(slice)
  1374. if rv.Kind() != reflect.Slice {
  1375. return &ServerCreateBulk{err: fmt.Errorf("calling to ServerClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1376. }
  1377. builders := make([]*ServerCreate, rv.Len())
  1378. for i := 0; i < rv.Len(); i++ {
  1379. builders[i] = c.Create()
  1380. setFunc(builders[i], i)
  1381. }
  1382. return &ServerCreateBulk{config: c.config, builders: builders}
  1383. }
  1384. // Update returns an update builder for Server.
  1385. func (c *ServerClient) Update() *ServerUpdate {
  1386. mutation := newServerMutation(c.config, OpUpdate)
  1387. return &ServerUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1388. }
  1389. // UpdateOne returns an update builder for the given entity.
  1390. func (c *ServerClient) UpdateOne(s *Server) *ServerUpdateOne {
  1391. mutation := newServerMutation(c.config, OpUpdateOne, withServer(s))
  1392. return &ServerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1393. }
  1394. // UpdateOneID returns an update builder for the given id.
  1395. func (c *ServerClient) UpdateOneID(id uint64) *ServerUpdateOne {
  1396. mutation := newServerMutation(c.config, OpUpdateOne, withServerID(id))
  1397. return &ServerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1398. }
  1399. // Delete returns a delete builder for Server.
  1400. func (c *ServerClient) Delete() *ServerDelete {
  1401. mutation := newServerMutation(c.config, OpDelete)
  1402. return &ServerDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1403. }
  1404. // DeleteOne returns a builder for deleting the given entity.
  1405. func (c *ServerClient) DeleteOne(s *Server) *ServerDeleteOne {
  1406. return c.DeleteOneID(s.ID)
  1407. }
  1408. // DeleteOneID returns a builder for deleting the given entity by its id.
  1409. func (c *ServerClient) DeleteOneID(id uint64) *ServerDeleteOne {
  1410. builder := c.Delete().Where(server.ID(id))
  1411. builder.mutation.id = &id
  1412. builder.mutation.op = OpDeleteOne
  1413. return &ServerDeleteOne{builder}
  1414. }
  1415. // Query returns a query builder for Server.
  1416. func (c *ServerClient) Query() *ServerQuery {
  1417. return &ServerQuery{
  1418. config: c.config,
  1419. ctx: &QueryContext{Type: TypeServer},
  1420. inters: c.Interceptors(),
  1421. }
  1422. }
  1423. // Get returns a Server entity by its id.
  1424. func (c *ServerClient) Get(ctx context.Context, id uint64) (*Server, error) {
  1425. return c.Query().Where(server.ID(id)).Only(ctx)
  1426. }
  1427. // GetX is like Get, but panics if an error occurs.
  1428. func (c *ServerClient) GetX(ctx context.Context, id uint64) *Server {
  1429. obj, err := c.Get(ctx, id)
  1430. if err != nil {
  1431. panic(err)
  1432. }
  1433. return obj
  1434. }
  1435. // QueryWxs queries the wxs edge of a Server.
  1436. func (c *ServerClient) QueryWxs(s *Server) *WxQuery {
  1437. query := (&WxClient{config: c.config}).Query()
  1438. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1439. id := s.ID
  1440. step := sqlgraph.NewStep(
  1441. sqlgraph.From(server.Table, server.FieldID, id),
  1442. sqlgraph.To(wx.Table, wx.FieldID),
  1443. sqlgraph.Edge(sqlgraph.O2M, false, server.WxsTable, server.WxsColumn),
  1444. )
  1445. fromV = sqlgraph.Neighbors(s.driver.Dialect(), step)
  1446. return fromV, nil
  1447. }
  1448. return query
  1449. }
  1450. // Hooks returns the client hooks.
  1451. func (c *ServerClient) Hooks() []Hook {
  1452. hooks := c.hooks.Server
  1453. return append(hooks[:len(hooks):len(hooks)], server.Hooks[:]...)
  1454. }
  1455. // Interceptors returns the client interceptors.
  1456. func (c *ServerClient) Interceptors() []Interceptor {
  1457. inters := c.inters.Server
  1458. return append(inters[:len(inters):len(inters)], server.Interceptors[:]...)
  1459. }
  1460. func (c *ServerClient) mutate(ctx context.Context, m *ServerMutation) (Value, error) {
  1461. switch m.Op() {
  1462. case OpCreate:
  1463. return (&ServerCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1464. case OpUpdate:
  1465. return (&ServerUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1466. case OpUpdateOne:
  1467. return (&ServerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1468. case OpDelete, OpDeleteOne:
  1469. return (&ServerDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1470. default:
  1471. return nil, fmt.Errorf("ent: unknown Server mutation op: %q", m.Op())
  1472. }
  1473. }
  1474. // SopNodeClient is a client for the SopNode schema.
  1475. type SopNodeClient struct {
  1476. config
  1477. }
  1478. // NewSopNodeClient returns a client for the SopNode from the given config.
  1479. func NewSopNodeClient(c config) *SopNodeClient {
  1480. return &SopNodeClient{config: c}
  1481. }
  1482. // Use adds a list of mutation hooks to the hooks stack.
  1483. // A call to `Use(f, g, h)` equals to `sopnode.Hooks(f(g(h())))`.
  1484. func (c *SopNodeClient) Use(hooks ...Hook) {
  1485. c.hooks.SopNode = append(c.hooks.SopNode, hooks...)
  1486. }
  1487. // Intercept adds a list of query interceptors to the interceptors stack.
  1488. // A call to `Intercept(f, g, h)` equals to `sopnode.Intercept(f(g(h())))`.
  1489. func (c *SopNodeClient) Intercept(interceptors ...Interceptor) {
  1490. c.inters.SopNode = append(c.inters.SopNode, interceptors...)
  1491. }
  1492. // Create returns a builder for creating a SopNode entity.
  1493. func (c *SopNodeClient) Create() *SopNodeCreate {
  1494. mutation := newSopNodeMutation(c.config, OpCreate)
  1495. return &SopNodeCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1496. }
  1497. // CreateBulk returns a builder for creating a bulk of SopNode entities.
  1498. func (c *SopNodeClient) CreateBulk(builders ...*SopNodeCreate) *SopNodeCreateBulk {
  1499. return &SopNodeCreateBulk{config: c.config, builders: builders}
  1500. }
  1501. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1502. // a builder and applies setFunc on it.
  1503. func (c *SopNodeClient) MapCreateBulk(slice any, setFunc func(*SopNodeCreate, int)) *SopNodeCreateBulk {
  1504. rv := reflect.ValueOf(slice)
  1505. if rv.Kind() != reflect.Slice {
  1506. return &SopNodeCreateBulk{err: fmt.Errorf("calling to SopNodeClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1507. }
  1508. builders := make([]*SopNodeCreate, rv.Len())
  1509. for i := 0; i < rv.Len(); i++ {
  1510. builders[i] = c.Create()
  1511. setFunc(builders[i], i)
  1512. }
  1513. return &SopNodeCreateBulk{config: c.config, builders: builders}
  1514. }
  1515. // Update returns an update builder for SopNode.
  1516. func (c *SopNodeClient) Update() *SopNodeUpdate {
  1517. mutation := newSopNodeMutation(c.config, OpUpdate)
  1518. return &SopNodeUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1519. }
  1520. // UpdateOne returns an update builder for the given entity.
  1521. func (c *SopNodeClient) UpdateOne(sn *SopNode) *SopNodeUpdateOne {
  1522. mutation := newSopNodeMutation(c.config, OpUpdateOne, withSopNode(sn))
  1523. return &SopNodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1524. }
  1525. // UpdateOneID returns an update builder for the given id.
  1526. func (c *SopNodeClient) UpdateOneID(id uint64) *SopNodeUpdateOne {
  1527. mutation := newSopNodeMutation(c.config, OpUpdateOne, withSopNodeID(id))
  1528. return &SopNodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1529. }
  1530. // Delete returns a delete builder for SopNode.
  1531. func (c *SopNodeClient) Delete() *SopNodeDelete {
  1532. mutation := newSopNodeMutation(c.config, OpDelete)
  1533. return &SopNodeDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1534. }
  1535. // DeleteOne returns a builder for deleting the given entity.
  1536. func (c *SopNodeClient) DeleteOne(sn *SopNode) *SopNodeDeleteOne {
  1537. return c.DeleteOneID(sn.ID)
  1538. }
  1539. // DeleteOneID returns a builder for deleting the given entity by its id.
  1540. func (c *SopNodeClient) DeleteOneID(id uint64) *SopNodeDeleteOne {
  1541. builder := c.Delete().Where(sopnode.ID(id))
  1542. builder.mutation.id = &id
  1543. builder.mutation.op = OpDeleteOne
  1544. return &SopNodeDeleteOne{builder}
  1545. }
  1546. // Query returns a query builder for SopNode.
  1547. func (c *SopNodeClient) Query() *SopNodeQuery {
  1548. return &SopNodeQuery{
  1549. config: c.config,
  1550. ctx: &QueryContext{Type: TypeSopNode},
  1551. inters: c.Interceptors(),
  1552. }
  1553. }
  1554. // Get returns a SopNode entity by its id.
  1555. func (c *SopNodeClient) Get(ctx context.Context, id uint64) (*SopNode, error) {
  1556. return c.Query().Where(sopnode.ID(id)).Only(ctx)
  1557. }
  1558. // GetX is like Get, but panics if an error occurs.
  1559. func (c *SopNodeClient) GetX(ctx context.Context, id uint64) *SopNode {
  1560. obj, err := c.Get(ctx, id)
  1561. if err != nil {
  1562. panic(err)
  1563. }
  1564. return obj
  1565. }
  1566. // QuerySopStage queries the sop_stage edge of a SopNode.
  1567. func (c *SopNodeClient) QuerySopStage(sn *SopNode) *SopStageQuery {
  1568. query := (&SopStageClient{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(sopstage.Table, sopstage.FieldID),
  1574. sqlgraph.Edge(sqlgraph.M2O, true, sopnode.SopStageTable, sopnode.SopStageColumn),
  1575. )
  1576. fromV = sqlgraph.Neighbors(sn.driver.Dialect(), step)
  1577. return fromV, nil
  1578. }
  1579. return query
  1580. }
  1581. // QueryNodeMessages queries the node_messages edge of a SopNode.
  1582. func (c *SopNodeClient) QueryNodeMessages(sn *SopNode) *MessageRecordsQuery {
  1583. query := (&MessageRecordsClient{config: c.config}).Query()
  1584. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1585. id := sn.ID
  1586. step := sqlgraph.NewStep(
  1587. sqlgraph.From(sopnode.Table, sopnode.FieldID, id),
  1588. sqlgraph.To(messagerecords.Table, messagerecords.FieldID),
  1589. sqlgraph.Edge(sqlgraph.O2M, false, sopnode.NodeMessagesTable, sopnode.NodeMessagesColumn),
  1590. )
  1591. fromV = sqlgraph.Neighbors(sn.driver.Dialect(), step)
  1592. return fromV, nil
  1593. }
  1594. return query
  1595. }
  1596. // Hooks returns the client hooks.
  1597. func (c *SopNodeClient) Hooks() []Hook {
  1598. hooks := c.hooks.SopNode
  1599. return append(hooks[:len(hooks):len(hooks)], sopnode.Hooks[:]...)
  1600. }
  1601. // Interceptors returns the client interceptors.
  1602. func (c *SopNodeClient) Interceptors() []Interceptor {
  1603. inters := c.inters.SopNode
  1604. return append(inters[:len(inters):len(inters)], sopnode.Interceptors[:]...)
  1605. }
  1606. func (c *SopNodeClient) mutate(ctx context.Context, m *SopNodeMutation) (Value, error) {
  1607. switch m.Op() {
  1608. case OpCreate:
  1609. return (&SopNodeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1610. case OpUpdate:
  1611. return (&SopNodeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1612. case OpUpdateOne:
  1613. return (&SopNodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1614. case OpDelete, OpDeleteOne:
  1615. return (&SopNodeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1616. default:
  1617. return nil, fmt.Errorf("ent: unknown SopNode mutation op: %q", m.Op())
  1618. }
  1619. }
  1620. // SopStageClient is a client for the SopStage schema.
  1621. type SopStageClient struct {
  1622. config
  1623. }
  1624. // NewSopStageClient returns a client for the SopStage from the given config.
  1625. func NewSopStageClient(c config) *SopStageClient {
  1626. return &SopStageClient{config: c}
  1627. }
  1628. // Use adds a list of mutation hooks to the hooks stack.
  1629. // A call to `Use(f, g, h)` equals to `sopstage.Hooks(f(g(h())))`.
  1630. func (c *SopStageClient) Use(hooks ...Hook) {
  1631. c.hooks.SopStage = append(c.hooks.SopStage, hooks...)
  1632. }
  1633. // Intercept adds a list of query interceptors to the interceptors stack.
  1634. // A call to `Intercept(f, g, h)` equals to `sopstage.Intercept(f(g(h())))`.
  1635. func (c *SopStageClient) Intercept(interceptors ...Interceptor) {
  1636. c.inters.SopStage = append(c.inters.SopStage, interceptors...)
  1637. }
  1638. // Create returns a builder for creating a SopStage entity.
  1639. func (c *SopStageClient) Create() *SopStageCreate {
  1640. mutation := newSopStageMutation(c.config, OpCreate)
  1641. return &SopStageCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1642. }
  1643. // CreateBulk returns a builder for creating a bulk of SopStage entities.
  1644. func (c *SopStageClient) CreateBulk(builders ...*SopStageCreate) *SopStageCreateBulk {
  1645. return &SopStageCreateBulk{config: c.config, builders: builders}
  1646. }
  1647. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1648. // a builder and applies setFunc on it.
  1649. func (c *SopStageClient) MapCreateBulk(slice any, setFunc func(*SopStageCreate, int)) *SopStageCreateBulk {
  1650. rv := reflect.ValueOf(slice)
  1651. if rv.Kind() != reflect.Slice {
  1652. return &SopStageCreateBulk{err: fmt.Errorf("calling to SopStageClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1653. }
  1654. builders := make([]*SopStageCreate, rv.Len())
  1655. for i := 0; i < rv.Len(); i++ {
  1656. builders[i] = c.Create()
  1657. setFunc(builders[i], i)
  1658. }
  1659. return &SopStageCreateBulk{config: c.config, builders: builders}
  1660. }
  1661. // Update returns an update builder for SopStage.
  1662. func (c *SopStageClient) Update() *SopStageUpdate {
  1663. mutation := newSopStageMutation(c.config, OpUpdate)
  1664. return &SopStageUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1665. }
  1666. // UpdateOne returns an update builder for the given entity.
  1667. func (c *SopStageClient) UpdateOne(ss *SopStage) *SopStageUpdateOne {
  1668. mutation := newSopStageMutation(c.config, OpUpdateOne, withSopStage(ss))
  1669. return &SopStageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1670. }
  1671. // UpdateOneID returns an update builder for the given id.
  1672. func (c *SopStageClient) UpdateOneID(id uint64) *SopStageUpdateOne {
  1673. mutation := newSopStageMutation(c.config, OpUpdateOne, withSopStageID(id))
  1674. return &SopStageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1675. }
  1676. // Delete returns a delete builder for SopStage.
  1677. func (c *SopStageClient) Delete() *SopStageDelete {
  1678. mutation := newSopStageMutation(c.config, OpDelete)
  1679. return &SopStageDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1680. }
  1681. // DeleteOne returns a builder for deleting the given entity.
  1682. func (c *SopStageClient) DeleteOne(ss *SopStage) *SopStageDeleteOne {
  1683. return c.DeleteOneID(ss.ID)
  1684. }
  1685. // DeleteOneID returns a builder for deleting the given entity by its id.
  1686. func (c *SopStageClient) DeleteOneID(id uint64) *SopStageDeleteOne {
  1687. builder := c.Delete().Where(sopstage.ID(id))
  1688. builder.mutation.id = &id
  1689. builder.mutation.op = OpDeleteOne
  1690. return &SopStageDeleteOne{builder}
  1691. }
  1692. // Query returns a query builder for SopStage.
  1693. func (c *SopStageClient) Query() *SopStageQuery {
  1694. return &SopStageQuery{
  1695. config: c.config,
  1696. ctx: &QueryContext{Type: TypeSopStage},
  1697. inters: c.Interceptors(),
  1698. }
  1699. }
  1700. // Get returns a SopStage entity by its id.
  1701. func (c *SopStageClient) Get(ctx context.Context, id uint64) (*SopStage, error) {
  1702. return c.Query().Where(sopstage.ID(id)).Only(ctx)
  1703. }
  1704. // GetX is like Get, but panics if an error occurs.
  1705. func (c *SopStageClient) GetX(ctx context.Context, id uint64) *SopStage {
  1706. obj, err := c.Get(ctx, id)
  1707. if err != nil {
  1708. panic(err)
  1709. }
  1710. return obj
  1711. }
  1712. // QuerySopTask queries the sop_task edge of a SopStage.
  1713. func (c *SopStageClient) QuerySopTask(ss *SopStage) *SopTaskQuery {
  1714. query := (&SopTaskClient{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(soptask.Table, soptask.FieldID),
  1720. sqlgraph.Edge(sqlgraph.M2O, true, sopstage.SopTaskTable, sopstage.SopTaskColumn),
  1721. )
  1722. fromV = sqlgraph.Neighbors(ss.driver.Dialect(), step)
  1723. return fromV, nil
  1724. }
  1725. return query
  1726. }
  1727. // QueryStageNodes queries the stage_nodes edge of a SopStage.
  1728. func (c *SopStageClient) QueryStageNodes(ss *SopStage) *SopNodeQuery {
  1729. query := (&SopNodeClient{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(sopnode.Table, sopnode.FieldID),
  1735. sqlgraph.Edge(sqlgraph.O2M, false, sopstage.StageNodesTable, sopstage.StageNodesColumn),
  1736. )
  1737. fromV = sqlgraph.Neighbors(ss.driver.Dialect(), step)
  1738. return fromV, nil
  1739. }
  1740. return query
  1741. }
  1742. // QueryStageMessages queries the stage_messages edge of a SopStage.
  1743. func (c *SopStageClient) QueryStageMessages(ss *SopStage) *MessageRecordsQuery {
  1744. query := (&MessageRecordsClient{config: c.config}).Query()
  1745. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1746. id := ss.ID
  1747. step := sqlgraph.NewStep(
  1748. sqlgraph.From(sopstage.Table, sopstage.FieldID, id),
  1749. sqlgraph.To(messagerecords.Table, messagerecords.FieldID),
  1750. sqlgraph.Edge(sqlgraph.O2M, false, sopstage.StageMessagesTable, sopstage.StageMessagesColumn),
  1751. )
  1752. fromV = sqlgraph.Neighbors(ss.driver.Dialect(), step)
  1753. return fromV, nil
  1754. }
  1755. return query
  1756. }
  1757. // Hooks returns the client hooks.
  1758. func (c *SopStageClient) Hooks() []Hook {
  1759. hooks := c.hooks.SopStage
  1760. return append(hooks[:len(hooks):len(hooks)], sopstage.Hooks[:]...)
  1761. }
  1762. // Interceptors returns the client interceptors.
  1763. func (c *SopStageClient) Interceptors() []Interceptor {
  1764. inters := c.inters.SopStage
  1765. return append(inters[:len(inters):len(inters)], sopstage.Interceptors[:]...)
  1766. }
  1767. func (c *SopStageClient) mutate(ctx context.Context, m *SopStageMutation) (Value, error) {
  1768. switch m.Op() {
  1769. case OpCreate:
  1770. return (&SopStageCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1771. case OpUpdate:
  1772. return (&SopStageUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1773. case OpUpdateOne:
  1774. return (&SopStageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1775. case OpDelete, OpDeleteOne:
  1776. return (&SopStageDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1777. default:
  1778. return nil, fmt.Errorf("ent: unknown SopStage mutation op: %q", m.Op())
  1779. }
  1780. }
  1781. // SopTaskClient is a client for the SopTask schema.
  1782. type SopTaskClient struct {
  1783. config
  1784. }
  1785. // NewSopTaskClient returns a client for the SopTask from the given config.
  1786. func NewSopTaskClient(c config) *SopTaskClient {
  1787. return &SopTaskClient{config: c}
  1788. }
  1789. // Use adds a list of mutation hooks to the hooks stack.
  1790. // A call to `Use(f, g, h)` equals to `soptask.Hooks(f(g(h())))`.
  1791. func (c *SopTaskClient) Use(hooks ...Hook) {
  1792. c.hooks.SopTask = append(c.hooks.SopTask, hooks...)
  1793. }
  1794. // Intercept adds a list of query interceptors to the interceptors stack.
  1795. // A call to `Intercept(f, g, h)` equals to `soptask.Intercept(f(g(h())))`.
  1796. func (c *SopTaskClient) Intercept(interceptors ...Interceptor) {
  1797. c.inters.SopTask = append(c.inters.SopTask, interceptors...)
  1798. }
  1799. // Create returns a builder for creating a SopTask entity.
  1800. func (c *SopTaskClient) Create() *SopTaskCreate {
  1801. mutation := newSopTaskMutation(c.config, OpCreate)
  1802. return &SopTaskCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1803. }
  1804. // CreateBulk returns a builder for creating a bulk of SopTask entities.
  1805. func (c *SopTaskClient) CreateBulk(builders ...*SopTaskCreate) *SopTaskCreateBulk {
  1806. return &SopTaskCreateBulk{config: c.config, builders: builders}
  1807. }
  1808. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1809. // a builder and applies setFunc on it.
  1810. func (c *SopTaskClient) MapCreateBulk(slice any, setFunc func(*SopTaskCreate, int)) *SopTaskCreateBulk {
  1811. rv := reflect.ValueOf(slice)
  1812. if rv.Kind() != reflect.Slice {
  1813. return &SopTaskCreateBulk{err: fmt.Errorf("calling to SopTaskClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1814. }
  1815. builders := make([]*SopTaskCreate, rv.Len())
  1816. for i := 0; i < rv.Len(); i++ {
  1817. builders[i] = c.Create()
  1818. setFunc(builders[i], i)
  1819. }
  1820. return &SopTaskCreateBulk{config: c.config, builders: builders}
  1821. }
  1822. // Update returns an update builder for SopTask.
  1823. func (c *SopTaskClient) Update() *SopTaskUpdate {
  1824. mutation := newSopTaskMutation(c.config, OpUpdate)
  1825. return &SopTaskUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1826. }
  1827. // UpdateOne returns an update builder for the given entity.
  1828. func (c *SopTaskClient) UpdateOne(st *SopTask) *SopTaskUpdateOne {
  1829. mutation := newSopTaskMutation(c.config, OpUpdateOne, withSopTask(st))
  1830. return &SopTaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1831. }
  1832. // UpdateOneID returns an update builder for the given id.
  1833. func (c *SopTaskClient) UpdateOneID(id uint64) *SopTaskUpdateOne {
  1834. mutation := newSopTaskMutation(c.config, OpUpdateOne, withSopTaskID(id))
  1835. return &SopTaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1836. }
  1837. // Delete returns a delete builder for SopTask.
  1838. func (c *SopTaskClient) Delete() *SopTaskDelete {
  1839. mutation := newSopTaskMutation(c.config, OpDelete)
  1840. return &SopTaskDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1841. }
  1842. // DeleteOne returns a builder for deleting the given entity.
  1843. func (c *SopTaskClient) DeleteOne(st *SopTask) *SopTaskDeleteOne {
  1844. return c.DeleteOneID(st.ID)
  1845. }
  1846. // DeleteOneID returns a builder for deleting the given entity by its id.
  1847. func (c *SopTaskClient) DeleteOneID(id uint64) *SopTaskDeleteOne {
  1848. builder := c.Delete().Where(soptask.ID(id))
  1849. builder.mutation.id = &id
  1850. builder.mutation.op = OpDeleteOne
  1851. return &SopTaskDeleteOne{builder}
  1852. }
  1853. // Query returns a query builder for SopTask.
  1854. func (c *SopTaskClient) Query() *SopTaskQuery {
  1855. return &SopTaskQuery{
  1856. config: c.config,
  1857. ctx: &QueryContext{Type: TypeSopTask},
  1858. inters: c.Interceptors(),
  1859. }
  1860. }
  1861. // Get returns a SopTask entity by its id.
  1862. func (c *SopTaskClient) Get(ctx context.Context, id uint64) (*SopTask, error) {
  1863. return c.Query().Where(soptask.ID(id)).Only(ctx)
  1864. }
  1865. // GetX is like Get, but panics if an error occurs.
  1866. func (c *SopTaskClient) GetX(ctx context.Context, id uint64) *SopTask {
  1867. obj, err := c.Get(ctx, id)
  1868. if err != nil {
  1869. panic(err)
  1870. }
  1871. return obj
  1872. }
  1873. // QueryTaskStages queries the task_stages edge of a SopTask.
  1874. func (c *SopTaskClient) QueryTaskStages(st *SopTask) *SopStageQuery {
  1875. query := (&SopStageClient{config: c.config}).Query()
  1876. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1877. id := st.ID
  1878. step := sqlgraph.NewStep(
  1879. sqlgraph.From(soptask.Table, soptask.FieldID, id),
  1880. sqlgraph.To(sopstage.Table, sopstage.FieldID),
  1881. sqlgraph.Edge(sqlgraph.O2M, false, soptask.TaskStagesTable, soptask.TaskStagesColumn),
  1882. )
  1883. fromV = sqlgraph.Neighbors(st.driver.Dialect(), step)
  1884. return fromV, nil
  1885. }
  1886. return query
  1887. }
  1888. // Hooks returns the client hooks.
  1889. func (c *SopTaskClient) Hooks() []Hook {
  1890. hooks := c.hooks.SopTask
  1891. return append(hooks[:len(hooks):len(hooks)], soptask.Hooks[:]...)
  1892. }
  1893. // Interceptors returns the client interceptors.
  1894. func (c *SopTaskClient) Interceptors() []Interceptor {
  1895. inters := c.inters.SopTask
  1896. return append(inters[:len(inters):len(inters)], soptask.Interceptors[:]...)
  1897. }
  1898. func (c *SopTaskClient) mutate(ctx context.Context, m *SopTaskMutation) (Value, error) {
  1899. switch m.Op() {
  1900. case OpCreate:
  1901. return (&SopTaskCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1902. case OpUpdate:
  1903. return (&SopTaskUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1904. case OpUpdateOne:
  1905. return (&SopTaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1906. case OpDelete, OpDeleteOne:
  1907. return (&SopTaskDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1908. default:
  1909. return nil, fmt.Errorf("ent: unknown SopTask mutation op: %q", m.Op())
  1910. }
  1911. }
  1912. // WxClient is a client for the Wx schema.
  1913. type WxClient struct {
  1914. config
  1915. }
  1916. // NewWxClient returns a client for the Wx from the given config.
  1917. func NewWxClient(c config) *WxClient {
  1918. return &WxClient{config: c}
  1919. }
  1920. // Use adds a list of mutation hooks to the hooks stack.
  1921. // A call to `Use(f, g, h)` equals to `wx.Hooks(f(g(h())))`.
  1922. func (c *WxClient) Use(hooks ...Hook) {
  1923. c.hooks.Wx = append(c.hooks.Wx, hooks...)
  1924. }
  1925. // Intercept adds a list of query interceptors to the interceptors stack.
  1926. // A call to `Intercept(f, g, h)` equals to `wx.Intercept(f(g(h())))`.
  1927. func (c *WxClient) Intercept(interceptors ...Interceptor) {
  1928. c.inters.Wx = append(c.inters.Wx, interceptors...)
  1929. }
  1930. // Create returns a builder for creating a Wx entity.
  1931. func (c *WxClient) Create() *WxCreate {
  1932. mutation := newWxMutation(c.config, OpCreate)
  1933. return &WxCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1934. }
  1935. // CreateBulk returns a builder for creating a bulk of Wx entities.
  1936. func (c *WxClient) CreateBulk(builders ...*WxCreate) *WxCreateBulk {
  1937. return &WxCreateBulk{config: c.config, builders: builders}
  1938. }
  1939. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1940. // a builder and applies setFunc on it.
  1941. func (c *WxClient) MapCreateBulk(slice any, setFunc func(*WxCreate, int)) *WxCreateBulk {
  1942. rv := reflect.ValueOf(slice)
  1943. if rv.Kind() != reflect.Slice {
  1944. return &WxCreateBulk{err: fmt.Errorf("calling to WxClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1945. }
  1946. builders := make([]*WxCreate, rv.Len())
  1947. for i := 0; i < rv.Len(); i++ {
  1948. builders[i] = c.Create()
  1949. setFunc(builders[i], i)
  1950. }
  1951. return &WxCreateBulk{config: c.config, builders: builders}
  1952. }
  1953. // Update returns an update builder for Wx.
  1954. func (c *WxClient) Update() *WxUpdate {
  1955. mutation := newWxMutation(c.config, OpUpdate)
  1956. return &WxUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1957. }
  1958. // UpdateOne returns an update builder for the given entity.
  1959. func (c *WxClient) UpdateOne(w *Wx) *WxUpdateOne {
  1960. mutation := newWxMutation(c.config, OpUpdateOne, withWx(w))
  1961. return &WxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1962. }
  1963. // UpdateOneID returns an update builder for the given id.
  1964. func (c *WxClient) UpdateOneID(id uint64) *WxUpdateOne {
  1965. mutation := newWxMutation(c.config, OpUpdateOne, withWxID(id))
  1966. return &WxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1967. }
  1968. // Delete returns a delete builder for Wx.
  1969. func (c *WxClient) Delete() *WxDelete {
  1970. mutation := newWxMutation(c.config, OpDelete)
  1971. return &WxDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1972. }
  1973. // DeleteOne returns a builder for deleting the given entity.
  1974. func (c *WxClient) DeleteOne(w *Wx) *WxDeleteOne {
  1975. return c.DeleteOneID(w.ID)
  1976. }
  1977. // DeleteOneID returns a builder for deleting the given entity by its id.
  1978. func (c *WxClient) DeleteOneID(id uint64) *WxDeleteOne {
  1979. builder := c.Delete().Where(wx.ID(id))
  1980. builder.mutation.id = &id
  1981. builder.mutation.op = OpDeleteOne
  1982. return &WxDeleteOne{builder}
  1983. }
  1984. // Query returns a query builder for Wx.
  1985. func (c *WxClient) Query() *WxQuery {
  1986. return &WxQuery{
  1987. config: c.config,
  1988. ctx: &QueryContext{Type: TypeWx},
  1989. inters: c.Interceptors(),
  1990. }
  1991. }
  1992. // Get returns a Wx entity by its id.
  1993. func (c *WxClient) Get(ctx context.Context, id uint64) (*Wx, error) {
  1994. return c.Query().Where(wx.ID(id)).Only(ctx)
  1995. }
  1996. // GetX is like Get, but panics if an error occurs.
  1997. func (c *WxClient) GetX(ctx context.Context, id uint64) *Wx {
  1998. obj, err := c.Get(ctx, id)
  1999. if err != nil {
  2000. panic(err)
  2001. }
  2002. return obj
  2003. }
  2004. // QueryServer queries the server edge of a Wx.
  2005. func (c *WxClient) QueryServer(w *Wx) *ServerQuery {
  2006. query := (&ServerClient{config: c.config}).Query()
  2007. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  2008. id := w.ID
  2009. step := sqlgraph.NewStep(
  2010. sqlgraph.From(wx.Table, wx.FieldID, id),
  2011. sqlgraph.To(server.Table, server.FieldID),
  2012. sqlgraph.Edge(sqlgraph.M2O, true, wx.ServerTable, wx.ServerColumn),
  2013. )
  2014. fromV = sqlgraph.Neighbors(w.driver.Dialect(), step)
  2015. return fromV, nil
  2016. }
  2017. return query
  2018. }
  2019. // QueryAgent queries the agent edge of a Wx.
  2020. func (c *WxClient) QueryAgent(w *Wx) *AgentQuery {
  2021. query := (&AgentClient{config: c.config}).Query()
  2022. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  2023. id := w.ID
  2024. step := sqlgraph.NewStep(
  2025. sqlgraph.From(wx.Table, wx.FieldID, id),
  2026. sqlgraph.To(agent.Table, agent.FieldID),
  2027. sqlgraph.Edge(sqlgraph.M2O, true, wx.AgentTable, wx.AgentColumn),
  2028. )
  2029. fromV = sqlgraph.Neighbors(w.driver.Dialect(), step)
  2030. return fromV, nil
  2031. }
  2032. return query
  2033. }
  2034. // Hooks returns the client hooks.
  2035. func (c *WxClient) Hooks() []Hook {
  2036. hooks := c.hooks.Wx
  2037. return append(hooks[:len(hooks):len(hooks)], wx.Hooks[:]...)
  2038. }
  2039. // Interceptors returns the client interceptors.
  2040. func (c *WxClient) Interceptors() []Interceptor {
  2041. inters := c.inters.Wx
  2042. return append(inters[:len(inters):len(inters)], wx.Interceptors[:]...)
  2043. }
  2044. func (c *WxClient) mutate(ctx context.Context, m *WxMutation) (Value, error) {
  2045. switch m.Op() {
  2046. case OpCreate:
  2047. return (&WxCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2048. case OpUpdate:
  2049. return (&WxUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2050. case OpUpdateOne:
  2051. return (&WxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2052. case OpDelete, OpDeleteOne:
  2053. return (&WxDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  2054. default:
  2055. return nil, fmt.Errorf("ent: unknown Wx mutation op: %q", m.Op())
  2056. }
  2057. }
  2058. // hooks and interceptors per client, for fast access.
  2059. type (
  2060. hooks struct {
  2061. Agent, BatchMsg, Contact, Label, LabelRelationship, Message, MessageRecords,
  2062. Msg, Server, SopNode, SopStage, SopTask, Wx []ent.Hook
  2063. }
  2064. inters struct {
  2065. Agent, BatchMsg, Contact, Label, LabelRelationship, Message, MessageRecords,
  2066. Msg, Server, SopNode, SopStage, SopTask, Wx []ent.Interceptor
  2067. }
  2068. )
  2069. // ExecContext allows calling the underlying ExecContext method of the driver if it is supported by it.
  2070. // See, database/sql#DB.ExecContext for more information.
  2071. func (c *config) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) {
  2072. ex, ok := c.driver.(interface {
  2073. ExecContext(context.Context, string, ...any) (stdsql.Result, error)
  2074. })
  2075. if !ok {
  2076. return nil, fmt.Errorf("Driver.ExecContext is not supported")
  2077. }
  2078. return ex.ExecContext(ctx, query, args...)
  2079. }
  2080. // QueryContext allows calling the underlying QueryContext method of the driver if it is supported by it.
  2081. // See, database/sql#DB.QueryContext for more information.
  2082. func (c *config) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) {
  2083. q, ok := c.driver.(interface {
  2084. QueryContext(context.Context, string, ...any) (*stdsql.Rows, error)
  2085. })
  2086. if !ok {
  2087. return nil, fmt.Errorf("Driver.QueryContext is not supported")
  2088. }
  2089. return q.QueryContext(ctx, query, args...)
  2090. }