client.go 68 KB

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