client.go 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  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/server"
  15. "wechat-api/ent/wx"
  16. "entgo.io/ent"
  17. "entgo.io/ent/dialect"
  18. "entgo.io/ent/dialect/sql"
  19. "entgo.io/ent/dialect/sql/sqlgraph"
  20. stdsql "database/sql"
  21. )
  22. // Client is the client that holds all ent builders.
  23. type Client struct {
  24. config
  25. // Schema is the client for creating, migrating and dropping schema.
  26. Schema *migrate.Schema
  27. // Contact is the client for interacting with the Contact builders.
  28. Contact *ContactClient
  29. // Label is the client for interacting with the Label builders.
  30. Label *LabelClient
  31. // LabelRelationship is the client for interacting with the LabelRelationship builders.
  32. LabelRelationship *LabelRelationshipClient
  33. // Message is the client for interacting with the Message builders.
  34. Message *MessageClient
  35. // Server is the client for interacting with the Server builders.
  36. Server *ServerClient
  37. // Wx is the client for interacting with the Wx builders.
  38. Wx *WxClient
  39. }
  40. // NewClient creates a new client configured with the given options.
  41. func NewClient(opts ...Option) *Client {
  42. client := &Client{config: newConfig(opts...)}
  43. client.init()
  44. return client
  45. }
  46. func (c *Client) init() {
  47. c.Schema = migrate.NewSchema(c.driver)
  48. c.Contact = NewContactClient(c.config)
  49. c.Label = NewLabelClient(c.config)
  50. c.LabelRelationship = NewLabelRelationshipClient(c.config)
  51. c.Message = NewMessageClient(c.config)
  52. c.Server = NewServerClient(c.config)
  53. c.Wx = NewWxClient(c.config)
  54. }
  55. type (
  56. // config is the configuration for the client and its builder.
  57. config struct {
  58. // driver used for executing database requests.
  59. driver dialect.Driver
  60. // debug enable a debug logging.
  61. debug bool
  62. // log used for logging on debug mode.
  63. log func(...any)
  64. // hooks to execute on mutations.
  65. hooks *hooks
  66. // interceptors to execute on queries.
  67. inters *inters
  68. }
  69. // Option function to configure the client.
  70. Option func(*config)
  71. )
  72. // newConfig creates a new config for the client.
  73. func newConfig(opts ...Option) config {
  74. cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
  75. cfg.options(opts...)
  76. return cfg
  77. }
  78. // options applies the options on the config object.
  79. func (c *config) options(opts ...Option) {
  80. for _, opt := range opts {
  81. opt(c)
  82. }
  83. if c.debug {
  84. c.driver = dialect.Debug(c.driver, c.log)
  85. }
  86. }
  87. // Debug enables debug logging on the ent.Driver.
  88. func Debug() Option {
  89. return func(c *config) {
  90. c.debug = true
  91. }
  92. }
  93. // Log sets the logging function for debug mode.
  94. func Log(fn func(...any)) Option {
  95. return func(c *config) {
  96. c.log = fn
  97. }
  98. }
  99. // Driver configures the client driver.
  100. func Driver(driver dialect.Driver) Option {
  101. return func(c *config) {
  102. c.driver = driver
  103. }
  104. }
  105. // Open opens a database/sql.DB specified by the driver name and
  106. // the data source name, and returns a new client attached to it.
  107. // Optional parameters can be added for configuring the client.
  108. func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
  109. switch driverName {
  110. case dialect.MySQL, dialect.Postgres, dialect.SQLite:
  111. drv, err := sql.Open(driverName, dataSourceName)
  112. if err != nil {
  113. return nil, err
  114. }
  115. return NewClient(append(options, Driver(drv))...), nil
  116. default:
  117. return nil, fmt.Errorf("unsupported driver: %q", driverName)
  118. }
  119. }
  120. // ErrTxStarted is returned when trying to start a new transaction from a transactional client.
  121. var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction")
  122. // Tx returns a new transactional client. The provided context
  123. // is used until the transaction is committed or rolled back.
  124. func (c *Client) Tx(ctx context.Context) (*Tx, error) {
  125. if _, ok := c.driver.(*txDriver); ok {
  126. return nil, ErrTxStarted
  127. }
  128. tx, err := newTx(ctx, c.driver)
  129. if err != nil {
  130. return nil, fmt.Errorf("ent: starting a transaction: %w", err)
  131. }
  132. cfg := c.config
  133. cfg.driver = tx
  134. return &Tx{
  135. ctx: ctx,
  136. config: cfg,
  137. Contact: NewContactClient(cfg),
  138. Label: NewLabelClient(cfg),
  139. LabelRelationship: NewLabelRelationshipClient(cfg),
  140. Message: NewMessageClient(cfg),
  141. Server: NewServerClient(cfg),
  142. Wx: NewWxClient(cfg),
  143. }, nil
  144. }
  145. // BeginTx returns a transactional client with specified options.
  146. func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
  147. if _, ok := c.driver.(*txDriver); ok {
  148. return nil, errors.New("ent: cannot start a transaction within a transaction")
  149. }
  150. tx, err := c.driver.(interface {
  151. BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)
  152. }).BeginTx(ctx, opts)
  153. if err != nil {
  154. return nil, fmt.Errorf("ent: starting a transaction: %w", err)
  155. }
  156. cfg := c.config
  157. cfg.driver = &txDriver{tx: tx, drv: c.driver}
  158. return &Tx{
  159. ctx: ctx,
  160. config: cfg,
  161. Contact: NewContactClient(cfg),
  162. Label: NewLabelClient(cfg),
  163. LabelRelationship: NewLabelRelationshipClient(cfg),
  164. Message: NewMessageClient(cfg),
  165. Server: NewServerClient(cfg),
  166. Wx: NewWxClient(cfg),
  167. }, nil
  168. }
  169. // Debug returns a new debug-client. It's used to get verbose logging on specific operations.
  170. //
  171. // client.Debug().
  172. // Contact.
  173. // Query().
  174. // Count(ctx)
  175. func (c *Client) Debug() *Client {
  176. if c.debug {
  177. return c
  178. }
  179. cfg := c.config
  180. cfg.driver = dialect.Debug(c.driver, c.log)
  181. client := &Client{config: cfg}
  182. client.init()
  183. return client
  184. }
  185. // Close closes the database connection and prevents new queries from starting.
  186. func (c *Client) Close() error {
  187. return c.driver.Close()
  188. }
  189. // Use adds the mutation hooks to all the entity clients.
  190. // In order to add hooks to a specific client, call: `client.Node.Use(...)`.
  191. func (c *Client) Use(hooks ...Hook) {
  192. for _, n := range []interface{ Use(...Hook) }{
  193. c.Contact, c.Label, c.LabelRelationship, c.Message, c.Server, c.Wx,
  194. } {
  195. n.Use(hooks...)
  196. }
  197. }
  198. // Intercept adds the query interceptors to all the entity clients.
  199. // In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
  200. func (c *Client) Intercept(interceptors ...Interceptor) {
  201. for _, n := range []interface{ Intercept(...Interceptor) }{
  202. c.Contact, c.Label, c.LabelRelationship, c.Message, c.Server, c.Wx,
  203. } {
  204. n.Intercept(interceptors...)
  205. }
  206. }
  207. // Mutate implements the ent.Mutator interface.
  208. func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
  209. switch m := m.(type) {
  210. case *ContactMutation:
  211. return c.Contact.mutate(ctx, m)
  212. case *LabelMutation:
  213. return c.Label.mutate(ctx, m)
  214. case *LabelRelationshipMutation:
  215. return c.LabelRelationship.mutate(ctx, m)
  216. case *MessageMutation:
  217. return c.Message.mutate(ctx, m)
  218. case *ServerMutation:
  219. return c.Server.mutate(ctx, m)
  220. case *WxMutation:
  221. return c.Wx.mutate(ctx, m)
  222. default:
  223. return nil, fmt.Errorf("ent: unknown mutation type %T", m)
  224. }
  225. }
  226. // ContactClient is a client for the Contact schema.
  227. type ContactClient struct {
  228. config
  229. }
  230. // NewContactClient returns a client for the Contact from the given config.
  231. func NewContactClient(c config) *ContactClient {
  232. return &ContactClient{config: c}
  233. }
  234. // Use adds a list of mutation hooks to the hooks stack.
  235. // A call to `Use(f, g, h)` equals to `contact.Hooks(f(g(h())))`.
  236. func (c *ContactClient) Use(hooks ...Hook) {
  237. c.hooks.Contact = append(c.hooks.Contact, hooks...)
  238. }
  239. // Intercept adds a list of query interceptors to the interceptors stack.
  240. // A call to `Intercept(f, g, h)` equals to `contact.Intercept(f(g(h())))`.
  241. func (c *ContactClient) Intercept(interceptors ...Interceptor) {
  242. c.inters.Contact = append(c.inters.Contact, interceptors...)
  243. }
  244. // Create returns a builder for creating a Contact entity.
  245. func (c *ContactClient) Create() *ContactCreate {
  246. mutation := newContactMutation(c.config, OpCreate)
  247. return &ContactCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  248. }
  249. // CreateBulk returns a builder for creating a bulk of Contact entities.
  250. func (c *ContactClient) CreateBulk(builders ...*ContactCreate) *ContactCreateBulk {
  251. return &ContactCreateBulk{config: c.config, builders: builders}
  252. }
  253. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  254. // a builder and applies setFunc on it.
  255. func (c *ContactClient) MapCreateBulk(slice any, setFunc func(*ContactCreate, int)) *ContactCreateBulk {
  256. rv := reflect.ValueOf(slice)
  257. if rv.Kind() != reflect.Slice {
  258. return &ContactCreateBulk{err: fmt.Errorf("calling to ContactClient.MapCreateBulk with wrong type %T, need slice", slice)}
  259. }
  260. builders := make([]*ContactCreate, rv.Len())
  261. for i := 0; i < rv.Len(); i++ {
  262. builders[i] = c.Create()
  263. setFunc(builders[i], i)
  264. }
  265. return &ContactCreateBulk{config: c.config, builders: builders}
  266. }
  267. // Update returns an update builder for Contact.
  268. func (c *ContactClient) Update() *ContactUpdate {
  269. mutation := newContactMutation(c.config, OpUpdate)
  270. return &ContactUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  271. }
  272. // UpdateOne returns an update builder for the given entity.
  273. func (c *ContactClient) UpdateOne(co *Contact) *ContactUpdateOne {
  274. mutation := newContactMutation(c.config, OpUpdateOne, withContact(co))
  275. return &ContactUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  276. }
  277. // UpdateOneID returns an update builder for the given id.
  278. func (c *ContactClient) UpdateOneID(id uint64) *ContactUpdateOne {
  279. mutation := newContactMutation(c.config, OpUpdateOne, withContactID(id))
  280. return &ContactUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  281. }
  282. // Delete returns a delete builder for Contact.
  283. func (c *ContactClient) Delete() *ContactDelete {
  284. mutation := newContactMutation(c.config, OpDelete)
  285. return &ContactDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  286. }
  287. // DeleteOne returns a builder for deleting the given entity.
  288. func (c *ContactClient) DeleteOne(co *Contact) *ContactDeleteOne {
  289. return c.DeleteOneID(co.ID)
  290. }
  291. // DeleteOneID returns a builder for deleting the given entity by its id.
  292. func (c *ContactClient) DeleteOneID(id uint64) *ContactDeleteOne {
  293. builder := c.Delete().Where(contact.ID(id))
  294. builder.mutation.id = &id
  295. builder.mutation.op = OpDeleteOne
  296. return &ContactDeleteOne{builder}
  297. }
  298. // Query returns a query builder for Contact.
  299. func (c *ContactClient) Query() *ContactQuery {
  300. return &ContactQuery{
  301. config: c.config,
  302. ctx: &QueryContext{Type: TypeContact},
  303. inters: c.Interceptors(),
  304. }
  305. }
  306. // Get returns a Contact entity by its id.
  307. func (c *ContactClient) Get(ctx context.Context, id uint64) (*Contact, error) {
  308. return c.Query().Where(contact.ID(id)).Only(ctx)
  309. }
  310. // GetX is like Get, but panics if an error occurs.
  311. func (c *ContactClient) GetX(ctx context.Context, id uint64) *Contact {
  312. obj, err := c.Get(ctx, id)
  313. if err != nil {
  314. panic(err)
  315. }
  316. return obj
  317. }
  318. // QueryContactRelationships queries the contact_relationships edge of a Contact.
  319. func (c *ContactClient) QueryContactRelationships(co *Contact) *LabelRelationshipQuery {
  320. query := (&LabelRelationshipClient{config: c.config}).Query()
  321. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  322. id := co.ID
  323. step := sqlgraph.NewStep(
  324. sqlgraph.From(contact.Table, contact.FieldID, id),
  325. sqlgraph.To(labelrelationship.Table, labelrelationship.FieldID),
  326. sqlgraph.Edge(sqlgraph.O2M, false, contact.ContactRelationshipsTable, contact.ContactRelationshipsColumn),
  327. )
  328. fromV = sqlgraph.Neighbors(co.driver.Dialect(), step)
  329. return fromV, nil
  330. }
  331. return query
  332. }
  333. // Hooks returns the client hooks.
  334. func (c *ContactClient) Hooks() []Hook {
  335. hooks := c.hooks.Contact
  336. return append(hooks[:len(hooks):len(hooks)], contact.Hooks[:]...)
  337. }
  338. // Interceptors returns the client interceptors.
  339. func (c *ContactClient) Interceptors() []Interceptor {
  340. inters := c.inters.Contact
  341. return append(inters[:len(inters):len(inters)], contact.Interceptors[:]...)
  342. }
  343. func (c *ContactClient) mutate(ctx context.Context, m *ContactMutation) (Value, error) {
  344. switch m.Op() {
  345. case OpCreate:
  346. return (&ContactCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  347. case OpUpdate:
  348. return (&ContactUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  349. case OpUpdateOne:
  350. return (&ContactUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  351. case OpDelete, OpDeleteOne:
  352. return (&ContactDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  353. default:
  354. return nil, fmt.Errorf("ent: unknown Contact mutation op: %q", m.Op())
  355. }
  356. }
  357. // LabelClient is a client for the Label schema.
  358. type LabelClient struct {
  359. config
  360. }
  361. // NewLabelClient returns a client for the Label from the given config.
  362. func NewLabelClient(c config) *LabelClient {
  363. return &LabelClient{config: c}
  364. }
  365. // Use adds a list of mutation hooks to the hooks stack.
  366. // A call to `Use(f, g, h)` equals to `label.Hooks(f(g(h())))`.
  367. func (c *LabelClient) Use(hooks ...Hook) {
  368. c.hooks.Label = append(c.hooks.Label, hooks...)
  369. }
  370. // Intercept adds a list of query interceptors to the interceptors stack.
  371. // A call to `Intercept(f, g, h)` equals to `label.Intercept(f(g(h())))`.
  372. func (c *LabelClient) Intercept(interceptors ...Interceptor) {
  373. c.inters.Label = append(c.inters.Label, interceptors...)
  374. }
  375. // Create returns a builder for creating a Label entity.
  376. func (c *LabelClient) Create() *LabelCreate {
  377. mutation := newLabelMutation(c.config, OpCreate)
  378. return &LabelCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  379. }
  380. // CreateBulk returns a builder for creating a bulk of Label entities.
  381. func (c *LabelClient) CreateBulk(builders ...*LabelCreate) *LabelCreateBulk {
  382. return &LabelCreateBulk{config: c.config, builders: builders}
  383. }
  384. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  385. // a builder and applies setFunc on it.
  386. func (c *LabelClient) MapCreateBulk(slice any, setFunc func(*LabelCreate, int)) *LabelCreateBulk {
  387. rv := reflect.ValueOf(slice)
  388. if rv.Kind() != reflect.Slice {
  389. return &LabelCreateBulk{err: fmt.Errorf("calling to LabelClient.MapCreateBulk with wrong type %T, need slice", slice)}
  390. }
  391. builders := make([]*LabelCreate, rv.Len())
  392. for i := 0; i < rv.Len(); i++ {
  393. builders[i] = c.Create()
  394. setFunc(builders[i], i)
  395. }
  396. return &LabelCreateBulk{config: c.config, builders: builders}
  397. }
  398. // Update returns an update builder for Label.
  399. func (c *LabelClient) Update() *LabelUpdate {
  400. mutation := newLabelMutation(c.config, OpUpdate)
  401. return &LabelUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  402. }
  403. // UpdateOne returns an update builder for the given entity.
  404. func (c *LabelClient) UpdateOne(l *Label) *LabelUpdateOne {
  405. mutation := newLabelMutation(c.config, OpUpdateOne, withLabel(l))
  406. return &LabelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  407. }
  408. // UpdateOneID returns an update builder for the given id.
  409. func (c *LabelClient) UpdateOneID(id uint64) *LabelUpdateOne {
  410. mutation := newLabelMutation(c.config, OpUpdateOne, withLabelID(id))
  411. return &LabelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  412. }
  413. // Delete returns a delete builder for Label.
  414. func (c *LabelClient) Delete() *LabelDelete {
  415. mutation := newLabelMutation(c.config, OpDelete)
  416. return &LabelDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  417. }
  418. // DeleteOne returns a builder for deleting the given entity.
  419. func (c *LabelClient) DeleteOne(l *Label) *LabelDeleteOne {
  420. return c.DeleteOneID(l.ID)
  421. }
  422. // DeleteOneID returns a builder for deleting the given entity by its id.
  423. func (c *LabelClient) DeleteOneID(id uint64) *LabelDeleteOne {
  424. builder := c.Delete().Where(label.ID(id))
  425. builder.mutation.id = &id
  426. builder.mutation.op = OpDeleteOne
  427. return &LabelDeleteOne{builder}
  428. }
  429. // Query returns a query builder for Label.
  430. func (c *LabelClient) Query() *LabelQuery {
  431. return &LabelQuery{
  432. config: c.config,
  433. ctx: &QueryContext{Type: TypeLabel},
  434. inters: c.Interceptors(),
  435. }
  436. }
  437. // Get returns a Label entity by its id.
  438. func (c *LabelClient) Get(ctx context.Context, id uint64) (*Label, error) {
  439. return c.Query().Where(label.ID(id)).Only(ctx)
  440. }
  441. // GetX is like Get, but panics if an error occurs.
  442. func (c *LabelClient) GetX(ctx context.Context, id uint64) *Label {
  443. obj, err := c.Get(ctx, id)
  444. if err != nil {
  445. panic(err)
  446. }
  447. return obj
  448. }
  449. // QueryLabelRelationships queries the label_relationships edge of a Label.
  450. func (c *LabelClient) QueryLabelRelationships(l *Label) *LabelRelationshipQuery {
  451. query := (&LabelRelationshipClient{config: c.config}).Query()
  452. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  453. id := l.ID
  454. step := sqlgraph.NewStep(
  455. sqlgraph.From(label.Table, label.FieldID, id),
  456. sqlgraph.To(labelrelationship.Table, labelrelationship.FieldID),
  457. sqlgraph.Edge(sqlgraph.O2M, false, label.LabelRelationshipsTable, label.LabelRelationshipsColumn),
  458. )
  459. fromV = sqlgraph.Neighbors(l.driver.Dialect(), step)
  460. return fromV, nil
  461. }
  462. return query
  463. }
  464. // Hooks returns the client hooks.
  465. func (c *LabelClient) Hooks() []Hook {
  466. hooks := c.hooks.Label
  467. return append(hooks[:len(hooks):len(hooks)], label.Hooks[:]...)
  468. }
  469. // Interceptors returns the client interceptors.
  470. func (c *LabelClient) Interceptors() []Interceptor {
  471. inters := c.inters.Label
  472. return append(inters[:len(inters):len(inters)], label.Interceptors[:]...)
  473. }
  474. func (c *LabelClient) mutate(ctx context.Context, m *LabelMutation) (Value, error) {
  475. switch m.Op() {
  476. case OpCreate:
  477. return (&LabelCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  478. case OpUpdate:
  479. return (&LabelUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  480. case OpUpdateOne:
  481. return (&LabelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  482. case OpDelete, OpDeleteOne:
  483. return (&LabelDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  484. default:
  485. return nil, fmt.Errorf("ent: unknown Label mutation op: %q", m.Op())
  486. }
  487. }
  488. // LabelRelationshipClient is a client for the LabelRelationship schema.
  489. type LabelRelationshipClient struct {
  490. config
  491. }
  492. // NewLabelRelationshipClient returns a client for the LabelRelationship from the given config.
  493. func NewLabelRelationshipClient(c config) *LabelRelationshipClient {
  494. return &LabelRelationshipClient{config: c}
  495. }
  496. // Use adds a list of mutation hooks to the hooks stack.
  497. // A call to `Use(f, g, h)` equals to `labelrelationship.Hooks(f(g(h())))`.
  498. func (c *LabelRelationshipClient) Use(hooks ...Hook) {
  499. c.hooks.LabelRelationship = append(c.hooks.LabelRelationship, hooks...)
  500. }
  501. // Intercept adds a list of query interceptors to the interceptors stack.
  502. // A call to `Intercept(f, g, h)` equals to `labelrelationship.Intercept(f(g(h())))`.
  503. func (c *LabelRelationshipClient) Intercept(interceptors ...Interceptor) {
  504. c.inters.LabelRelationship = append(c.inters.LabelRelationship, interceptors...)
  505. }
  506. // Create returns a builder for creating a LabelRelationship entity.
  507. func (c *LabelRelationshipClient) Create() *LabelRelationshipCreate {
  508. mutation := newLabelRelationshipMutation(c.config, OpCreate)
  509. return &LabelRelationshipCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  510. }
  511. // CreateBulk returns a builder for creating a bulk of LabelRelationship entities.
  512. func (c *LabelRelationshipClient) CreateBulk(builders ...*LabelRelationshipCreate) *LabelRelationshipCreateBulk {
  513. return &LabelRelationshipCreateBulk{config: c.config, builders: builders}
  514. }
  515. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  516. // a builder and applies setFunc on it.
  517. func (c *LabelRelationshipClient) MapCreateBulk(slice any, setFunc func(*LabelRelationshipCreate, int)) *LabelRelationshipCreateBulk {
  518. rv := reflect.ValueOf(slice)
  519. if rv.Kind() != reflect.Slice {
  520. return &LabelRelationshipCreateBulk{err: fmt.Errorf("calling to LabelRelationshipClient.MapCreateBulk with wrong type %T, need slice", slice)}
  521. }
  522. builders := make([]*LabelRelationshipCreate, rv.Len())
  523. for i := 0; i < rv.Len(); i++ {
  524. builders[i] = c.Create()
  525. setFunc(builders[i], i)
  526. }
  527. return &LabelRelationshipCreateBulk{config: c.config, builders: builders}
  528. }
  529. // Update returns an update builder for LabelRelationship.
  530. func (c *LabelRelationshipClient) Update() *LabelRelationshipUpdate {
  531. mutation := newLabelRelationshipMutation(c.config, OpUpdate)
  532. return &LabelRelationshipUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  533. }
  534. // UpdateOne returns an update builder for the given entity.
  535. func (c *LabelRelationshipClient) UpdateOne(lr *LabelRelationship) *LabelRelationshipUpdateOne {
  536. mutation := newLabelRelationshipMutation(c.config, OpUpdateOne, withLabelRelationship(lr))
  537. return &LabelRelationshipUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  538. }
  539. // UpdateOneID returns an update builder for the given id.
  540. func (c *LabelRelationshipClient) UpdateOneID(id uint64) *LabelRelationshipUpdateOne {
  541. mutation := newLabelRelationshipMutation(c.config, OpUpdateOne, withLabelRelationshipID(id))
  542. return &LabelRelationshipUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  543. }
  544. // Delete returns a delete builder for LabelRelationship.
  545. func (c *LabelRelationshipClient) Delete() *LabelRelationshipDelete {
  546. mutation := newLabelRelationshipMutation(c.config, OpDelete)
  547. return &LabelRelationshipDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  548. }
  549. // DeleteOne returns a builder for deleting the given entity.
  550. func (c *LabelRelationshipClient) DeleteOne(lr *LabelRelationship) *LabelRelationshipDeleteOne {
  551. return c.DeleteOneID(lr.ID)
  552. }
  553. // DeleteOneID returns a builder for deleting the given entity by its id.
  554. func (c *LabelRelationshipClient) DeleteOneID(id uint64) *LabelRelationshipDeleteOne {
  555. builder := c.Delete().Where(labelrelationship.ID(id))
  556. builder.mutation.id = &id
  557. builder.mutation.op = OpDeleteOne
  558. return &LabelRelationshipDeleteOne{builder}
  559. }
  560. // Query returns a query builder for LabelRelationship.
  561. func (c *LabelRelationshipClient) Query() *LabelRelationshipQuery {
  562. return &LabelRelationshipQuery{
  563. config: c.config,
  564. ctx: &QueryContext{Type: TypeLabelRelationship},
  565. inters: c.Interceptors(),
  566. }
  567. }
  568. // Get returns a LabelRelationship entity by its id.
  569. func (c *LabelRelationshipClient) Get(ctx context.Context, id uint64) (*LabelRelationship, error) {
  570. return c.Query().Where(labelrelationship.ID(id)).Only(ctx)
  571. }
  572. // GetX is like Get, but panics if an error occurs.
  573. func (c *LabelRelationshipClient) GetX(ctx context.Context, id uint64) *LabelRelationship {
  574. obj, err := c.Get(ctx, id)
  575. if err != nil {
  576. panic(err)
  577. }
  578. return obj
  579. }
  580. // QueryContacts queries the contacts edge of a LabelRelationship.
  581. func (c *LabelRelationshipClient) QueryContacts(lr *LabelRelationship) *ContactQuery {
  582. query := (&ContactClient{config: c.config}).Query()
  583. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  584. id := lr.ID
  585. step := sqlgraph.NewStep(
  586. sqlgraph.From(labelrelationship.Table, labelrelationship.FieldID, id),
  587. sqlgraph.To(contact.Table, contact.FieldID),
  588. sqlgraph.Edge(sqlgraph.M2O, true, labelrelationship.ContactsTable, labelrelationship.ContactsColumn),
  589. )
  590. fromV = sqlgraph.Neighbors(lr.driver.Dialect(), step)
  591. return fromV, nil
  592. }
  593. return query
  594. }
  595. // QueryLabels queries the labels edge of a LabelRelationship.
  596. func (c *LabelRelationshipClient) QueryLabels(lr *LabelRelationship) *LabelQuery {
  597. query := (&LabelClient{config: c.config}).Query()
  598. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  599. id := lr.ID
  600. step := sqlgraph.NewStep(
  601. sqlgraph.From(labelrelationship.Table, labelrelationship.FieldID, id),
  602. sqlgraph.To(label.Table, label.FieldID),
  603. sqlgraph.Edge(sqlgraph.M2O, true, labelrelationship.LabelsTable, labelrelationship.LabelsColumn),
  604. )
  605. fromV = sqlgraph.Neighbors(lr.driver.Dialect(), step)
  606. return fromV, nil
  607. }
  608. return query
  609. }
  610. // Hooks returns the client hooks.
  611. func (c *LabelRelationshipClient) Hooks() []Hook {
  612. hooks := c.hooks.LabelRelationship
  613. return append(hooks[:len(hooks):len(hooks)], labelrelationship.Hooks[:]...)
  614. }
  615. // Interceptors returns the client interceptors.
  616. func (c *LabelRelationshipClient) Interceptors() []Interceptor {
  617. inters := c.inters.LabelRelationship
  618. return append(inters[:len(inters):len(inters)], labelrelationship.Interceptors[:]...)
  619. }
  620. func (c *LabelRelationshipClient) mutate(ctx context.Context, m *LabelRelationshipMutation) (Value, error) {
  621. switch m.Op() {
  622. case OpCreate:
  623. return (&LabelRelationshipCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  624. case OpUpdate:
  625. return (&LabelRelationshipUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  626. case OpUpdateOne:
  627. return (&LabelRelationshipUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  628. case OpDelete, OpDeleteOne:
  629. return (&LabelRelationshipDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  630. default:
  631. return nil, fmt.Errorf("ent: unknown LabelRelationship mutation op: %q", m.Op())
  632. }
  633. }
  634. // MessageClient is a client for the Message schema.
  635. type MessageClient struct {
  636. config
  637. }
  638. // NewMessageClient returns a client for the Message from the given config.
  639. func NewMessageClient(c config) *MessageClient {
  640. return &MessageClient{config: c}
  641. }
  642. // Use adds a list of mutation hooks to the hooks stack.
  643. // A call to `Use(f, g, h)` equals to `message.Hooks(f(g(h())))`.
  644. func (c *MessageClient) Use(hooks ...Hook) {
  645. c.hooks.Message = append(c.hooks.Message, hooks...)
  646. }
  647. // Intercept adds a list of query interceptors to the interceptors stack.
  648. // A call to `Intercept(f, g, h)` equals to `message.Intercept(f(g(h())))`.
  649. func (c *MessageClient) Intercept(interceptors ...Interceptor) {
  650. c.inters.Message = append(c.inters.Message, interceptors...)
  651. }
  652. // Create returns a builder for creating a Message entity.
  653. func (c *MessageClient) Create() *MessageCreate {
  654. mutation := newMessageMutation(c.config, OpCreate)
  655. return &MessageCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  656. }
  657. // CreateBulk returns a builder for creating a bulk of Message entities.
  658. func (c *MessageClient) CreateBulk(builders ...*MessageCreate) *MessageCreateBulk {
  659. return &MessageCreateBulk{config: c.config, builders: builders}
  660. }
  661. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  662. // a builder and applies setFunc on it.
  663. func (c *MessageClient) MapCreateBulk(slice any, setFunc func(*MessageCreate, int)) *MessageCreateBulk {
  664. rv := reflect.ValueOf(slice)
  665. if rv.Kind() != reflect.Slice {
  666. return &MessageCreateBulk{err: fmt.Errorf("calling to MessageClient.MapCreateBulk with wrong type %T, need slice", slice)}
  667. }
  668. builders := make([]*MessageCreate, rv.Len())
  669. for i := 0; i < rv.Len(); i++ {
  670. builders[i] = c.Create()
  671. setFunc(builders[i], i)
  672. }
  673. return &MessageCreateBulk{config: c.config, builders: builders}
  674. }
  675. // Update returns an update builder for Message.
  676. func (c *MessageClient) Update() *MessageUpdate {
  677. mutation := newMessageMutation(c.config, OpUpdate)
  678. return &MessageUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  679. }
  680. // UpdateOne returns an update builder for the given entity.
  681. func (c *MessageClient) UpdateOne(m *Message) *MessageUpdateOne {
  682. mutation := newMessageMutation(c.config, OpUpdateOne, withMessage(m))
  683. return &MessageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  684. }
  685. // UpdateOneID returns an update builder for the given id.
  686. func (c *MessageClient) UpdateOneID(id int) *MessageUpdateOne {
  687. mutation := newMessageMutation(c.config, OpUpdateOne, withMessageID(id))
  688. return &MessageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  689. }
  690. // Delete returns a delete builder for Message.
  691. func (c *MessageClient) Delete() *MessageDelete {
  692. mutation := newMessageMutation(c.config, OpDelete)
  693. return &MessageDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  694. }
  695. // DeleteOne returns a builder for deleting the given entity.
  696. func (c *MessageClient) DeleteOne(m *Message) *MessageDeleteOne {
  697. return c.DeleteOneID(m.ID)
  698. }
  699. // DeleteOneID returns a builder for deleting the given entity by its id.
  700. func (c *MessageClient) DeleteOneID(id int) *MessageDeleteOne {
  701. builder := c.Delete().Where(message.ID(id))
  702. builder.mutation.id = &id
  703. builder.mutation.op = OpDeleteOne
  704. return &MessageDeleteOne{builder}
  705. }
  706. // Query returns a query builder for Message.
  707. func (c *MessageClient) Query() *MessageQuery {
  708. return &MessageQuery{
  709. config: c.config,
  710. ctx: &QueryContext{Type: TypeMessage},
  711. inters: c.Interceptors(),
  712. }
  713. }
  714. // Get returns a Message entity by its id.
  715. func (c *MessageClient) Get(ctx context.Context, id int) (*Message, error) {
  716. return c.Query().Where(message.ID(id)).Only(ctx)
  717. }
  718. // GetX is like Get, but panics if an error occurs.
  719. func (c *MessageClient) GetX(ctx context.Context, id int) *Message {
  720. obj, err := c.Get(ctx, id)
  721. if err != nil {
  722. panic(err)
  723. }
  724. return obj
  725. }
  726. // Hooks returns the client hooks.
  727. func (c *MessageClient) Hooks() []Hook {
  728. return c.hooks.Message
  729. }
  730. // Interceptors returns the client interceptors.
  731. func (c *MessageClient) Interceptors() []Interceptor {
  732. return c.inters.Message
  733. }
  734. func (c *MessageClient) mutate(ctx context.Context, m *MessageMutation) (Value, error) {
  735. switch m.Op() {
  736. case OpCreate:
  737. return (&MessageCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  738. case OpUpdate:
  739. return (&MessageUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  740. case OpUpdateOne:
  741. return (&MessageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  742. case OpDelete, OpDeleteOne:
  743. return (&MessageDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  744. default:
  745. return nil, fmt.Errorf("ent: unknown Message mutation op: %q", m.Op())
  746. }
  747. }
  748. // ServerClient is a client for the Server schema.
  749. type ServerClient struct {
  750. config
  751. }
  752. // NewServerClient returns a client for the Server from the given config.
  753. func NewServerClient(c config) *ServerClient {
  754. return &ServerClient{config: c}
  755. }
  756. // Use adds a list of mutation hooks to the hooks stack.
  757. // A call to `Use(f, g, h)` equals to `server.Hooks(f(g(h())))`.
  758. func (c *ServerClient) Use(hooks ...Hook) {
  759. c.hooks.Server = append(c.hooks.Server, hooks...)
  760. }
  761. // Intercept adds a list of query interceptors to the interceptors stack.
  762. // A call to `Intercept(f, g, h)` equals to `server.Intercept(f(g(h())))`.
  763. func (c *ServerClient) Intercept(interceptors ...Interceptor) {
  764. c.inters.Server = append(c.inters.Server, interceptors...)
  765. }
  766. // Create returns a builder for creating a Server entity.
  767. func (c *ServerClient) Create() *ServerCreate {
  768. mutation := newServerMutation(c.config, OpCreate)
  769. return &ServerCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  770. }
  771. // CreateBulk returns a builder for creating a bulk of Server entities.
  772. func (c *ServerClient) CreateBulk(builders ...*ServerCreate) *ServerCreateBulk {
  773. return &ServerCreateBulk{config: c.config, builders: builders}
  774. }
  775. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  776. // a builder and applies setFunc on it.
  777. func (c *ServerClient) MapCreateBulk(slice any, setFunc func(*ServerCreate, int)) *ServerCreateBulk {
  778. rv := reflect.ValueOf(slice)
  779. if rv.Kind() != reflect.Slice {
  780. return &ServerCreateBulk{err: fmt.Errorf("calling to ServerClient.MapCreateBulk with wrong type %T, need slice", slice)}
  781. }
  782. builders := make([]*ServerCreate, rv.Len())
  783. for i := 0; i < rv.Len(); i++ {
  784. builders[i] = c.Create()
  785. setFunc(builders[i], i)
  786. }
  787. return &ServerCreateBulk{config: c.config, builders: builders}
  788. }
  789. // Update returns an update builder for Server.
  790. func (c *ServerClient) Update() *ServerUpdate {
  791. mutation := newServerMutation(c.config, OpUpdate)
  792. return &ServerUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  793. }
  794. // UpdateOne returns an update builder for the given entity.
  795. func (c *ServerClient) UpdateOne(s *Server) *ServerUpdateOne {
  796. mutation := newServerMutation(c.config, OpUpdateOne, withServer(s))
  797. return &ServerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  798. }
  799. // UpdateOneID returns an update builder for the given id.
  800. func (c *ServerClient) UpdateOneID(id uint64) *ServerUpdateOne {
  801. mutation := newServerMutation(c.config, OpUpdateOne, withServerID(id))
  802. return &ServerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  803. }
  804. // Delete returns a delete builder for Server.
  805. func (c *ServerClient) Delete() *ServerDelete {
  806. mutation := newServerMutation(c.config, OpDelete)
  807. return &ServerDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  808. }
  809. // DeleteOne returns a builder for deleting the given entity.
  810. func (c *ServerClient) DeleteOne(s *Server) *ServerDeleteOne {
  811. return c.DeleteOneID(s.ID)
  812. }
  813. // DeleteOneID returns a builder for deleting the given entity by its id.
  814. func (c *ServerClient) DeleteOneID(id uint64) *ServerDeleteOne {
  815. builder := c.Delete().Where(server.ID(id))
  816. builder.mutation.id = &id
  817. builder.mutation.op = OpDeleteOne
  818. return &ServerDeleteOne{builder}
  819. }
  820. // Query returns a query builder for Server.
  821. func (c *ServerClient) Query() *ServerQuery {
  822. return &ServerQuery{
  823. config: c.config,
  824. ctx: &QueryContext{Type: TypeServer},
  825. inters: c.Interceptors(),
  826. }
  827. }
  828. // Get returns a Server entity by its id.
  829. func (c *ServerClient) Get(ctx context.Context, id uint64) (*Server, error) {
  830. return c.Query().Where(server.ID(id)).Only(ctx)
  831. }
  832. // GetX is like Get, but panics if an error occurs.
  833. func (c *ServerClient) GetX(ctx context.Context, id uint64) *Server {
  834. obj, err := c.Get(ctx, id)
  835. if err != nil {
  836. panic(err)
  837. }
  838. return obj
  839. }
  840. // QueryWxs queries the wxs edge of a Server.
  841. func (c *ServerClient) QueryWxs(s *Server) *WxQuery {
  842. query := (&WxClient{config: c.config}).Query()
  843. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  844. id := s.ID
  845. step := sqlgraph.NewStep(
  846. sqlgraph.From(server.Table, server.FieldID, id),
  847. sqlgraph.To(wx.Table, wx.FieldID),
  848. sqlgraph.Edge(sqlgraph.O2M, false, server.WxsTable, server.WxsColumn),
  849. )
  850. fromV = sqlgraph.Neighbors(s.driver.Dialect(), step)
  851. return fromV, nil
  852. }
  853. return query
  854. }
  855. // Hooks returns the client hooks.
  856. func (c *ServerClient) Hooks() []Hook {
  857. hooks := c.hooks.Server
  858. return append(hooks[:len(hooks):len(hooks)], server.Hooks[:]...)
  859. }
  860. // Interceptors returns the client interceptors.
  861. func (c *ServerClient) Interceptors() []Interceptor {
  862. inters := c.inters.Server
  863. return append(inters[:len(inters):len(inters)], server.Interceptors[:]...)
  864. }
  865. func (c *ServerClient) mutate(ctx context.Context, m *ServerMutation) (Value, error) {
  866. switch m.Op() {
  867. case OpCreate:
  868. return (&ServerCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  869. case OpUpdate:
  870. return (&ServerUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  871. case OpUpdateOne:
  872. return (&ServerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  873. case OpDelete, OpDeleteOne:
  874. return (&ServerDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  875. default:
  876. return nil, fmt.Errorf("ent: unknown Server mutation op: %q", m.Op())
  877. }
  878. }
  879. // WxClient is a client for the Wx schema.
  880. type WxClient struct {
  881. config
  882. }
  883. // NewWxClient returns a client for the Wx from the given config.
  884. func NewWxClient(c config) *WxClient {
  885. return &WxClient{config: c}
  886. }
  887. // Use adds a list of mutation hooks to the hooks stack.
  888. // A call to `Use(f, g, h)` equals to `wx.Hooks(f(g(h())))`.
  889. func (c *WxClient) Use(hooks ...Hook) {
  890. c.hooks.Wx = append(c.hooks.Wx, hooks...)
  891. }
  892. // Intercept adds a list of query interceptors to the interceptors stack.
  893. // A call to `Intercept(f, g, h)` equals to `wx.Intercept(f(g(h())))`.
  894. func (c *WxClient) Intercept(interceptors ...Interceptor) {
  895. c.inters.Wx = append(c.inters.Wx, interceptors...)
  896. }
  897. // Create returns a builder for creating a Wx entity.
  898. func (c *WxClient) Create() *WxCreate {
  899. mutation := newWxMutation(c.config, OpCreate)
  900. return &WxCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  901. }
  902. // CreateBulk returns a builder for creating a bulk of Wx entities.
  903. func (c *WxClient) CreateBulk(builders ...*WxCreate) *WxCreateBulk {
  904. return &WxCreateBulk{config: c.config, builders: builders}
  905. }
  906. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  907. // a builder and applies setFunc on it.
  908. func (c *WxClient) MapCreateBulk(slice any, setFunc func(*WxCreate, int)) *WxCreateBulk {
  909. rv := reflect.ValueOf(slice)
  910. if rv.Kind() != reflect.Slice {
  911. return &WxCreateBulk{err: fmt.Errorf("calling to WxClient.MapCreateBulk with wrong type %T, need slice", slice)}
  912. }
  913. builders := make([]*WxCreate, rv.Len())
  914. for i := 0; i < rv.Len(); i++ {
  915. builders[i] = c.Create()
  916. setFunc(builders[i], i)
  917. }
  918. return &WxCreateBulk{config: c.config, builders: builders}
  919. }
  920. // Update returns an update builder for Wx.
  921. func (c *WxClient) Update() *WxUpdate {
  922. mutation := newWxMutation(c.config, OpUpdate)
  923. return &WxUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  924. }
  925. // UpdateOne returns an update builder for the given entity.
  926. func (c *WxClient) UpdateOne(w *Wx) *WxUpdateOne {
  927. mutation := newWxMutation(c.config, OpUpdateOne, withWx(w))
  928. return &WxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  929. }
  930. // UpdateOneID returns an update builder for the given id.
  931. func (c *WxClient) UpdateOneID(id uint64) *WxUpdateOne {
  932. mutation := newWxMutation(c.config, OpUpdateOne, withWxID(id))
  933. return &WxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  934. }
  935. // Delete returns a delete builder for Wx.
  936. func (c *WxClient) Delete() *WxDelete {
  937. mutation := newWxMutation(c.config, OpDelete)
  938. return &WxDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  939. }
  940. // DeleteOne returns a builder for deleting the given entity.
  941. func (c *WxClient) DeleteOne(w *Wx) *WxDeleteOne {
  942. return c.DeleteOneID(w.ID)
  943. }
  944. // DeleteOneID returns a builder for deleting the given entity by its id.
  945. func (c *WxClient) DeleteOneID(id uint64) *WxDeleteOne {
  946. builder := c.Delete().Where(wx.ID(id))
  947. builder.mutation.id = &id
  948. builder.mutation.op = OpDeleteOne
  949. return &WxDeleteOne{builder}
  950. }
  951. // Query returns a query builder for Wx.
  952. func (c *WxClient) Query() *WxQuery {
  953. return &WxQuery{
  954. config: c.config,
  955. ctx: &QueryContext{Type: TypeWx},
  956. inters: c.Interceptors(),
  957. }
  958. }
  959. // Get returns a Wx entity by its id.
  960. func (c *WxClient) Get(ctx context.Context, id uint64) (*Wx, error) {
  961. return c.Query().Where(wx.ID(id)).Only(ctx)
  962. }
  963. // GetX is like Get, but panics if an error occurs.
  964. func (c *WxClient) GetX(ctx context.Context, id uint64) *Wx {
  965. obj, err := c.Get(ctx, id)
  966. if err != nil {
  967. panic(err)
  968. }
  969. return obj
  970. }
  971. // QueryServer queries the server edge of a Wx.
  972. func (c *WxClient) QueryServer(w *Wx) *ServerQuery {
  973. query := (&ServerClient{config: c.config}).Query()
  974. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  975. id := w.ID
  976. step := sqlgraph.NewStep(
  977. sqlgraph.From(wx.Table, wx.FieldID, id),
  978. sqlgraph.To(server.Table, server.FieldID),
  979. sqlgraph.Edge(sqlgraph.M2O, true, wx.ServerTable, wx.ServerColumn),
  980. )
  981. fromV = sqlgraph.Neighbors(w.driver.Dialect(), step)
  982. return fromV, nil
  983. }
  984. return query
  985. }
  986. // Hooks returns the client hooks.
  987. func (c *WxClient) Hooks() []Hook {
  988. hooks := c.hooks.Wx
  989. return append(hooks[:len(hooks):len(hooks)], wx.Hooks[:]...)
  990. }
  991. // Interceptors returns the client interceptors.
  992. func (c *WxClient) Interceptors() []Interceptor {
  993. inters := c.inters.Wx
  994. return append(inters[:len(inters):len(inters)], wx.Interceptors[:]...)
  995. }
  996. func (c *WxClient) mutate(ctx context.Context, m *WxMutation) (Value, error) {
  997. switch m.Op() {
  998. case OpCreate:
  999. return (&WxCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1000. case OpUpdate:
  1001. return (&WxUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1002. case OpUpdateOne:
  1003. return (&WxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1004. case OpDelete, OpDeleteOne:
  1005. return (&WxDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1006. default:
  1007. return nil, fmt.Errorf("ent: unknown Wx mutation op: %q", m.Op())
  1008. }
  1009. }
  1010. // hooks and interceptors per client, for fast access.
  1011. type (
  1012. hooks struct {
  1013. Contact, Label, LabelRelationship, Message, Server, Wx []ent.Hook
  1014. }
  1015. inters struct {
  1016. Contact, Label, LabelRelationship, Message, Server, Wx []ent.Interceptor
  1017. }
  1018. )
  1019. // ExecContext allows calling the underlying ExecContext method of the driver if it is supported by it.
  1020. // See, database/sql#DB.ExecContext for more information.
  1021. func (c *config) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) {
  1022. ex, ok := c.driver.(interface {
  1023. ExecContext(context.Context, string, ...any) (stdsql.Result, error)
  1024. })
  1025. if !ok {
  1026. return nil, fmt.Errorf("Driver.ExecContext is not supported")
  1027. }
  1028. return ex.ExecContext(ctx, query, args...)
  1029. }
  1030. // QueryContext allows calling the underlying QueryContext method of the driver if it is supported by it.
  1031. // See, database/sql#DB.QueryContext for more information.
  1032. func (c *config) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) {
  1033. q, ok := c.driver.(interface {
  1034. QueryContext(context.Context, string, ...any) (*stdsql.Rows, error)
  1035. })
  1036. if !ok {
  1037. return nil, fmt.Errorf("Driver.QueryContext is not supported")
  1038. }
  1039. return q.QueryContext(ctx, query, args...)
  1040. }