client.go 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209
  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 uint64) *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 uint64) *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 uint64) (*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 uint64) *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. hooks := c.hooks.Msg
  1185. return append(hooks[:len(hooks):len(hooks)], msg.Hooks[:]...)
  1186. }
  1187. // Interceptors returns the client interceptors.
  1188. func (c *MsgClient) Interceptors() []Interceptor {
  1189. inters := c.inters.Msg
  1190. return append(inters[:len(inters):len(inters)], msg.Interceptors[:]...)
  1191. }
  1192. func (c *MsgClient) mutate(ctx context.Context, m *MsgMutation) (Value, error) {
  1193. switch m.Op() {
  1194. case OpCreate:
  1195. return (&MsgCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1196. case OpUpdate:
  1197. return (&MsgUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1198. case OpUpdateOne:
  1199. return (&MsgUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1200. case OpDelete, OpDeleteOne:
  1201. return (&MsgDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1202. default:
  1203. return nil, fmt.Errorf("ent: unknown Msg mutation op: %q", m.Op())
  1204. }
  1205. }
  1206. // ServerClient is a client for the Server schema.
  1207. type ServerClient struct {
  1208. config
  1209. }
  1210. // NewServerClient returns a client for the Server from the given config.
  1211. func NewServerClient(c config) *ServerClient {
  1212. return &ServerClient{config: c}
  1213. }
  1214. // Use adds a list of mutation hooks to the hooks stack.
  1215. // A call to `Use(f, g, h)` equals to `server.Hooks(f(g(h())))`.
  1216. func (c *ServerClient) Use(hooks ...Hook) {
  1217. c.hooks.Server = append(c.hooks.Server, hooks...)
  1218. }
  1219. // Intercept adds a list of query interceptors to the interceptors stack.
  1220. // A call to `Intercept(f, g, h)` equals to `server.Intercept(f(g(h())))`.
  1221. func (c *ServerClient) Intercept(interceptors ...Interceptor) {
  1222. c.inters.Server = append(c.inters.Server, interceptors...)
  1223. }
  1224. // Create returns a builder for creating a Server entity.
  1225. func (c *ServerClient) Create() *ServerCreate {
  1226. mutation := newServerMutation(c.config, OpCreate)
  1227. return &ServerCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1228. }
  1229. // CreateBulk returns a builder for creating a bulk of Server entities.
  1230. func (c *ServerClient) CreateBulk(builders ...*ServerCreate) *ServerCreateBulk {
  1231. return &ServerCreateBulk{config: c.config, builders: builders}
  1232. }
  1233. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1234. // a builder and applies setFunc on it.
  1235. func (c *ServerClient) MapCreateBulk(slice any, setFunc func(*ServerCreate, int)) *ServerCreateBulk {
  1236. rv := reflect.ValueOf(slice)
  1237. if rv.Kind() != reflect.Slice {
  1238. return &ServerCreateBulk{err: fmt.Errorf("calling to ServerClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1239. }
  1240. builders := make([]*ServerCreate, rv.Len())
  1241. for i := 0; i < rv.Len(); i++ {
  1242. builders[i] = c.Create()
  1243. setFunc(builders[i], i)
  1244. }
  1245. return &ServerCreateBulk{config: c.config, builders: builders}
  1246. }
  1247. // Update returns an update builder for Server.
  1248. func (c *ServerClient) Update() *ServerUpdate {
  1249. mutation := newServerMutation(c.config, OpUpdate)
  1250. return &ServerUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1251. }
  1252. // UpdateOne returns an update builder for the given entity.
  1253. func (c *ServerClient) UpdateOne(s *Server) *ServerUpdateOne {
  1254. mutation := newServerMutation(c.config, OpUpdateOne, withServer(s))
  1255. return &ServerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1256. }
  1257. // UpdateOneID returns an update builder for the given id.
  1258. func (c *ServerClient) UpdateOneID(id uint64) *ServerUpdateOne {
  1259. mutation := newServerMutation(c.config, OpUpdateOne, withServerID(id))
  1260. return &ServerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1261. }
  1262. // Delete returns a delete builder for Server.
  1263. func (c *ServerClient) Delete() *ServerDelete {
  1264. mutation := newServerMutation(c.config, OpDelete)
  1265. return &ServerDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1266. }
  1267. // DeleteOne returns a builder for deleting the given entity.
  1268. func (c *ServerClient) DeleteOne(s *Server) *ServerDeleteOne {
  1269. return c.DeleteOneID(s.ID)
  1270. }
  1271. // DeleteOneID returns a builder for deleting the given entity by its id.
  1272. func (c *ServerClient) DeleteOneID(id uint64) *ServerDeleteOne {
  1273. builder := c.Delete().Where(server.ID(id))
  1274. builder.mutation.id = &id
  1275. builder.mutation.op = OpDeleteOne
  1276. return &ServerDeleteOne{builder}
  1277. }
  1278. // Query returns a query builder for Server.
  1279. func (c *ServerClient) Query() *ServerQuery {
  1280. return &ServerQuery{
  1281. config: c.config,
  1282. ctx: &QueryContext{Type: TypeServer},
  1283. inters: c.Interceptors(),
  1284. }
  1285. }
  1286. // Get returns a Server entity by its id.
  1287. func (c *ServerClient) Get(ctx context.Context, id uint64) (*Server, error) {
  1288. return c.Query().Where(server.ID(id)).Only(ctx)
  1289. }
  1290. // GetX is like Get, but panics if an error occurs.
  1291. func (c *ServerClient) GetX(ctx context.Context, id uint64) *Server {
  1292. obj, err := c.Get(ctx, id)
  1293. if err != nil {
  1294. panic(err)
  1295. }
  1296. return obj
  1297. }
  1298. // QueryWxs queries the wxs edge of a Server.
  1299. func (c *ServerClient) QueryWxs(s *Server) *WxQuery {
  1300. query := (&WxClient{config: c.config}).Query()
  1301. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1302. id := s.ID
  1303. step := sqlgraph.NewStep(
  1304. sqlgraph.From(server.Table, server.FieldID, id),
  1305. sqlgraph.To(wx.Table, wx.FieldID),
  1306. sqlgraph.Edge(sqlgraph.O2M, false, server.WxsTable, server.WxsColumn),
  1307. )
  1308. fromV = sqlgraph.Neighbors(s.driver.Dialect(), step)
  1309. return fromV, nil
  1310. }
  1311. return query
  1312. }
  1313. // Hooks returns the client hooks.
  1314. func (c *ServerClient) Hooks() []Hook {
  1315. hooks := c.hooks.Server
  1316. return append(hooks[:len(hooks):len(hooks)], server.Hooks[:]...)
  1317. }
  1318. // Interceptors returns the client interceptors.
  1319. func (c *ServerClient) Interceptors() []Interceptor {
  1320. inters := c.inters.Server
  1321. return append(inters[:len(inters):len(inters)], server.Interceptors[:]...)
  1322. }
  1323. func (c *ServerClient) mutate(ctx context.Context, m *ServerMutation) (Value, error) {
  1324. switch m.Op() {
  1325. case OpCreate:
  1326. return (&ServerCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1327. case OpUpdate:
  1328. return (&ServerUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1329. case OpUpdateOne:
  1330. return (&ServerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1331. case OpDelete, OpDeleteOne:
  1332. return (&ServerDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1333. default:
  1334. return nil, fmt.Errorf("ent: unknown Server mutation op: %q", m.Op())
  1335. }
  1336. }
  1337. // SopNodeClient is a client for the SopNode schema.
  1338. type SopNodeClient struct {
  1339. config
  1340. }
  1341. // NewSopNodeClient returns a client for the SopNode from the given config.
  1342. func NewSopNodeClient(c config) *SopNodeClient {
  1343. return &SopNodeClient{config: c}
  1344. }
  1345. // Use adds a list of mutation hooks to the hooks stack.
  1346. // A call to `Use(f, g, h)` equals to `sopnode.Hooks(f(g(h())))`.
  1347. func (c *SopNodeClient) Use(hooks ...Hook) {
  1348. c.hooks.SopNode = append(c.hooks.SopNode, hooks...)
  1349. }
  1350. // Intercept adds a list of query interceptors to the interceptors stack.
  1351. // A call to `Intercept(f, g, h)` equals to `sopnode.Intercept(f(g(h())))`.
  1352. func (c *SopNodeClient) Intercept(interceptors ...Interceptor) {
  1353. c.inters.SopNode = append(c.inters.SopNode, interceptors...)
  1354. }
  1355. // Create returns a builder for creating a SopNode entity.
  1356. func (c *SopNodeClient) Create() *SopNodeCreate {
  1357. mutation := newSopNodeMutation(c.config, OpCreate)
  1358. return &SopNodeCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1359. }
  1360. // CreateBulk returns a builder for creating a bulk of SopNode entities.
  1361. func (c *SopNodeClient) CreateBulk(builders ...*SopNodeCreate) *SopNodeCreateBulk {
  1362. return &SopNodeCreateBulk{config: c.config, builders: builders}
  1363. }
  1364. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1365. // a builder and applies setFunc on it.
  1366. func (c *SopNodeClient) MapCreateBulk(slice any, setFunc func(*SopNodeCreate, int)) *SopNodeCreateBulk {
  1367. rv := reflect.ValueOf(slice)
  1368. if rv.Kind() != reflect.Slice {
  1369. return &SopNodeCreateBulk{err: fmt.Errorf("calling to SopNodeClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1370. }
  1371. builders := make([]*SopNodeCreate, rv.Len())
  1372. for i := 0; i < rv.Len(); i++ {
  1373. builders[i] = c.Create()
  1374. setFunc(builders[i], i)
  1375. }
  1376. return &SopNodeCreateBulk{config: c.config, builders: builders}
  1377. }
  1378. // Update returns an update builder for SopNode.
  1379. func (c *SopNodeClient) Update() *SopNodeUpdate {
  1380. mutation := newSopNodeMutation(c.config, OpUpdate)
  1381. return &SopNodeUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1382. }
  1383. // UpdateOne returns an update builder for the given entity.
  1384. func (c *SopNodeClient) UpdateOne(sn *SopNode) *SopNodeUpdateOne {
  1385. mutation := newSopNodeMutation(c.config, OpUpdateOne, withSopNode(sn))
  1386. return &SopNodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1387. }
  1388. // UpdateOneID returns an update builder for the given id.
  1389. func (c *SopNodeClient) UpdateOneID(id uint64) *SopNodeUpdateOne {
  1390. mutation := newSopNodeMutation(c.config, OpUpdateOne, withSopNodeID(id))
  1391. return &SopNodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1392. }
  1393. // Delete returns a delete builder for SopNode.
  1394. func (c *SopNodeClient) Delete() *SopNodeDelete {
  1395. mutation := newSopNodeMutation(c.config, OpDelete)
  1396. return &SopNodeDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1397. }
  1398. // DeleteOne returns a builder for deleting the given entity.
  1399. func (c *SopNodeClient) DeleteOne(sn *SopNode) *SopNodeDeleteOne {
  1400. return c.DeleteOneID(sn.ID)
  1401. }
  1402. // DeleteOneID returns a builder for deleting the given entity by its id.
  1403. func (c *SopNodeClient) DeleteOneID(id uint64) *SopNodeDeleteOne {
  1404. builder := c.Delete().Where(sopnode.ID(id))
  1405. builder.mutation.id = &id
  1406. builder.mutation.op = OpDeleteOne
  1407. return &SopNodeDeleteOne{builder}
  1408. }
  1409. // Query returns a query builder for SopNode.
  1410. func (c *SopNodeClient) Query() *SopNodeQuery {
  1411. return &SopNodeQuery{
  1412. config: c.config,
  1413. ctx: &QueryContext{Type: TypeSopNode},
  1414. inters: c.Interceptors(),
  1415. }
  1416. }
  1417. // Get returns a SopNode entity by its id.
  1418. func (c *SopNodeClient) Get(ctx context.Context, id uint64) (*SopNode, error) {
  1419. return c.Query().Where(sopnode.ID(id)).Only(ctx)
  1420. }
  1421. // GetX is like Get, but panics if an error occurs.
  1422. func (c *SopNodeClient) GetX(ctx context.Context, id uint64) *SopNode {
  1423. obj, err := c.Get(ctx, id)
  1424. if err != nil {
  1425. panic(err)
  1426. }
  1427. return obj
  1428. }
  1429. // QuerySopStage queries the sop_stage edge of a SopNode.
  1430. func (c *SopNodeClient) QuerySopStage(sn *SopNode) *SopStageQuery {
  1431. query := (&SopStageClient{config: c.config}).Query()
  1432. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1433. id := sn.ID
  1434. step := sqlgraph.NewStep(
  1435. sqlgraph.From(sopnode.Table, sopnode.FieldID, id),
  1436. sqlgraph.To(sopstage.Table, sopstage.FieldID),
  1437. sqlgraph.Edge(sqlgraph.M2O, true, sopnode.SopStageTable, sopnode.SopStageColumn),
  1438. )
  1439. fromV = sqlgraph.Neighbors(sn.driver.Dialect(), step)
  1440. return fromV, nil
  1441. }
  1442. return query
  1443. }
  1444. // QueryNodeMessages queries the node_messages edge of a SopNode.
  1445. func (c *SopNodeClient) QueryNodeMessages(sn *SopNode) *MessageRecordsQuery {
  1446. query := (&MessageRecordsClient{config: c.config}).Query()
  1447. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1448. id := sn.ID
  1449. step := sqlgraph.NewStep(
  1450. sqlgraph.From(sopnode.Table, sopnode.FieldID, id),
  1451. sqlgraph.To(messagerecords.Table, messagerecords.FieldID),
  1452. sqlgraph.Edge(sqlgraph.O2M, false, sopnode.NodeMessagesTable, sopnode.NodeMessagesColumn),
  1453. )
  1454. fromV = sqlgraph.Neighbors(sn.driver.Dialect(), step)
  1455. return fromV, nil
  1456. }
  1457. return query
  1458. }
  1459. // Hooks returns the client hooks.
  1460. func (c *SopNodeClient) Hooks() []Hook {
  1461. hooks := c.hooks.SopNode
  1462. return append(hooks[:len(hooks):len(hooks)], sopnode.Hooks[:]...)
  1463. }
  1464. // Interceptors returns the client interceptors.
  1465. func (c *SopNodeClient) Interceptors() []Interceptor {
  1466. inters := c.inters.SopNode
  1467. return append(inters[:len(inters):len(inters)], sopnode.Interceptors[:]...)
  1468. }
  1469. func (c *SopNodeClient) mutate(ctx context.Context, m *SopNodeMutation) (Value, error) {
  1470. switch m.Op() {
  1471. case OpCreate:
  1472. return (&SopNodeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1473. case OpUpdate:
  1474. return (&SopNodeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1475. case OpUpdateOne:
  1476. return (&SopNodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1477. case OpDelete, OpDeleteOne:
  1478. return (&SopNodeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1479. default:
  1480. return nil, fmt.Errorf("ent: unknown SopNode mutation op: %q", m.Op())
  1481. }
  1482. }
  1483. // SopStageClient is a client for the SopStage schema.
  1484. type SopStageClient struct {
  1485. config
  1486. }
  1487. // NewSopStageClient returns a client for the SopStage from the given config.
  1488. func NewSopStageClient(c config) *SopStageClient {
  1489. return &SopStageClient{config: c}
  1490. }
  1491. // Use adds a list of mutation hooks to the hooks stack.
  1492. // A call to `Use(f, g, h)` equals to `sopstage.Hooks(f(g(h())))`.
  1493. func (c *SopStageClient) Use(hooks ...Hook) {
  1494. c.hooks.SopStage = append(c.hooks.SopStage, hooks...)
  1495. }
  1496. // Intercept adds a list of query interceptors to the interceptors stack.
  1497. // A call to `Intercept(f, g, h)` equals to `sopstage.Intercept(f(g(h())))`.
  1498. func (c *SopStageClient) Intercept(interceptors ...Interceptor) {
  1499. c.inters.SopStage = append(c.inters.SopStage, interceptors...)
  1500. }
  1501. // Create returns a builder for creating a SopStage entity.
  1502. func (c *SopStageClient) Create() *SopStageCreate {
  1503. mutation := newSopStageMutation(c.config, OpCreate)
  1504. return &SopStageCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1505. }
  1506. // CreateBulk returns a builder for creating a bulk of SopStage entities.
  1507. func (c *SopStageClient) CreateBulk(builders ...*SopStageCreate) *SopStageCreateBulk {
  1508. return &SopStageCreateBulk{config: c.config, builders: builders}
  1509. }
  1510. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1511. // a builder and applies setFunc on it.
  1512. func (c *SopStageClient) MapCreateBulk(slice any, setFunc func(*SopStageCreate, int)) *SopStageCreateBulk {
  1513. rv := reflect.ValueOf(slice)
  1514. if rv.Kind() != reflect.Slice {
  1515. return &SopStageCreateBulk{err: fmt.Errorf("calling to SopStageClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1516. }
  1517. builders := make([]*SopStageCreate, rv.Len())
  1518. for i := 0; i < rv.Len(); i++ {
  1519. builders[i] = c.Create()
  1520. setFunc(builders[i], i)
  1521. }
  1522. return &SopStageCreateBulk{config: c.config, builders: builders}
  1523. }
  1524. // Update returns an update builder for SopStage.
  1525. func (c *SopStageClient) Update() *SopStageUpdate {
  1526. mutation := newSopStageMutation(c.config, OpUpdate)
  1527. return &SopStageUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1528. }
  1529. // UpdateOne returns an update builder for the given entity.
  1530. func (c *SopStageClient) UpdateOne(ss *SopStage) *SopStageUpdateOne {
  1531. mutation := newSopStageMutation(c.config, OpUpdateOne, withSopStage(ss))
  1532. return &SopStageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1533. }
  1534. // UpdateOneID returns an update builder for the given id.
  1535. func (c *SopStageClient) UpdateOneID(id uint64) *SopStageUpdateOne {
  1536. mutation := newSopStageMutation(c.config, OpUpdateOne, withSopStageID(id))
  1537. return &SopStageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1538. }
  1539. // Delete returns a delete builder for SopStage.
  1540. func (c *SopStageClient) Delete() *SopStageDelete {
  1541. mutation := newSopStageMutation(c.config, OpDelete)
  1542. return &SopStageDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1543. }
  1544. // DeleteOne returns a builder for deleting the given entity.
  1545. func (c *SopStageClient) DeleteOne(ss *SopStage) *SopStageDeleteOne {
  1546. return c.DeleteOneID(ss.ID)
  1547. }
  1548. // DeleteOneID returns a builder for deleting the given entity by its id.
  1549. func (c *SopStageClient) DeleteOneID(id uint64) *SopStageDeleteOne {
  1550. builder := c.Delete().Where(sopstage.ID(id))
  1551. builder.mutation.id = &id
  1552. builder.mutation.op = OpDeleteOne
  1553. return &SopStageDeleteOne{builder}
  1554. }
  1555. // Query returns a query builder for SopStage.
  1556. func (c *SopStageClient) Query() *SopStageQuery {
  1557. return &SopStageQuery{
  1558. config: c.config,
  1559. ctx: &QueryContext{Type: TypeSopStage},
  1560. inters: c.Interceptors(),
  1561. }
  1562. }
  1563. // Get returns a SopStage entity by its id.
  1564. func (c *SopStageClient) Get(ctx context.Context, id uint64) (*SopStage, error) {
  1565. return c.Query().Where(sopstage.ID(id)).Only(ctx)
  1566. }
  1567. // GetX is like Get, but panics if an error occurs.
  1568. func (c *SopStageClient) GetX(ctx context.Context, id uint64) *SopStage {
  1569. obj, err := c.Get(ctx, id)
  1570. if err != nil {
  1571. panic(err)
  1572. }
  1573. return obj
  1574. }
  1575. // QuerySopTask queries the sop_task edge of a SopStage.
  1576. func (c *SopStageClient) QuerySopTask(ss *SopStage) *SopTaskQuery {
  1577. query := (&SopTaskClient{config: c.config}).Query()
  1578. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1579. id := ss.ID
  1580. step := sqlgraph.NewStep(
  1581. sqlgraph.From(sopstage.Table, sopstage.FieldID, id),
  1582. sqlgraph.To(soptask.Table, soptask.FieldID),
  1583. sqlgraph.Edge(sqlgraph.M2O, true, sopstage.SopTaskTable, sopstage.SopTaskColumn),
  1584. )
  1585. fromV = sqlgraph.Neighbors(ss.driver.Dialect(), step)
  1586. return fromV, nil
  1587. }
  1588. return query
  1589. }
  1590. // QueryStageNodes queries the stage_nodes edge of a SopStage.
  1591. func (c *SopStageClient) QueryStageNodes(ss *SopStage) *SopNodeQuery {
  1592. query := (&SopNodeClient{config: c.config}).Query()
  1593. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1594. id := ss.ID
  1595. step := sqlgraph.NewStep(
  1596. sqlgraph.From(sopstage.Table, sopstage.FieldID, id),
  1597. sqlgraph.To(sopnode.Table, sopnode.FieldID),
  1598. sqlgraph.Edge(sqlgraph.O2M, false, sopstage.StageNodesTable, sopstage.StageNodesColumn),
  1599. )
  1600. fromV = sqlgraph.Neighbors(ss.driver.Dialect(), step)
  1601. return fromV, nil
  1602. }
  1603. return query
  1604. }
  1605. // QueryStageMessages queries the stage_messages edge of a SopStage.
  1606. func (c *SopStageClient) QueryStageMessages(ss *SopStage) *MessageRecordsQuery {
  1607. query := (&MessageRecordsClient{config: c.config}).Query()
  1608. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1609. id := ss.ID
  1610. step := sqlgraph.NewStep(
  1611. sqlgraph.From(sopstage.Table, sopstage.FieldID, id),
  1612. sqlgraph.To(messagerecords.Table, messagerecords.FieldID),
  1613. sqlgraph.Edge(sqlgraph.O2M, false, sopstage.StageMessagesTable, sopstage.StageMessagesColumn),
  1614. )
  1615. fromV = sqlgraph.Neighbors(ss.driver.Dialect(), step)
  1616. return fromV, nil
  1617. }
  1618. return query
  1619. }
  1620. // Hooks returns the client hooks.
  1621. func (c *SopStageClient) Hooks() []Hook {
  1622. hooks := c.hooks.SopStage
  1623. return append(hooks[:len(hooks):len(hooks)], sopstage.Hooks[:]...)
  1624. }
  1625. // Interceptors returns the client interceptors.
  1626. func (c *SopStageClient) Interceptors() []Interceptor {
  1627. inters := c.inters.SopStage
  1628. return append(inters[:len(inters):len(inters)], sopstage.Interceptors[:]...)
  1629. }
  1630. func (c *SopStageClient) mutate(ctx context.Context, m *SopStageMutation) (Value, error) {
  1631. switch m.Op() {
  1632. case OpCreate:
  1633. return (&SopStageCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1634. case OpUpdate:
  1635. return (&SopStageUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1636. case OpUpdateOne:
  1637. return (&SopStageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1638. case OpDelete, OpDeleteOne:
  1639. return (&SopStageDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1640. default:
  1641. return nil, fmt.Errorf("ent: unknown SopStage mutation op: %q", m.Op())
  1642. }
  1643. }
  1644. // SopTaskClient is a client for the SopTask schema.
  1645. type SopTaskClient struct {
  1646. config
  1647. }
  1648. // NewSopTaskClient returns a client for the SopTask from the given config.
  1649. func NewSopTaskClient(c config) *SopTaskClient {
  1650. return &SopTaskClient{config: c}
  1651. }
  1652. // Use adds a list of mutation hooks to the hooks stack.
  1653. // A call to `Use(f, g, h)` equals to `soptask.Hooks(f(g(h())))`.
  1654. func (c *SopTaskClient) Use(hooks ...Hook) {
  1655. c.hooks.SopTask = append(c.hooks.SopTask, hooks...)
  1656. }
  1657. // Intercept adds a list of query interceptors to the interceptors stack.
  1658. // A call to `Intercept(f, g, h)` equals to `soptask.Intercept(f(g(h())))`.
  1659. func (c *SopTaskClient) Intercept(interceptors ...Interceptor) {
  1660. c.inters.SopTask = append(c.inters.SopTask, interceptors...)
  1661. }
  1662. // Create returns a builder for creating a SopTask entity.
  1663. func (c *SopTaskClient) Create() *SopTaskCreate {
  1664. mutation := newSopTaskMutation(c.config, OpCreate)
  1665. return &SopTaskCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1666. }
  1667. // CreateBulk returns a builder for creating a bulk of SopTask entities.
  1668. func (c *SopTaskClient) CreateBulk(builders ...*SopTaskCreate) *SopTaskCreateBulk {
  1669. return &SopTaskCreateBulk{config: c.config, builders: builders}
  1670. }
  1671. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1672. // a builder and applies setFunc on it.
  1673. func (c *SopTaskClient) MapCreateBulk(slice any, setFunc func(*SopTaskCreate, int)) *SopTaskCreateBulk {
  1674. rv := reflect.ValueOf(slice)
  1675. if rv.Kind() != reflect.Slice {
  1676. return &SopTaskCreateBulk{err: fmt.Errorf("calling to SopTaskClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1677. }
  1678. builders := make([]*SopTaskCreate, rv.Len())
  1679. for i := 0; i < rv.Len(); i++ {
  1680. builders[i] = c.Create()
  1681. setFunc(builders[i], i)
  1682. }
  1683. return &SopTaskCreateBulk{config: c.config, builders: builders}
  1684. }
  1685. // Update returns an update builder for SopTask.
  1686. func (c *SopTaskClient) Update() *SopTaskUpdate {
  1687. mutation := newSopTaskMutation(c.config, OpUpdate)
  1688. return &SopTaskUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1689. }
  1690. // UpdateOne returns an update builder for the given entity.
  1691. func (c *SopTaskClient) UpdateOne(st *SopTask) *SopTaskUpdateOne {
  1692. mutation := newSopTaskMutation(c.config, OpUpdateOne, withSopTask(st))
  1693. return &SopTaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1694. }
  1695. // UpdateOneID returns an update builder for the given id.
  1696. func (c *SopTaskClient) UpdateOneID(id uint64) *SopTaskUpdateOne {
  1697. mutation := newSopTaskMutation(c.config, OpUpdateOne, withSopTaskID(id))
  1698. return &SopTaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1699. }
  1700. // Delete returns a delete builder for SopTask.
  1701. func (c *SopTaskClient) Delete() *SopTaskDelete {
  1702. mutation := newSopTaskMutation(c.config, OpDelete)
  1703. return &SopTaskDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1704. }
  1705. // DeleteOne returns a builder for deleting the given entity.
  1706. func (c *SopTaskClient) DeleteOne(st *SopTask) *SopTaskDeleteOne {
  1707. return c.DeleteOneID(st.ID)
  1708. }
  1709. // DeleteOneID returns a builder for deleting the given entity by its id.
  1710. func (c *SopTaskClient) DeleteOneID(id uint64) *SopTaskDeleteOne {
  1711. builder := c.Delete().Where(soptask.ID(id))
  1712. builder.mutation.id = &id
  1713. builder.mutation.op = OpDeleteOne
  1714. return &SopTaskDeleteOne{builder}
  1715. }
  1716. // Query returns a query builder for SopTask.
  1717. func (c *SopTaskClient) Query() *SopTaskQuery {
  1718. return &SopTaskQuery{
  1719. config: c.config,
  1720. ctx: &QueryContext{Type: TypeSopTask},
  1721. inters: c.Interceptors(),
  1722. }
  1723. }
  1724. // Get returns a SopTask entity by its id.
  1725. func (c *SopTaskClient) Get(ctx context.Context, id uint64) (*SopTask, error) {
  1726. return c.Query().Where(soptask.ID(id)).Only(ctx)
  1727. }
  1728. // GetX is like Get, but panics if an error occurs.
  1729. func (c *SopTaskClient) GetX(ctx context.Context, id uint64) *SopTask {
  1730. obj, err := c.Get(ctx, id)
  1731. if err != nil {
  1732. panic(err)
  1733. }
  1734. return obj
  1735. }
  1736. // QueryTaskStages queries the task_stages edge of a SopTask.
  1737. func (c *SopTaskClient) QueryTaskStages(st *SopTask) *SopStageQuery {
  1738. query := (&SopStageClient{config: c.config}).Query()
  1739. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1740. id := st.ID
  1741. step := sqlgraph.NewStep(
  1742. sqlgraph.From(soptask.Table, soptask.FieldID, id),
  1743. sqlgraph.To(sopstage.Table, sopstage.FieldID),
  1744. sqlgraph.Edge(sqlgraph.O2M, false, soptask.TaskStagesTable, soptask.TaskStagesColumn),
  1745. )
  1746. fromV = sqlgraph.Neighbors(st.driver.Dialect(), step)
  1747. return fromV, nil
  1748. }
  1749. return query
  1750. }
  1751. // Hooks returns the client hooks.
  1752. func (c *SopTaskClient) Hooks() []Hook {
  1753. hooks := c.hooks.SopTask
  1754. return append(hooks[:len(hooks):len(hooks)], soptask.Hooks[:]...)
  1755. }
  1756. // Interceptors returns the client interceptors.
  1757. func (c *SopTaskClient) Interceptors() []Interceptor {
  1758. inters := c.inters.SopTask
  1759. return append(inters[:len(inters):len(inters)], soptask.Interceptors[:]...)
  1760. }
  1761. func (c *SopTaskClient) mutate(ctx context.Context, m *SopTaskMutation) (Value, error) {
  1762. switch m.Op() {
  1763. case OpCreate:
  1764. return (&SopTaskCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1765. case OpUpdate:
  1766. return (&SopTaskUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1767. case OpUpdateOne:
  1768. return (&SopTaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1769. case OpDelete, OpDeleteOne:
  1770. return (&SopTaskDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1771. default:
  1772. return nil, fmt.Errorf("ent: unknown SopTask mutation op: %q", m.Op())
  1773. }
  1774. }
  1775. // WxClient is a client for the Wx schema.
  1776. type WxClient struct {
  1777. config
  1778. }
  1779. // NewWxClient returns a client for the Wx from the given config.
  1780. func NewWxClient(c config) *WxClient {
  1781. return &WxClient{config: c}
  1782. }
  1783. // Use adds a list of mutation hooks to the hooks stack.
  1784. // A call to `Use(f, g, h)` equals to `wx.Hooks(f(g(h())))`.
  1785. func (c *WxClient) Use(hooks ...Hook) {
  1786. c.hooks.Wx = append(c.hooks.Wx, hooks...)
  1787. }
  1788. // Intercept adds a list of query interceptors to the interceptors stack.
  1789. // A call to `Intercept(f, g, h)` equals to `wx.Intercept(f(g(h())))`.
  1790. func (c *WxClient) Intercept(interceptors ...Interceptor) {
  1791. c.inters.Wx = append(c.inters.Wx, interceptors...)
  1792. }
  1793. // Create returns a builder for creating a Wx entity.
  1794. func (c *WxClient) Create() *WxCreate {
  1795. mutation := newWxMutation(c.config, OpCreate)
  1796. return &WxCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1797. }
  1798. // CreateBulk returns a builder for creating a bulk of Wx entities.
  1799. func (c *WxClient) CreateBulk(builders ...*WxCreate) *WxCreateBulk {
  1800. return &WxCreateBulk{config: c.config, builders: builders}
  1801. }
  1802. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1803. // a builder and applies setFunc on it.
  1804. func (c *WxClient) MapCreateBulk(slice any, setFunc func(*WxCreate, int)) *WxCreateBulk {
  1805. rv := reflect.ValueOf(slice)
  1806. if rv.Kind() != reflect.Slice {
  1807. return &WxCreateBulk{err: fmt.Errorf("calling to WxClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1808. }
  1809. builders := make([]*WxCreate, rv.Len())
  1810. for i := 0; i < rv.Len(); i++ {
  1811. builders[i] = c.Create()
  1812. setFunc(builders[i], i)
  1813. }
  1814. return &WxCreateBulk{config: c.config, builders: builders}
  1815. }
  1816. // Update returns an update builder for Wx.
  1817. func (c *WxClient) Update() *WxUpdate {
  1818. mutation := newWxMutation(c.config, OpUpdate)
  1819. return &WxUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1820. }
  1821. // UpdateOne returns an update builder for the given entity.
  1822. func (c *WxClient) UpdateOne(w *Wx) *WxUpdateOne {
  1823. mutation := newWxMutation(c.config, OpUpdateOne, withWx(w))
  1824. return &WxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1825. }
  1826. // UpdateOneID returns an update builder for the given id.
  1827. func (c *WxClient) UpdateOneID(id uint64) *WxUpdateOne {
  1828. mutation := newWxMutation(c.config, OpUpdateOne, withWxID(id))
  1829. return &WxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1830. }
  1831. // Delete returns a delete builder for Wx.
  1832. func (c *WxClient) Delete() *WxDelete {
  1833. mutation := newWxMutation(c.config, OpDelete)
  1834. return &WxDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1835. }
  1836. // DeleteOne returns a builder for deleting the given entity.
  1837. func (c *WxClient) DeleteOne(w *Wx) *WxDeleteOne {
  1838. return c.DeleteOneID(w.ID)
  1839. }
  1840. // DeleteOneID returns a builder for deleting the given entity by its id.
  1841. func (c *WxClient) DeleteOneID(id uint64) *WxDeleteOne {
  1842. builder := c.Delete().Where(wx.ID(id))
  1843. builder.mutation.id = &id
  1844. builder.mutation.op = OpDeleteOne
  1845. return &WxDeleteOne{builder}
  1846. }
  1847. // Query returns a query builder for Wx.
  1848. func (c *WxClient) Query() *WxQuery {
  1849. return &WxQuery{
  1850. config: c.config,
  1851. ctx: &QueryContext{Type: TypeWx},
  1852. inters: c.Interceptors(),
  1853. }
  1854. }
  1855. // Get returns a Wx entity by its id.
  1856. func (c *WxClient) Get(ctx context.Context, id uint64) (*Wx, error) {
  1857. return c.Query().Where(wx.ID(id)).Only(ctx)
  1858. }
  1859. // GetX is like Get, but panics if an error occurs.
  1860. func (c *WxClient) GetX(ctx context.Context, id uint64) *Wx {
  1861. obj, err := c.Get(ctx, id)
  1862. if err != nil {
  1863. panic(err)
  1864. }
  1865. return obj
  1866. }
  1867. // QueryServer queries the server edge of a Wx.
  1868. func (c *WxClient) QueryServer(w *Wx) *ServerQuery {
  1869. query := (&ServerClient{config: c.config}).Query()
  1870. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1871. id := w.ID
  1872. step := sqlgraph.NewStep(
  1873. sqlgraph.From(wx.Table, wx.FieldID, id),
  1874. sqlgraph.To(server.Table, server.FieldID),
  1875. sqlgraph.Edge(sqlgraph.M2O, true, wx.ServerTable, wx.ServerColumn),
  1876. )
  1877. fromV = sqlgraph.Neighbors(w.driver.Dialect(), step)
  1878. return fromV, nil
  1879. }
  1880. return query
  1881. }
  1882. // Hooks returns the client hooks.
  1883. func (c *WxClient) Hooks() []Hook {
  1884. hooks := c.hooks.Wx
  1885. return append(hooks[:len(hooks):len(hooks)], wx.Hooks[:]...)
  1886. }
  1887. // Interceptors returns the client interceptors.
  1888. func (c *WxClient) Interceptors() []Interceptor {
  1889. inters := c.inters.Wx
  1890. return append(inters[:len(inters):len(inters)], wx.Interceptors[:]...)
  1891. }
  1892. func (c *WxClient) mutate(ctx context.Context, m *WxMutation) (Value, error) {
  1893. switch m.Op() {
  1894. case OpCreate:
  1895. return (&WxCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1896. case OpUpdate:
  1897. return (&WxUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1898. case OpUpdateOne:
  1899. return (&WxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1900. case OpDelete, OpDeleteOne:
  1901. return (&WxDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1902. default:
  1903. return nil, fmt.Errorf("ent: unknown Wx mutation op: %q", m.Op())
  1904. }
  1905. }
  1906. // hooks and interceptors per client, for fast access.
  1907. type (
  1908. hooks struct {
  1909. BatchMsg, Contact, Label, LabelRelationship, Message, MessageRecords, Msg,
  1910. Server, SopNode, SopStage, SopTask, Wx []ent.Hook
  1911. }
  1912. inters struct {
  1913. BatchMsg, Contact, Label, LabelRelationship, Message, MessageRecords, Msg,
  1914. Server, SopNode, SopStage, SopTask, Wx []ent.Interceptor
  1915. }
  1916. )
  1917. // ExecContext allows calling the underlying ExecContext method of the driver if it is supported by it.
  1918. // See, database/sql#DB.ExecContext for more information.
  1919. func (c *config) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) {
  1920. ex, ok := c.driver.(interface {
  1921. ExecContext(context.Context, string, ...any) (stdsql.Result, error)
  1922. })
  1923. if !ok {
  1924. return nil, fmt.Errorf("Driver.ExecContext is not supported")
  1925. }
  1926. return ex.ExecContext(ctx, query, args...)
  1927. }
  1928. // QueryContext allows calling the underlying QueryContext method of the driver if it is supported by it.
  1929. // See, database/sql#DB.QueryContext for more information.
  1930. func (c *config) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) {
  1931. q, ok := c.driver.(interface {
  1932. QueryContext(context.Context, string, ...any) (*stdsql.Rows, error)
  1933. })
  1934. if !ok {
  1935. return nil, fmt.Errorf("Driver.QueryContext is not supported")
  1936. }
  1937. return q.QueryContext(ctx, query, args...)
  1938. }