client.go 74 KB

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