client.go 78 KB

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