client.go 119 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308
  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/agent"
  11. "wechat-api/ent/batchmsg"
  12. "wechat-api/ent/category"
  13. "wechat-api/ent/contact"
  14. "wechat-api/ent/employee"
  15. "wechat-api/ent/employeeconfig"
  16. "wechat-api/ent/label"
  17. "wechat-api/ent/labelrelationship"
  18. "wechat-api/ent/message"
  19. "wechat-api/ent/messagerecords"
  20. "wechat-api/ent/msg"
  21. "wechat-api/ent/server"
  22. "wechat-api/ent/sopnode"
  23. "wechat-api/ent/sopstage"
  24. "wechat-api/ent/soptask"
  25. "wechat-api/ent/token"
  26. "wechat-api/ent/tutorial"
  27. "wechat-api/ent/workexperience"
  28. "wechat-api/ent/wx"
  29. "entgo.io/ent"
  30. "entgo.io/ent/dialect"
  31. "entgo.io/ent/dialect/sql"
  32. "entgo.io/ent/dialect/sql/sqlgraph"
  33. stdsql "database/sql"
  34. )
  35. // Client is the client that holds all ent builders.
  36. type Client struct {
  37. config
  38. // Schema is the client for creating, migrating and dropping schema.
  39. Schema *migrate.Schema
  40. // Agent is the client for interacting with the Agent builders.
  41. Agent *AgentClient
  42. // BatchMsg is the client for interacting with the BatchMsg builders.
  43. BatchMsg *BatchMsgClient
  44. // Category is the client for interacting with the Category builders.
  45. Category *CategoryClient
  46. // Contact is the client for interacting with the Contact builders.
  47. Contact *ContactClient
  48. // Employee is the client for interacting with the Employee builders.
  49. Employee *EmployeeClient
  50. // EmployeeConfig is the client for interacting with the EmployeeConfig builders.
  51. EmployeeConfig *EmployeeConfigClient
  52. // Label is the client for interacting with the Label builders.
  53. Label *LabelClient
  54. // LabelRelationship is the client for interacting with the LabelRelationship builders.
  55. LabelRelationship *LabelRelationshipClient
  56. // Message is the client for interacting with the Message builders.
  57. Message *MessageClient
  58. // MessageRecords is the client for interacting with the MessageRecords builders.
  59. MessageRecords *MessageRecordsClient
  60. // Msg is the client for interacting with the Msg builders.
  61. Msg *MsgClient
  62. // Server is the client for interacting with the Server builders.
  63. Server *ServerClient
  64. // SopNode is the client for interacting with the SopNode builders.
  65. SopNode *SopNodeClient
  66. // SopStage is the client for interacting with the SopStage builders.
  67. SopStage *SopStageClient
  68. // SopTask is the client for interacting with the SopTask builders.
  69. SopTask *SopTaskClient
  70. // Token is the client for interacting with the Token builders.
  71. Token *TokenClient
  72. // Tutorial is the client for interacting with the Tutorial builders.
  73. Tutorial *TutorialClient
  74. // WorkExperience is the client for interacting with the WorkExperience builders.
  75. WorkExperience *WorkExperienceClient
  76. // Wx is the client for interacting with the Wx builders.
  77. Wx *WxClient
  78. }
  79. // NewClient creates a new client configured with the given options.
  80. func NewClient(opts ...Option) *Client {
  81. client := &Client{config: newConfig(opts...)}
  82. client.init()
  83. return client
  84. }
  85. func (c *Client) init() {
  86. c.Schema = migrate.NewSchema(c.driver)
  87. c.Agent = NewAgentClient(c.config)
  88. c.BatchMsg = NewBatchMsgClient(c.config)
  89. c.Category = NewCategoryClient(c.config)
  90. c.Contact = NewContactClient(c.config)
  91. c.Employee = NewEmployeeClient(c.config)
  92. c.EmployeeConfig = NewEmployeeConfigClient(c.config)
  93. c.Label = NewLabelClient(c.config)
  94. c.LabelRelationship = NewLabelRelationshipClient(c.config)
  95. c.Message = NewMessageClient(c.config)
  96. c.MessageRecords = NewMessageRecordsClient(c.config)
  97. c.Msg = NewMsgClient(c.config)
  98. c.Server = NewServerClient(c.config)
  99. c.SopNode = NewSopNodeClient(c.config)
  100. c.SopStage = NewSopStageClient(c.config)
  101. c.SopTask = NewSopTaskClient(c.config)
  102. c.Token = NewTokenClient(c.config)
  103. c.Tutorial = NewTutorialClient(c.config)
  104. c.WorkExperience = NewWorkExperienceClient(c.config)
  105. c.Wx = NewWxClient(c.config)
  106. }
  107. type (
  108. // config is the configuration for the client and its builder.
  109. config struct {
  110. // driver used for executing database requests.
  111. driver dialect.Driver
  112. // debug enable a debug logging.
  113. debug bool
  114. // log used for logging on debug mode.
  115. log func(...any)
  116. // hooks to execute on mutations.
  117. hooks *hooks
  118. // interceptors to execute on queries.
  119. inters *inters
  120. }
  121. // Option function to configure the client.
  122. Option func(*config)
  123. )
  124. // newConfig creates a new config for the client.
  125. func newConfig(opts ...Option) config {
  126. cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
  127. cfg.options(opts...)
  128. return cfg
  129. }
  130. // options applies the options on the config object.
  131. func (c *config) options(opts ...Option) {
  132. for _, opt := range opts {
  133. opt(c)
  134. }
  135. if c.debug {
  136. c.driver = dialect.Debug(c.driver, c.log)
  137. }
  138. }
  139. // Debug enables debug logging on the ent.Driver.
  140. func Debug() Option {
  141. return func(c *config) {
  142. c.debug = true
  143. }
  144. }
  145. // Log sets the logging function for debug mode.
  146. func Log(fn func(...any)) Option {
  147. return func(c *config) {
  148. c.log = fn
  149. }
  150. }
  151. // Driver configures the client driver.
  152. func Driver(driver dialect.Driver) Option {
  153. return func(c *config) {
  154. c.driver = driver
  155. }
  156. }
  157. // Open opens a database/sql.DB specified by the driver name and
  158. // the data source name, and returns a new client attached to it.
  159. // Optional parameters can be added for configuring the client.
  160. func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
  161. switch driverName {
  162. case dialect.MySQL, dialect.Postgres, dialect.SQLite:
  163. drv, err := sql.Open(driverName, dataSourceName)
  164. if err != nil {
  165. return nil, err
  166. }
  167. return NewClient(append(options, Driver(drv))...), nil
  168. default:
  169. return nil, fmt.Errorf("unsupported driver: %q", driverName)
  170. }
  171. }
  172. // ErrTxStarted is returned when trying to start a new transaction from a transactional client.
  173. var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction")
  174. // Tx returns a new transactional client. The provided context
  175. // is used until the transaction is committed or rolled back.
  176. func (c *Client) Tx(ctx context.Context) (*Tx, error) {
  177. if _, ok := c.driver.(*txDriver); ok {
  178. return nil, ErrTxStarted
  179. }
  180. tx, err := newTx(ctx, c.driver)
  181. if err != nil {
  182. return nil, fmt.Errorf("ent: starting a transaction: %w", err)
  183. }
  184. cfg := c.config
  185. cfg.driver = tx
  186. return &Tx{
  187. ctx: ctx,
  188. config: cfg,
  189. Agent: NewAgentClient(cfg),
  190. BatchMsg: NewBatchMsgClient(cfg),
  191. Category: NewCategoryClient(cfg),
  192. Contact: NewContactClient(cfg),
  193. Employee: NewEmployeeClient(cfg),
  194. EmployeeConfig: NewEmployeeConfigClient(cfg),
  195. Label: NewLabelClient(cfg),
  196. LabelRelationship: NewLabelRelationshipClient(cfg),
  197. Message: NewMessageClient(cfg),
  198. MessageRecords: NewMessageRecordsClient(cfg),
  199. Msg: NewMsgClient(cfg),
  200. Server: NewServerClient(cfg),
  201. SopNode: NewSopNodeClient(cfg),
  202. SopStage: NewSopStageClient(cfg),
  203. SopTask: NewSopTaskClient(cfg),
  204. Token: NewTokenClient(cfg),
  205. Tutorial: NewTutorialClient(cfg),
  206. WorkExperience: NewWorkExperienceClient(cfg),
  207. Wx: NewWxClient(cfg),
  208. }, nil
  209. }
  210. // BeginTx returns a transactional client with specified options.
  211. func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
  212. if _, ok := c.driver.(*txDriver); ok {
  213. return nil, errors.New("ent: cannot start a transaction within a transaction")
  214. }
  215. tx, err := c.driver.(interface {
  216. BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)
  217. }).BeginTx(ctx, opts)
  218. if err != nil {
  219. return nil, fmt.Errorf("ent: starting a transaction: %w", err)
  220. }
  221. cfg := c.config
  222. cfg.driver = &txDriver{tx: tx, drv: c.driver}
  223. return &Tx{
  224. ctx: ctx,
  225. config: cfg,
  226. Agent: NewAgentClient(cfg),
  227. BatchMsg: NewBatchMsgClient(cfg),
  228. Category: NewCategoryClient(cfg),
  229. Contact: NewContactClient(cfg),
  230. Employee: NewEmployeeClient(cfg),
  231. EmployeeConfig: NewEmployeeConfigClient(cfg),
  232. Label: NewLabelClient(cfg),
  233. LabelRelationship: NewLabelRelationshipClient(cfg),
  234. Message: NewMessageClient(cfg),
  235. MessageRecords: NewMessageRecordsClient(cfg),
  236. Msg: NewMsgClient(cfg),
  237. Server: NewServerClient(cfg),
  238. SopNode: NewSopNodeClient(cfg),
  239. SopStage: NewSopStageClient(cfg),
  240. SopTask: NewSopTaskClient(cfg),
  241. Token: NewTokenClient(cfg),
  242. Tutorial: NewTutorialClient(cfg),
  243. WorkExperience: NewWorkExperienceClient(cfg),
  244. Wx: NewWxClient(cfg),
  245. }, nil
  246. }
  247. // Debug returns a new debug-client. It's used to get verbose logging on specific operations.
  248. //
  249. // client.Debug().
  250. // Agent.
  251. // Query().
  252. // Count(ctx)
  253. func (c *Client) Debug() *Client {
  254. if c.debug {
  255. return c
  256. }
  257. cfg := c.config
  258. cfg.driver = dialect.Debug(c.driver, c.log)
  259. client := &Client{config: cfg}
  260. client.init()
  261. return client
  262. }
  263. // Close closes the database connection and prevents new queries from starting.
  264. func (c *Client) Close() error {
  265. return c.driver.Close()
  266. }
  267. // Use adds the mutation hooks to all the entity clients.
  268. // In order to add hooks to a specific client, call: `client.Node.Use(...)`.
  269. func (c *Client) Use(hooks ...Hook) {
  270. for _, n := range []interface{ Use(...Hook) }{
  271. c.Agent, c.BatchMsg, c.Category, c.Contact, c.Employee, c.EmployeeConfig,
  272. c.Label, c.LabelRelationship, c.Message, c.MessageRecords, c.Msg, c.Server,
  273. c.SopNode, c.SopStage, c.SopTask, c.Token, c.Tutorial, c.WorkExperience, c.Wx,
  274. } {
  275. n.Use(hooks...)
  276. }
  277. }
  278. // Intercept adds the query interceptors to all the entity clients.
  279. // In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
  280. func (c *Client) Intercept(interceptors ...Interceptor) {
  281. for _, n := range []interface{ Intercept(...Interceptor) }{
  282. c.Agent, c.BatchMsg, c.Category, c.Contact, c.Employee, c.EmployeeConfig,
  283. c.Label, c.LabelRelationship, c.Message, c.MessageRecords, c.Msg, c.Server,
  284. c.SopNode, c.SopStage, c.SopTask, c.Token, c.Tutorial, c.WorkExperience, c.Wx,
  285. } {
  286. n.Intercept(interceptors...)
  287. }
  288. }
  289. // Mutate implements the ent.Mutator interface.
  290. func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
  291. switch m := m.(type) {
  292. case *AgentMutation:
  293. return c.Agent.mutate(ctx, m)
  294. case *BatchMsgMutation:
  295. return c.BatchMsg.mutate(ctx, m)
  296. case *CategoryMutation:
  297. return c.Category.mutate(ctx, m)
  298. case *ContactMutation:
  299. return c.Contact.mutate(ctx, m)
  300. case *EmployeeMutation:
  301. return c.Employee.mutate(ctx, m)
  302. case *EmployeeConfigMutation:
  303. return c.EmployeeConfig.mutate(ctx, m)
  304. case *LabelMutation:
  305. return c.Label.mutate(ctx, m)
  306. case *LabelRelationshipMutation:
  307. return c.LabelRelationship.mutate(ctx, m)
  308. case *MessageMutation:
  309. return c.Message.mutate(ctx, m)
  310. case *MessageRecordsMutation:
  311. return c.MessageRecords.mutate(ctx, m)
  312. case *MsgMutation:
  313. return c.Msg.mutate(ctx, m)
  314. case *ServerMutation:
  315. return c.Server.mutate(ctx, m)
  316. case *SopNodeMutation:
  317. return c.SopNode.mutate(ctx, m)
  318. case *SopStageMutation:
  319. return c.SopStage.mutate(ctx, m)
  320. case *SopTaskMutation:
  321. return c.SopTask.mutate(ctx, m)
  322. case *TokenMutation:
  323. return c.Token.mutate(ctx, m)
  324. case *TutorialMutation:
  325. return c.Tutorial.mutate(ctx, m)
  326. case *WorkExperienceMutation:
  327. return c.WorkExperience.mutate(ctx, m)
  328. case *WxMutation:
  329. return c.Wx.mutate(ctx, m)
  330. default:
  331. return nil, fmt.Errorf("ent: unknown mutation type %T", m)
  332. }
  333. }
  334. // AgentClient is a client for the Agent schema.
  335. type AgentClient struct {
  336. config
  337. }
  338. // NewAgentClient returns a client for the Agent from the given config.
  339. func NewAgentClient(c config) *AgentClient {
  340. return &AgentClient{config: c}
  341. }
  342. // Use adds a list of mutation hooks to the hooks stack.
  343. // A call to `Use(f, g, h)` equals to `agent.Hooks(f(g(h())))`.
  344. func (c *AgentClient) Use(hooks ...Hook) {
  345. c.hooks.Agent = append(c.hooks.Agent, hooks...)
  346. }
  347. // Intercept adds a list of query interceptors to the interceptors stack.
  348. // A call to `Intercept(f, g, h)` equals to `agent.Intercept(f(g(h())))`.
  349. func (c *AgentClient) Intercept(interceptors ...Interceptor) {
  350. c.inters.Agent = append(c.inters.Agent, interceptors...)
  351. }
  352. // Create returns a builder for creating a Agent entity.
  353. func (c *AgentClient) Create() *AgentCreate {
  354. mutation := newAgentMutation(c.config, OpCreate)
  355. return &AgentCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  356. }
  357. // CreateBulk returns a builder for creating a bulk of Agent entities.
  358. func (c *AgentClient) CreateBulk(builders ...*AgentCreate) *AgentCreateBulk {
  359. return &AgentCreateBulk{config: c.config, builders: builders}
  360. }
  361. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  362. // a builder and applies setFunc on it.
  363. func (c *AgentClient) MapCreateBulk(slice any, setFunc func(*AgentCreate, int)) *AgentCreateBulk {
  364. rv := reflect.ValueOf(slice)
  365. if rv.Kind() != reflect.Slice {
  366. return &AgentCreateBulk{err: fmt.Errorf("calling to AgentClient.MapCreateBulk with wrong type %T, need slice", slice)}
  367. }
  368. builders := make([]*AgentCreate, rv.Len())
  369. for i := 0; i < rv.Len(); i++ {
  370. builders[i] = c.Create()
  371. setFunc(builders[i], i)
  372. }
  373. return &AgentCreateBulk{config: c.config, builders: builders}
  374. }
  375. // Update returns an update builder for Agent.
  376. func (c *AgentClient) Update() *AgentUpdate {
  377. mutation := newAgentMutation(c.config, OpUpdate)
  378. return &AgentUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  379. }
  380. // UpdateOne returns an update builder for the given entity.
  381. func (c *AgentClient) UpdateOne(a *Agent) *AgentUpdateOne {
  382. mutation := newAgentMutation(c.config, OpUpdateOne, withAgent(a))
  383. return &AgentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  384. }
  385. // UpdateOneID returns an update builder for the given id.
  386. func (c *AgentClient) UpdateOneID(id uint64) *AgentUpdateOne {
  387. mutation := newAgentMutation(c.config, OpUpdateOne, withAgentID(id))
  388. return &AgentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  389. }
  390. // Delete returns a delete builder for Agent.
  391. func (c *AgentClient) Delete() *AgentDelete {
  392. mutation := newAgentMutation(c.config, OpDelete)
  393. return &AgentDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  394. }
  395. // DeleteOne returns a builder for deleting the given entity.
  396. func (c *AgentClient) DeleteOne(a *Agent) *AgentDeleteOne {
  397. return c.DeleteOneID(a.ID)
  398. }
  399. // DeleteOneID returns a builder for deleting the given entity by its id.
  400. func (c *AgentClient) DeleteOneID(id uint64) *AgentDeleteOne {
  401. builder := c.Delete().Where(agent.ID(id))
  402. builder.mutation.id = &id
  403. builder.mutation.op = OpDeleteOne
  404. return &AgentDeleteOne{builder}
  405. }
  406. // Query returns a query builder for Agent.
  407. func (c *AgentClient) Query() *AgentQuery {
  408. return &AgentQuery{
  409. config: c.config,
  410. ctx: &QueryContext{Type: TypeAgent},
  411. inters: c.Interceptors(),
  412. }
  413. }
  414. // Get returns a Agent entity by its id.
  415. func (c *AgentClient) Get(ctx context.Context, id uint64) (*Agent, error) {
  416. return c.Query().Where(agent.ID(id)).Only(ctx)
  417. }
  418. // GetX is like Get, but panics if an error occurs.
  419. func (c *AgentClient) GetX(ctx context.Context, id uint64) *Agent {
  420. obj, err := c.Get(ctx, id)
  421. if err != nil {
  422. panic(err)
  423. }
  424. return obj
  425. }
  426. // QueryWxAgent queries the wx_agent edge of a Agent.
  427. func (c *AgentClient) QueryWxAgent(a *Agent) *WxQuery {
  428. query := (&WxClient{config: c.config}).Query()
  429. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  430. id := a.ID
  431. step := sqlgraph.NewStep(
  432. sqlgraph.From(agent.Table, agent.FieldID, id),
  433. sqlgraph.To(wx.Table, wx.FieldID),
  434. sqlgraph.Edge(sqlgraph.O2M, false, agent.WxAgentTable, agent.WxAgentColumn),
  435. )
  436. fromV = sqlgraph.Neighbors(a.driver.Dialect(), step)
  437. return fromV, nil
  438. }
  439. return query
  440. }
  441. // Hooks returns the client hooks.
  442. func (c *AgentClient) Hooks() []Hook {
  443. hooks := c.hooks.Agent
  444. return append(hooks[:len(hooks):len(hooks)], agent.Hooks[:]...)
  445. }
  446. // Interceptors returns the client interceptors.
  447. func (c *AgentClient) Interceptors() []Interceptor {
  448. inters := c.inters.Agent
  449. return append(inters[:len(inters):len(inters)], agent.Interceptors[:]...)
  450. }
  451. func (c *AgentClient) mutate(ctx context.Context, m *AgentMutation) (Value, error) {
  452. switch m.Op() {
  453. case OpCreate:
  454. return (&AgentCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  455. case OpUpdate:
  456. return (&AgentUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  457. case OpUpdateOne:
  458. return (&AgentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  459. case OpDelete, OpDeleteOne:
  460. return (&AgentDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  461. default:
  462. return nil, fmt.Errorf("ent: unknown Agent mutation op: %q", m.Op())
  463. }
  464. }
  465. // BatchMsgClient is a client for the BatchMsg schema.
  466. type BatchMsgClient struct {
  467. config
  468. }
  469. // NewBatchMsgClient returns a client for the BatchMsg from the given config.
  470. func NewBatchMsgClient(c config) *BatchMsgClient {
  471. return &BatchMsgClient{config: c}
  472. }
  473. // Use adds a list of mutation hooks to the hooks stack.
  474. // A call to `Use(f, g, h)` equals to `batchmsg.Hooks(f(g(h())))`.
  475. func (c *BatchMsgClient) Use(hooks ...Hook) {
  476. c.hooks.BatchMsg = append(c.hooks.BatchMsg, hooks...)
  477. }
  478. // Intercept adds a list of query interceptors to the interceptors stack.
  479. // A call to `Intercept(f, g, h)` equals to `batchmsg.Intercept(f(g(h())))`.
  480. func (c *BatchMsgClient) Intercept(interceptors ...Interceptor) {
  481. c.inters.BatchMsg = append(c.inters.BatchMsg, interceptors...)
  482. }
  483. // Create returns a builder for creating a BatchMsg entity.
  484. func (c *BatchMsgClient) Create() *BatchMsgCreate {
  485. mutation := newBatchMsgMutation(c.config, OpCreate)
  486. return &BatchMsgCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  487. }
  488. // CreateBulk returns a builder for creating a bulk of BatchMsg entities.
  489. func (c *BatchMsgClient) CreateBulk(builders ...*BatchMsgCreate) *BatchMsgCreateBulk {
  490. return &BatchMsgCreateBulk{config: c.config, builders: builders}
  491. }
  492. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  493. // a builder and applies setFunc on it.
  494. func (c *BatchMsgClient) MapCreateBulk(slice any, setFunc func(*BatchMsgCreate, int)) *BatchMsgCreateBulk {
  495. rv := reflect.ValueOf(slice)
  496. if rv.Kind() != reflect.Slice {
  497. return &BatchMsgCreateBulk{err: fmt.Errorf("calling to BatchMsgClient.MapCreateBulk with wrong type %T, need slice", slice)}
  498. }
  499. builders := make([]*BatchMsgCreate, rv.Len())
  500. for i := 0; i < rv.Len(); i++ {
  501. builders[i] = c.Create()
  502. setFunc(builders[i], i)
  503. }
  504. return &BatchMsgCreateBulk{config: c.config, builders: builders}
  505. }
  506. // Update returns an update builder for BatchMsg.
  507. func (c *BatchMsgClient) Update() *BatchMsgUpdate {
  508. mutation := newBatchMsgMutation(c.config, OpUpdate)
  509. return &BatchMsgUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  510. }
  511. // UpdateOne returns an update builder for the given entity.
  512. func (c *BatchMsgClient) UpdateOne(bm *BatchMsg) *BatchMsgUpdateOne {
  513. mutation := newBatchMsgMutation(c.config, OpUpdateOne, withBatchMsg(bm))
  514. return &BatchMsgUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  515. }
  516. // UpdateOneID returns an update builder for the given id.
  517. func (c *BatchMsgClient) UpdateOneID(id uint64) *BatchMsgUpdateOne {
  518. mutation := newBatchMsgMutation(c.config, OpUpdateOne, withBatchMsgID(id))
  519. return &BatchMsgUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  520. }
  521. // Delete returns a delete builder for BatchMsg.
  522. func (c *BatchMsgClient) Delete() *BatchMsgDelete {
  523. mutation := newBatchMsgMutation(c.config, OpDelete)
  524. return &BatchMsgDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  525. }
  526. // DeleteOne returns a builder for deleting the given entity.
  527. func (c *BatchMsgClient) DeleteOne(bm *BatchMsg) *BatchMsgDeleteOne {
  528. return c.DeleteOneID(bm.ID)
  529. }
  530. // DeleteOneID returns a builder for deleting the given entity by its id.
  531. func (c *BatchMsgClient) DeleteOneID(id uint64) *BatchMsgDeleteOne {
  532. builder := c.Delete().Where(batchmsg.ID(id))
  533. builder.mutation.id = &id
  534. builder.mutation.op = OpDeleteOne
  535. return &BatchMsgDeleteOne{builder}
  536. }
  537. // Query returns a query builder for BatchMsg.
  538. func (c *BatchMsgClient) Query() *BatchMsgQuery {
  539. return &BatchMsgQuery{
  540. config: c.config,
  541. ctx: &QueryContext{Type: TypeBatchMsg},
  542. inters: c.Interceptors(),
  543. }
  544. }
  545. // Get returns a BatchMsg entity by its id.
  546. func (c *BatchMsgClient) Get(ctx context.Context, id uint64) (*BatchMsg, error) {
  547. return c.Query().Where(batchmsg.ID(id)).Only(ctx)
  548. }
  549. // GetX is like Get, but panics if an error occurs.
  550. func (c *BatchMsgClient) GetX(ctx context.Context, id uint64) *BatchMsg {
  551. obj, err := c.Get(ctx, id)
  552. if err != nil {
  553. panic(err)
  554. }
  555. return obj
  556. }
  557. // Hooks returns the client hooks.
  558. func (c *BatchMsgClient) Hooks() []Hook {
  559. hooks := c.hooks.BatchMsg
  560. return append(hooks[:len(hooks):len(hooks)], batchmsg.Hooks[:]...)
  561. }
  562. // Interceptors returns the client interceptors.
  563. func (c *BatchMsgClient) Interceptors() []Interceptor {
  564. inters := c.inters.BatchMsg
  565. return append(inters[:len(inters):len(inters)], batchmsg.Interceptors[:]...)
  566. }
  567. func (c *BatchMsgClient) mutate(ctx context.Context, m *BatchMsgMutation) (Value, error) {
  568. switch m.Op() {
  569. case OpCreate:
  570. return (&BatchMsgCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  571. case OpUpdate:
  572. return (&BatchMsgUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  573. case OpUpdateOne:
  574. return (&BatchMsgUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  575. case OpDelete, OpDeleteOne:
  576. return (&BatchMsgDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  577. default:
  578. return nil, fmt.Errorf("ent: unknown BatchMsg mutation op: %q", m.Op())
  579. }
  580. }
  581. // CategoryClient is a client for the Category schema.
  582. type CategoryClient struct {
  583. config
  584. }
  585. // NewCategoryClient returns a client for the Category from the given config.
  586. func NewCategoryClient(c config) *CategoryClient {
  587. return &CategoryClient{config: c}
  588. }
  589. // Use adds a list of mutation hooks to the hooks stack.
  590. // A call to `Use(f, g, h)` equals to `category.Hooks(f(g(h())))`.
  591. func (c *CategoryClient) Use(hooks ...Hook) {
  592. c.hooks.Category = append(c.hooks.Category, hooks...)
  593. }
  594. // Intercept adds a list of query interceptors to the interceptors stack.
  595. // A call to `Intercept(f, g, h)` equals to `category.Intercept(f(g(h())))`.
  596. func (c *CategoryClient) Intercept(interceptors ...Interceptor) {
  597. c.inters.Category = append(c.inters.Category, interceptors...)
  598. }
  599. // Create returns a builder for creating a Category entity.
  600. func (c *CategoryClient) Create() *CategoryCreate {
  601. mutation := newCategoryMutation(c.config, OpCreate)
  602. return &CategoryCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  603. }
  604. // CreateBulk returns a builder for creating a bulk of Category entities.
  605. func (c *CategoryClient) CreateBulk(builders ...*CategoryCreate) *CategoryCreateBulk {
  606. return &CategoryCreateBulk{config: c.config, builders: builders}
  607. }
  608. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  609. // a builder and applies setFunc on it.
  610. func (c *CategoryClient) MapCreateBulk(slice any, setFunc func(*CategoryCreate, int)) *CategoryCreateBulk {
  611. rv := reflect.ValueOf(slice)
  612. if rv.Kind() != reflect.Slice {
  613. return &CategoryCreateBulk{err: fmt.Errorf("calling to CategoryClient.MapCreateBulk with wrong type %T, need slice", slice)}
  614. }
  615. builders := make([]*CategoryCreate, rv.Len())
  616. for i := 0; i < rv.Len(); i++ {
  617. builders[i] = c.Create()
  618. setFunc(builders[i], i)
  619. }
  620. return &CategoryCreateBulk{config: c.config, builders: builders}
  621. }
  622. // Update returns an update builder for Category.
  623. func (c *CategoryClient) Update() *CategoryUpdate {
  624. mutation := newCategoryMutation(c.config, OpUpdate)
  625. return &CategoryUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  626. }
  627. // UpdateOne returns an update builder for the given entity.
  628. func (c *CategoryClient) UpdateOne(ca *Category) *CategoryUpdateOne {
  629. mutation := newCategoryMutation(c.config, OpUpdateOne, withCategory(ca))
  630. return &CategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  631. }
  632. // UpdateOneID returns an update builder for the given id.
  633. func (c *CategoryClient) UpdateOneID(id uint64) *CategoryUpdateOne {
  634. mutation := newCategoryMutation(c.config, OpUpdateOne, withCategoryID(id))
  635. return &CategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  636. }
  637. // Delete returns a delete builder for Category.
  638. func (c *CategoryClient) Delete() *CategoryDelete {
  639. mutation := newCategoryMutation(c.config, OpDelete)
  640. return &CategoryDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  641. }
  642. // DeleteOne returns a builder for deleting the given entity.
  643. func (c *CategoryClient) DeleteOne(ca *Category) *CategoryDeleteOne {
  644. return c.DeleteOneID(ca.ID)
  645. }
  646. // DeleteOneID returns a builder for deleting the given entity by its id.
  647. func (c *CategoryClient) DeleteOneID(id uint64) *CategoryDeleteOne {
  648. builder := c.Delete().Where(category.ID(id))
  649. builder.mutation.id = &id
  650. builder.mutation.op = OpDeleteOne
  651. return &CategoryDeleteOne{builder}
  652. }
  653. // Query returns a query builder for Category.
  654. func (c *CategoryClient) Query() *CategoryQuery {
  655. return &CategoryQuery{
  656. config: c.config,
  657. ctx: &QueryContext{Type: TypeCategory},
  658. inters: c.Interceptors(),
  659. }
  660. }
  661. // Get returns a Category entity by its id.
  662. func (c *CategoryClient) Get(ctx context.Context, id uint64) (*Category, error) {
  663. return c.Query().Where(category.ID(id)).Only(ctx)
  664. }
  665. // GetX is like Get, but panics if an error occurs.
  666. func (c *CategoryClient) GetX(ctx context.Context, id uint64) *Category {
  667. obj, err := c.Get(ctx, id)
  668. if err != nil {
  669. panic(err)
  670. }
  671. return obj
  672. }
  673. // Hooks returns the client hooks.
  674. func (c *CategoryClient) Hooks() []Hook {
  675. hooks := c.hooks.Category
  676. return append(hooks[:len(hooks):len(hooks)], category.Hooks[:]...)
  677. }
  678. // Interceptors returns the client interceptors.
  679. func (c *CategoryClient) Interceptors() []Interceptor {
  680. inters := c.inters.Category
  681. return append(inters[:len(inters):len(inters)], category.Interceptors[:]...)
  682. }
  683. func (c *CategoryClient) mutate(ctx context.Context, m *CategoryMutation) (Value, error) {
  684. switch m.Op() {
  685. case OpCreate:
  686. return (&CategoryCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  687. case OpUpdate:
  688. return (&CategoryUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  689. case OpUpdateOne:
  690. return (&CategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  691. case OpDelete, OpDeleteOne:
  692. return (&CategoryDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  693. default:
  694. return nil, fmt.Errorf("ent: unknown Category mutation op: %q", m.Op())
  695. }
  696. }
  697. // ContactClient is a client for the Contact schema.
  698. type ContactClient struct {
  699. config
  700. }
  701. // NewContactClient returns a client for the Contact from the given config.
  702. func NewContactClient(c config) *ContactClient {
  703. return &ContactClient{config: c}
  704. }
  705. // Use adds a list of mutation hooks to the hooks stack.
  706. // A call to `Use(f, g, h)` equals to `contact.Hooks(f(g(h())))`.
  707. func (c *ContactClient) Use(hooks ...Hook) {
  708. c.hooks.Contact = append(c.hooks.Contact, hooks...)
  709. }
  710. // Intercept adds a list of query interceptors to the interceptors stack.
  711. // A call to `Intercept(f, g, h)` equals to `contact.Intercept(f(g(h())))`.
  712. func (c *ContactClient) Intercept(interceptors ...Interceptor) {
  713. c.inters.Contact = append(c.inters.Contact, interceptors...)
  714. }
  715. // Create returns a builder for creating a Contact entity.
  716. func (c *ContactClient) Create() *ContactCreate {
  717. mutation := newContactMutation(c.config, OpCreate)
  718. return &ContactCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  719. }
  720. // CreateBulk returns a builder for creating a bulk of Contact entities.
  721. func (c *ContactClient) CreateBulk(builders ...*ContactCreate) *ContactCreateBulk {
  722. return &ContactCreateBulk{config: c.config, builders: builders}
  723. }
  724. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  725. // a builder and applies setFunc on it.
  726. func (c *ContactClient) MapCreateBulk(slice any, setFunc func(*ContactCreate, int)) *ContactCreateBulk {
  727. rv := reflect.ValueOf(slice)
  728. if rv.Kind() != reflect.Slice {
  729. return &ContactCreateBulk{err: fmt.Errorf("calling to ContactClient.MapCreateBulk with wrong type %T, need slice", slice)}
  730. }
  731. builders := make([]*ContactCreate, rv.Len())
  732. for i := 0; i < rv.Len(); i++ {
  733. builders[i] = c.Create()
  734. setFunc(builders[i], i)
  735. }
  736. return &ContactCreateBulk{config: c.config, builders: builders}
  737. }
  738. // Update returns an update builder for Contact.
  739. func (c *ContactClient) Update() *ContactUpdate {
  740. mutation := newContactMutation(c.config, OpUpdate)
  741. return &ContactUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  742. }
  743. // UpdateOne returns an update builder for the given entity.
  744. func (c *ContactClient) UpdateOne(co *Contact) *ContactUpdateOne {
  745. mutation := newContactMutation(c.config, OpUpdateOne, withContact(co))
  746. return &ContactUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  747. }
  748. // UpdateOneID returns an update builder for the given id.
  749. func (c *ContactClient) UpdateOneID(id uint64) *ContactUpdateOne {
  750. mutation := newContactMutation(c.config, OpUpdateOne, withContactID(id))
  751. return &ContactUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  752. }
  753. // Delete returns a delete builder for Contact.
  754. func (c *ContactClient) Delete() *ContactDelete {
  755. mutation := newContactMutation(c.config, OpDelete)
  756. return &ContactDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  757. }
  758. // DeleteOne returns a builder for deleting the given entity.
  759. func (c *ContactClient) DeleteOne(co *Contact) *ContactDeleteOne {
  760. return c.DeleteOneID(co.ID)
  761. }
  762. // DeleteOneID returns a builder for deleting the given entity by its id.
  763. func (c *ContactClient) DeleteOneID(id uint64) *ContactDeleteOne {
  764. builder := c.Delete().Where(contact.ID(id))
  765. builder.mutation.id = &id
  766. builder.mutation.op = OpDeleteOne
  767. return &ContactDeleteOne{builder}
  768. }
  769. // Query returns a query builder for Contact.
  770. func (c *ContactClient) Query() *ContactQuery {
  771. return &ContactQuery{
  772. config: c.config,
  773. ctx: &QueryContext{Type: TypeContact},
  774. inters: c.Interceptors(),
  775. }
  776. }
  777. // Get returns a Contact entity by its id.
  778. func (c *ContactClient) Get(ctx context.Context, id uint64) (*Contact, error) {
  779. return c.Query().Where(contact.ID(id)).Only(ctx)
  780. }
  781. // GetX is like Get, but panics if an error occurs.
  782. func (c *ContactClient) GetX(ctx context.Context, id uint64) *Contact {
  783. obj, err := c.Get(ctx, id)
  784. if err != nil {
  785. panic(err)
  786. }
  787. return obj
  788. }
  789. // QueryContactRelationships queries the contact_relationships edge of a Contact.
  790. func (c *ContactClient) QueryContactRelationships(co *Contact) *LabelRelationshipQuery {
  791. query := (&LabelRelationshipClient{config: c.config}).Query()
  792. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  793. id := co.ID
  794. step := sqlgraph.NewStep(
  795. sqlgraph.From(contact.Table, contact.FieldID, id),
  796. sqlgraph.To(labelrelationship.Table, labelrelationship.FieldID),
  797. sqlgraph.Edge(sqlgraph.O2M, false, contact.ContactRelationshipsTable, contact.ContactRelationshipsColumn),
  798. )
  799. fromV = sqlgraph.Neighbors(co.driver.Dialect(), step)
  800. return fromV, nil
  801. }
  802. return query
  803. }
  804. // QueryContactMessages queries the contact_messages edge of a Contact.
  805. func (c *ContactClient) QueryContactMessages(co *Contact) *MessageRecordsQuery {
  806. query := (&MessageRecordsClient{config: c.config}).Query()
  807. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  808. id := co.ID
  809. step := sqlgraph.NewStep(
  810. sqlgraph.From(contact.Table, contact.FieldID, id),
  811. sqlgraph.To(messagerecords.Table, messagerecords.FieldID),
  812. sqlgraph.Edge(sqlgraph.O2M, false, contact.ContactMessagesTable, contact.ContactMessagesColumn),
  813. )
  814. fromV = sqlgraph.Neighbors(co.driver.Dialect(), step)
  815. return fromV, nil
  816. }
  817. return query
  818. }
  819. // Hooks returns the client hooks.
  820. func (c *ContactClient) Hooks() []Hook {
  821. hooks := c.hooks.Contact
  822. return append(hooks[:len(hooks):len(hooks)], contact.Hooks[:]...)
  823. }
  824. // Interceptors returns the client interceptors.
  825. func (c *ContactClient) Interceptors() []Interceptor {
  826. inters := c.inters.Contact
  827. return append(inters[:len(inters):len(inters)], contact.Interceptors[:]...)
  828. }
  829. func (c *ContactClient) mutate(ctx context.Context, m *ContactMutation) (Value, error) {
  830. switch m.Op() {
  831. case OpCreate:
  832. return (&ContactCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  833. case OpUpdate:
  834. return (&ContactUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  835. case OpUpdateOne:
  836. return (&ContactUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  837. case OpDelete, OpDeleteOne:
  838. return (&ContactDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  839. default:
  840. return nil, fmt.Errorf("ent: unknown Contact mutation op: %q", m.Op())
  841. }
  842. }
  843. // EmployeeClient is a client for the Employee schema.
  844. type EmployeeClient struct {
  845. config
  846. }
  847. // NewEmployeeClient returns a client for the Employee from the given config.
  848. func NewEmployeeClient(c config) *EmployeeClient {
  849. return &EmployeeClient{config: c}
  850. }
  851. // Use adds a list of mutation hooks to the hooks stack.
  852. // A call to `Use(f, g, h)` equals to `employee.Hooks(f(g(h())))`.
  853. func (c *EmployeeClient) Use(hooks ...Hook) {
  854. c.hooks.Employee = append(c.hooks.Employee, hooks...)
  855. }
  856. // Intercept adds a list of query interceptors to the interceptors stack.
  857. // A call to `Intercept(f, g, h)` equals to `employee.Intercept(f(g(h())))`.
  858. func (c *EmployeeClient) Intercept(interceptors ...Interceptor) {
  859. c.inters.Employee = append(c.inters.Employee, interceptors...)
  860. }
  861. // Create returns a builder for creating a Employee entity.
  862. func (c *EmployeeClient) Create() *EmployeeCreate {
  863. mutation := newEmployeeMutation(c.config, OpCreate)
  864. return &EmployeeCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  865. }
  866. // CreateBulk returns a builder for creating a bulk of Employee entities.
  867. func (c *EmployeeClient) CreateBulk(builders ...*EmployeeCreate) *EmployeeCreateBulk {
  868. return &EmployeeCreateBulk{config: c.config, builders: builders}
  869. }
  870. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  871. // a builder and applies setFunc on it.
  872. func (c *EmployeeClient) MapCreateBulk(slice any, setFunc func(*EmployeeCreate, int)) *EmployeeCreateBulk {
  873. rv := reflect.ValueOf(slice)
  874. if rv.Kind() != reflect.Slice {
  875. return &EmployeeCreateBulk{err: fmt.Errorf("calling to EmployeeClient.MapCreateBulk with wrong type %T, need slice", slice)}
  876. }
  877. builders := make([]*EmployeeCreate, rv.Len())
  878. for i := 0; i < rv.Len(); i++ {
  879. builders[i] = c.Create()
  880. setFunc(builders[i], i)
  881. }
  882. return &EmployeeCreateBulk{config: c.config, builders: builders}
  883. }
  884. // Update returns an update builder for Employee.
  885. func (c *EmployeeClient) Update() *EmployeeUpdate {
  886. mutation := newEmployeeMutation(c.config, OpUpdate)
  887. return &EmployeeUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  888. }
  889. // UpdateOne returns an update builder for the given entity.
  890. func (c *EmployeeClient) UpdateOne(e *Employee) *EmployeeUpdateOne {
  891. mutation := newEmployeeMutation(c.config, OpUpdateOne, withEmployee(e))
  892. return &EmployeeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  893. }
  894. // UpdateOneID returns an update builder for the given id.
  895. func (c *EmployeeClient) UpdateOneID(id uint64) *EmployeeUpdateOne {
  896. mutation := newEmployeeMutation(c.config, OpUpdateOne, withEmployeeID(id))
  897. return &EmployeeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  898. }
  899. // Delete returns a delete builder for Employee.
  900. func (c *EmployeeClient) Delete() *EmployeeDelete {
  901. mutation := newEmployeeMutation(c.config, OpDelete)
  902. return &EmployeeDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  903. }
  904. // DeleteOne returns a builder for deleting the given entity.
  905. func (c *EmployeeClient) DeleteOne(e *Employee) *EmployeeDeleteOne {
  906. return c.DeleteOneID(e.ID)
  907. }
  908. // DeleteOneID returns a builder for deleting the given entity by its id.
  909. func (c *EmployeeClient) DeleteOneID(id uint64) *EmployeeDeleteOne {
  910. builder := c.Delete().Where(employee.ID(id))
  911. builder.mutation.id = &id
  912. builder.mutation.op = OpDeleteOne
  913. return &EmployeeDeleteOne{builder}
  914. }
  915. // Query returns a query builder for Employee.
  916. func (c *EmployeeClient) Query() *EmployeeQuery {
  917. return &EmployeeQuery{
  918. config: c.config,
  919. ctx: &QueryContext{Type: TypeEmployee},
  920. inters: c.Interceptors(),
  921. }
  922. }
  923. // Get returns a Employee entity by its id.
  924. func (c *EmployeeClient) Get(ctx context.Context, id uint64) (*Employee, error) {
  925. return c.Query().Where(employee.ID(id)).Only(ctx)
  926. }
  927. // GetX is like Get, but panics if an error occurs.
  928. func (c *EmployeeClient) GetX(ctx context.Context, id uint64) *Employee {
  929. obj, err := c.Get(ctx, id)
  930. if err != nil {
  931. panic(err)
  932. }
  933. return obj
  934. }
  935. // QueryEmWorkExperiences queries the em_work_experiences edge of a Employee.
  936. func (c *EmployeeClient) QueryEmWorkExperiences(e *Employee) *WorkExperienceQuery {
  937. query := (&WorkExperienceClient{config: c.config}).Query()
  938. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  939. id := e.ID
  940. step := sqlgraph.NewStep(
  941. sqlgraph.From(employee.Table, employee.FieldID, id),
  942. sqlgraph.To(workexperience.Table, workexperience.FieldID),
  943. sqlgraph.Edge(sqlgraph.O2M, false, employee.EmWorkExperiencesTable, employee.EmWorkExperiencesColumn),
  944. )
  945. fromV = sqlgraph.Neighbors(e.driver.Dialect(), step)
  946. return fromV, nil
  947. }
  948. return query
  949. }
  950. // QueryEmTutorial queries the em_tutorial edge of a Employee.
  951. func (c *EmployeeClient) QueryEmTutorial(e *Employee) *TutorialQuery {
  952. query := (&TutorialClient{config: c.config}).Query()
  953. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  954. id := e.ID
  955. step := sqlgraph.NewStep(
  956. sqlgraph.From(employee.Table, employee.FieldID, id),
  957. sqlgraph.To(tutorial.Table, tutorial.FieldID),
  958. sqlgraph.Edge(sqlgraph.O2M, false, employee.EmTutorialTable, employee.EmTutorialColumn),
  959. )
  960. fromV = sqlgraph.Neighbors(e.driver.Dialect(), step)
  961. return fromV, nil
  962. }
  963. return query
  964. }
  965. // Hooks returns the client hooks.
  966. func (c *EmployeeClient) Hooks() []Hook {
  967. hooks := c.hooks.Employee
  968. return append(hooks[:len(hooks):len(hooks)], employee.Hooks[:]...)
  969. }
  970. // Interceptors returns the client interceptors.
  971. func (c *EmployeeClient) Interceptors() []Interceptor {
  972. inters := c.inters.Employee
  973. return append(inters[:len(inters):len(inters)], employee.Interceptors[:]...)
  974. }
  975. func (c *EmployeeClient) mutate(ctx context.Context, m *EmployeeMutation) (Value, error) {
  976. switch m.Op() {
  977. case OpCreate:
  978. return (&EmployeeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  979. case OpUpdate:
  980. return (&EmployeeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  981. case OpUpdateOne:
  982. return (&EmployeeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  983. case OpDelete, OpDeleteOne:
  984. return (&EmployeeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  985. default:
  986. return nil, fmt.Errorf("ent: unknown Employee mutation op: %q", m.Op())
  987. }
  988. }
  989. // EmployeeConfigClient is a client for the EmployeeConfig schema.
  990. type EmployeeConfigClient struct {
  991. config
  992. }
  993. // NewEmployeeConfigClient returns a client for the EmployeeConfig from the given config.
  994. func NewEmployeeConfigClient(c config) *EmployeeConfigClient {
  995. return &EmployeeConfigClient{config: c}
  996. }
  997. // Use adds a list of mutation hooks to the hooks stack.
  998. // A call to `Use(f, g, h)` equals to `employeeconfig.Hooks(f(g(h())))`.
  999. func (c *EmployeeConfigClient) Use(hooks ...Hook) {
  1000. c.hooks.EmployeeConfig = append(c.hooks.EmployeeConfig, hooks...)
  1001. }
  1002. // Intercept adds a list of query interceptors to the interceptors stack.
  1003. // A call to `Intercept(f, g, h)` equals to `employeeconfig.Intercept(f(g(h())))`.
  1004. func (c *EmployeeConfigClient) Intercept(interceptors ...Interceptor) {
  1005. c.inters.EmployeeConfig = append(c.inters.EmployeeConfig, interceptors...)
  1006. }
  1007. // Create returns a builder for creating a EmployeeConfig entity.
  1008. func (c *EmployeeConfigClient) Create() *EmployeeConfigCreate {
  1009. mutation := newEmployeeConfigMutation(c.config, OpCreate)
  1010. return &EmployeeConfigCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1011. }
  1012. // CreateBulk returns a builder for creating a bulk of EmployeeConfig entities.
  1013. func (c *EmployeeConfigClient) CreateBulk(builders ...*EmployeeConfigCreate) *EmployeeConfigCreateBulk {
  1014. return &EmployeeConfigCreateBulk{config: c.config, builders: builders}
  1015. }
  1016. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1017. // a builder and applies setFunc on it.
  1018. func (c *EmployeeConfigClient) MapCreateBulk(slice any, setFunc func(*EmployeeConfigCreate, int)) *EmployeeConfigCreateBulk {
  1019. rv := reflect.ValueOf(slice)
  1020. if rv.Kind() != reflect.Slice {
  1021. return &EmployeeConfigCreateBulk{err: fmt.Errorf("calling to EmployeeConfigClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1022. }
  1023. builders := make([]*EmployeeConfigCreate, rv.Len())
  1024. for i := 0; i < rv.Len(); i++ {
  1025. builders[i] = c.Create()
  1026. setFunc(builders[i], i)
  1027. }
  1028. return &EmployeeConfigCreateBulk{config: c.config, builders: builders}
  1029. }
  1030. // Update returns an update builder for EmployeeConfig.
  1031. func (c *EmployeeConfigClient) Update() *EmployeeConfigUpdate {
  1032. mutation := newEmployeeConfigMutation(c.config, OpUpdate)
  1033. return &EmployeeConfigUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1034. }
  1035. // UpdateOne returns an update builder for the given entity.
  1036. func (c *EmployeeConfigClient) UpdateOne(ec *EmployeeConfig) *EmployeeConfigUpdateOne {
  1037. mutation := newEmployeeConfigMutation(c.config, OpUpdateOne, withEmployeeConfig(ec))
  1038. return &EmployeeConfigUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1039. }
  1040. // UpdateOneID returns an update builder for the given id.
  1041. func (c *EmployeeConfigClient) UpdateOneID(id uint64) *EmployeeConfigUpdateOne {
  1042. mutation := newEmployeeConfigMutation(c.config, OpUpdateOne, withEmployeeConfigID(id))
  1043. return &EmployeeConfigUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1044. }
  1045. // Delete returns a delete builder for EmployeeConfig.
  1046. func (c *EmployeeConfigClient) Delete() *EmployeeConfigDelete {
  1047. mutation := newEmployeeConfigMutation(c.config, OpDelete)
  1048. return &EmployeeConfigDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1049. }
  1050. // DeleteOne returns a builder for deleting the given entity.
  1051. func (c *EmployeeConfigClient) DeleteOne(ec *EmployeeConfig) *EmployeeConfigDeleteOne {
  1052. return c.DeleteOneID(ec.ID)
  1053. }
  1054. // DeleteOneID returns a builder for deleting the given entity by its id.
  1055. func (c *EmployeeConfigClient) DeleteOneID(id uint64) *EmployeeConfigDeleteOne {
  1056. builder := c.Delete().Where(employeeconfig.ID(id))
  1057. builder.mutation.id = &id
  1058. builder.mutation.op = OpDeleteOne
  1059. return &EmployeeConfigDeleteOne{builder}
  1060. }
  1061. // Query returns a query builder for EmployeeConfig.
  1062. func (c *EmployeeConfigClient) Query() *EmployeeConfigQuery {
  1063. return &EmployeeConfigQuery{
  1064. config: c.config,
  1065. ctx: &QueryContext{Type: TypeEmployeeConfig},
  1066. inters: c.Interceptors(),
  1067. }
  1068. }
  1069. // Get returns a EmployeeConfig entity by its id.
  1070. func (c *EmployeeConfigClient) Get(ctx context.Context, id uint64) (*EmployeeConfig, error) {
  1071. return c.Query().Where(employeeconfig.ID(id)).Only(ctx)
  1072. }
  1073. // GetX is like Get, but panics if an error occurs.
  1074. func (c *EmployeeConfigClient) GetX(ctx context.Context, id uint64) *EmployeeConfig {
  1075. obj, err := c.Get(ctx, id)
  1076. if err != nil {
  1077. panic(err)
  1078. }
  1079. return obj
  1080. }
  1081. // Hooks returns the client hooks.
  1082. func (c *EmployeeConfigClient) Hooks() []Hook {
  1083. hooks := c.hooks.EmployeeConfig
  1084. return append(hooks[:len(hooks):len(hooks)], employeeconfig.Hooks[:]...)
  1085. }
  1086. // Interceptors returns the client interceptors.
  1087. func (c *EmployeeConfigClient) Interceptors() []Interceptor {
  1088. inters := c.inters.EmployeeConfig
  1089. return append(inters[:len(inters):len(inters)], employeeconfig.Interceptors[:]...)
  1090. }
  1091. func (c *EmployeeConfigClient) mutate(ctx context.Context, m *EmployeeConfigMutation) (Value, error) {
  1092. switch m.Op() {
  1093. case OpCreate:
  1094. return (&EmployeeConfigCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1095. case OpUpdate:
  1096. return (&EmployeeConfigUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1097. case OpUpdateOne:
  1098. return (&EmployeeConfigUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1099. case OpDelete, OpDeleteOne:
  1100. return (&EmployeeConfigDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1101. default:
  1102. return nil, fmt.Errorf("ent: unknown EmployeeConfig mutation op: %q", m.Op())
  1103. }
  1104. }
  1105. // LabelClient is a client for the Label schema.
  1106. type LabelClient struct {
  1107. config
  1108. }
  1109. // NewLabelClient returns a client for the Label from the given config.
  1110. func NewLabelClient(c config) *LabelClient {
  1111. return &LabelClient{config: c}
  1112. }
  1113. // Use adds a list of mutation hooks to the hooks stack.
  1114. // A call to `Use(f, g, h)` equals to `label.Hooks(f(g(h())))`.
  1115. func (c *LabelClient) Use(hooks ...Hook) {
  1116. c.hooks.Label = append(c.hooks.Label, hooks...)
  1117. }
  1118. // Intercept adds a list of query interceptors to the interceptors stack.
  1119. // A call to `Intercept(f, g, h)` equals to `label.Intercept(f(g(h())))`.
  1120. func (c *LabelClient) Intercept(interceptors ...Interceptor) {
  1121. c.inters.Label = append(c.inters.Label, interceptors...)
  1122. }
  1123. // Create returns a builder for creating a Label entity.
  1124. func (c *LabelClient) Create() *LabelCreate {
  1125. mutation := newLabelMutation(c.config, OpCreate)
  1126. return &LabelCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1127. }
  1128. // CreateBulk returns a builder for creating a bulk of Label entities.
  1129. func (c *LabelClient) CreateBulk(builders ...*LabelCreate) *LabelCreateBulk {
  1130. return &LabelCreateBulk{config: c.config, builders: builders}
  1131. }
  1132. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1133. // a builder and applies setFunc on it.
  1134. func (c *LabelClient) MapCreateBulk(slice any, setFunc func(*LabelCreate, int)) *LabelCreateBulk {
  1135. rv := reflect.ValueOf(slice)
  1136. if rv.Kind() != reflect.Slice {
  1137. return &LabelCreateBulk{err: fmt.Errorf("calling to LabelClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1138. }
  1139. builders := make([]*LabelCreate, rv.Len())
  1140. for i := 0; i < rv.Len(); i++ {
  1141. builders[i] = c.Create()
  1142. setFunc(builders[i], i)
  1143. }
  1144. return &LabelCreateBulk{config: c.config, builders: builders}
  1145. }
  1146. // Update returns an update builder for Label.
  1147. func (c *LabelClient) Update() *LabelUpdate {
  1148. mutation := newLabelMutation(c.config, OpUpdate)
  1149. return &LabelUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1150. }
  1151. // UpdateOne returns an update builder for the given entity.
  1152. func (c *LabelClient) UpdateOne(l *Label) *LabelUpdateOne {
  1153. mutation := newLabelMutation(c.config, OpUpdateOne, withLabel(l))
  1154. return &LabelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1155. }
  1156. // UpdateOneID returns an update builder for the given id.
  1157. func (c *LabelClient) UpdateOneID(id uint64) *LabelUpdateOne {
  1158. mutation := newLabelMutation(c.config, OpUpdateOne, withLabelID(id))
  1159. return &LabelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1160. }
  1161. // Delete returns a delete builder for Label.
  1162. func (c *LabelClient) Delete() *LabelDelete {
  1163. mutation := newLabelMutation(c.config, OpDelete)
  1164. return &LabelDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1165. }
  1166. // DeleteOne returns a builder for deleting the given entity.
  1167. func (c *LabelClient) DeleteOne(l *Label) *LabelDeleteOne {
  1168. return c.DeleteOneID(l.ID)
  1169. }
  1170. // DeleteOneID returns a builder for deleting the given entity by its id.
  1171. func (c *LabelClient) DeleteOneID(id uint64) *LabelDeleteOne {
  1172. builder := c.Delete().Where(label.ID(id))
  1173. builder.mutation.id = &id
  1174. builder.mutation.op = OpDeleteOne
  1175. return &LabelDeleteOne{builder}
  1176. }
  1177. // Query returns a query builder for Label.
  1178. func (c *LabelClient) Query() *LabelQuery {
  1179. return &LabelQuery{
  1180. config: c.config,
  1181. ctx: &QueryContext{Type: TypeLabel},
  1182. inters: c.Interceptors(),
  1183. }
  1184. }
  1185. // Get returns a Label entity by its id.
  1186. func (c *LabelClient) Get(ctx context.Context, id uint64) (*Label, error) {
  1187. return c.Query().Where(label.ID(id)).Only(ctx)
  1188. }
  1189. // GetX is like Get, but panics if an error occurs.
  1190. func (c *LabelClient) GetX(ctx context.Context, id uint64) *Label {
  1191. obj, err := c.Get(ctx, id)
  1192. if err != nil {
  1193. panic(err)
  1194. }
  1195. return obj
  1196. }
  1197. // QueryLabelRelationships queries the label_relationships edge of a Label.
  1198. func (c *LabelClient) QueryLabelRelationships(l *Label) *LabelRelationshipQuery {
  1199. query := (&LabelRelationshipClient{config: c.config}).Query()
  1200. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1201. id := l.ID
  1202. step := sqlgraph.NewStep(
  1203. sqlgraph.From(label.Table, label.FieldID, id),
  1204. sqlgraph.To(labelrelationship.Table, labelrelationship.FieldID),
  1205. sqlgraph.Edge(sqlgraph.O2M, false, label.LabelRelationshipsTable, label.LabelRelationshipsColumn),
  1206. )
  1207. fromV = sqlgraph.Neighbors(l.driver.Dialect(), step)
  1208. return fromV, nil
  1209. }
  1210. return query
  1211. }
  1212. // Hooks returns the client hooks.
  1213. func (c *LabelClient) Hooks() []Hook {
  1214. return c.hooks.Label
  1215. }
  1216. // Interceptors returns the client interceptors.
  1217. func (c *LabelClient) Interceptors() []Interceptor {
  1218. return c.inters.Label
  1219. }
  1220. func (c *LabelClient) mutate(ctx context.Context, m *LabelMutation) (Value, error) {
  1221. switch m.Op() {
  1222. case OpCreate:
  1223. return (&LabelCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1224. case OpUpdate:
  1225. return (&LabelUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1226. case OpUpdateOne:
  1227. return (&LabelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1228. case OpDelete, OpDeleteOne:
  1229. return (&LabelDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1230. default:
  1231. return nil, fmt.Errorf("ent: unknown Label mutation op: %q", m.Op())
  1232. }
  1233. }
  1234. // LabelRelationshipClient is a client for the LabelRelationship schema.
  1235. type LabelRelationshipClient struct {
  1236. config
  1237. }
  1238. // NewLabelRelationshipClient returns a client for the LabelRelationship from the given config.
  1239. func NewLabelRelationshipClient(c config) *LabelRelationshipClient {
  1240. return &LabelRelationshipClient{config: c}
  1241. }
  1242. // Use adds a list of mutation hooks to the hooks stack.
  1243. // A call to `Use(f, g, h)` equals to `labelrelationship.Hooks(f(g(h())))`.
  1244. func (c *LabelRelationshipClient) Use(hooks ...Hook) {
  1245. c.hooks.LabelRelationship = append(c.hooks.LabelRelationship, hooks...)
  1246. }
  1247. // Intercept adds a list of query interceptors to the interceptors stack.
  1248. // A call to `Intercept(f, g, h)` equals to `labelrelationship.Intercept(f(g(h())))`.
  1249. func (c *LabelRelationshipClient) Intercept(interceptors ...Interceptor) {
  1250. c.inters.LabelRelationship = append(c.inters.LabelRelationship, interceptors...)
  1251. }
  1252. // Create returns a builder for creating a LabelRelationship entity.
  1253. func (c *LabelRelationshipClient) Create() *LabelRelationshipCreate {
  1254. mutation := newLabelRelationshipMutation(c.config, OpCreate)
  1255. return &LabelRelationshipCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1256. }
  1257. // CreateBulk returns a builder for creating a bulk of LabelRelationship entities.
  1258. func (c *LabelRelationshipClient) CreateBulk(builders ...*LabelRelationshipCreate) *LabelRelationshipCreateBulk {
  1259. return &LabelRelationshipCreateBulk{config: c.config, builders: builders}
  1260. }
  1261. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1262. // a builder and applies setFunc on it.
  1263. func (c *LabelRelationshipClient) MapCreateBulk(slice any, setFunc func(*LabelRelationshipCreate, int)) *LabelRelationshipCreateBulk {
  1264. rv := reflect.ValueOf(slice)
  1265. if rv.Kind() != reflect.Slice {
  1266. return &LabelRelationshipCreateBulk{err: fmt.Errorf("calling to LabelRelationshipClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1267. }
  1268. builders := make([]*LabelRelationshipCreate, rv.Len())
  1269. for i := 0; i < rv.Len(); i++ {
  1270. builders[i] = c.Create()
  1271. setFunc(builders[i], i)
  1272. }
  1273. return &LabelRelationshipCreateBulk{config: c.config, builders: builders}
  1274. }
  1275. // Update returns an update builder for LabelRelationship.
  1276. func (c *LabelRelationshipClient) Update() *LabelRelationshipUpdate {
  1277. mutation := newLabelRelationshipMutation(c.config, OpUpdate)
  1278. return &LabelRelationshipUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1279. }
  1280. // UpdateOne returns an update builder for the given entity.
  1281. func (c *LabelRelationshipClient) UpdateOne(lr *LabelRelationship) *LabelRelationshipUpdateOne {
  1282. mutation := newLabelRelationshipMutation(c.config, OpUpdateOne, withLabelRelationship(lr))
  1283. return &LabelRelationshipUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1284. }
  1285. // UpdateOneID returns an update builder for the given id.
  1286. func (c *LabelRelationshipClient) UpdateOneID(id uint64) *LabelRelationshipUpdateOne {
  1287. mutation := newLabelRelationshipMutation(c.config, OpUpdateOne, withLabelRelationshipID(id))
  1288. return &LabelRelationshipUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1289. }
  1290. // Delete returns a delete builder for LabelRelationship.
  1291. func (c *LabelRelationshipClient) Delete() *LabelRelationshipDelete {
  1292. mutation := newLabelRelationshipMutation(c.config, OpDelete)
  1293. return &LabelRelationshipDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1294. }
  1295. // DeleteOne returns a builder for deleting the given entity.
  1296. func (c *LabelRelationshipClient) DeleteOne(lr *LabelRelationship) *LabelRelationshipDeleteOne {
  1297. return c.DeleteOneID(lr.ID)
  1298. }
  1299. // DeleteOneID returns a builder for deleting the given entity by its id.
  1300. func (c *LabelRelationshipClient) DeleteOneID(id uint64) *LabelRelationshipDeleteOne {
  1301. builder := c.Delete().Where(labelrelationship.ID(id))
  1302. builder.mutation.id = &id
  1303. builder.mutation.op = OpDeleteOne
  1304. return &LabelRelationshipDeleteOne{builder}
  1305. }
  1306. // Query returns a query builder for LabelRelationship.
  1307. func (c *LabelRelationshipClient) Query() *LabelRelationshipQuery {
  1308. return &LabelRelationshipQuery{
  1309. config: c.config,
  1310. ctx: &QueryContext{Type: TypeLabelRelationship},
  1311. inters: c.Interceptors(),
  1312. }
  1313. }
  1314. // Get returns a LabelRelationship entity by its id.
  1315. func (c *LabelRelationshipClient) Get(ctx context.Context, id uint64) (*LabelRelationship, error) {
  1316. return c.Query().Where(labelrelationship.ID(id)).Only(ctx)
  1317. }
  1318. // GetX is like Get, but panics if an error occurs.
  1319. func (c *LabelRelationshipClient) GetX(ctx context.Context, id uint64) *LabelRelationship {
  1320. obj, err := c.Get(ctx, id)
  1321. if err != nil {
  1322. panic(err)
  1323. }
  1324. return obj
  1325. }
  1326. // QueryContacts queries the contacts edge of a LabelRelationship.
  1327. func (c *LabelRelationshipClient) QueryContacts(lr *LabelRelationship) *ContactQuery {
  1328. query := (&ContactClient{config: c.config}).Query()
  1329. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1330. id := lr.ID
  1331. step := sqlgraph.NewStep(
  1332. sqlgraph.From(labelrelationship.Table, labelrelationship.FieldID, id),
  1333. sqlgraph.To(contact.Table, contact.FieldID),
  1334. sqlgraph.Edge(sqlgraph.M2O, true, labelrelationship.ContactsTable, labelrelationship.ContactsColumn),
  1335. )
  1336. fromV = sqlgraph.Neighbors(lr.driver.Dialect(), step)
  1337. return fromV, nil
  1338. }
  1339. return query
  1340. }
  1341. // QueryLabels queries the labels edge of a LabelRelationship.
  1342. func (c *LabelRelationshipClient) QueryLabels(lr *LabelRelationship) *LabelQuery {
  1343. query := (&LabelClient{config: c.config}).Query()
  1344. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1345. id := lr.ID
  1346. step := sqlgraph.NewStep(
  1347. sqlgraph.From(labelrelationship.Table, labelrelationship.FieldID, id),
  1348. sqlgraph.To(label.Table, label.FieldID),
  1349. sqlgraph.Edge(sqlgraph.M2O, true, labelrelationship.LabelsTable, labelrelationship.LabelsColumn),
  1350. )
  1351. fromV = sqlgraph.Neighbors(lr.driver.Dialect(), step)
  1352. return fromV, nil
  1353. }
  1354. return query
  1355. }
  1356. // Hooks returns the client hooks.
  1357. func (c *LabelRelationshipClient) Hooks() []Hook {
  1358. hooks := c.hooks.LabelRelationship
  1359. return append(hooks[:len(hooks):len(hooks)], labelrelationship.Hooks[:]...)
  1360. }
  1361. // Interceptors returns the client interceptors.
  1362. func (c *LabelRelationshipClient) Interceptors() []Interceptor {
  1363. inters := c.inters.LabelRelationship
  1364. return append(inters[:len(inters):len(inters)], labelrelationship.Interceptors[:]...)
  1365. }
  1366. func (c *LabelRelationshipClient) mutate(ctx context.Context, m *LabelRelationshipMutation) (Value, error) {
  1367. switch m.Op() {
  1368. case OpCreate:
  1369. return (&LabelRelationshipCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1370. case OpUpdate:
  1371. return (&LabelRelationshipUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1372. case OpUpdateOne:
  1373. return (&LabelRelationshipUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1374. case OpDelete, OpDeleteOne:
  1375. return (&LabelRelationshipDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1376. default:
  1377. return nil, fmt.Errorf("ent: unknown LabelRelationship mutation op: %q", m.Op())
  1378. }
  1379. }
  1380. // MessageClient is a client for the Message schema.
  1381. type MessageClient struct {
  1382. config
  1383. }
  1384. // NewMessageClient returns a client for the Message from the given config.
  1385. func NewMessageClient(c config) *MessageClient {
  1386. return &MessageClient{config: c}
  1387. }
  1388. // Use adds a list of mutation hooks to the hooks stack.
  1389. // A call to `Use(f, g, h)` equals to `message.Hooks(f(g(h())))`.
  1390. func (c *MessageClient) Use(hooks ...Hook) {
  1391. c.hooks.Message = append(c.hooks.Message, hooks...)
  1392. }
  1393. // Intercept adds a list of query interceptors to the interceptors stack.
  1394. // A call to `Intercept(f, g, h)` equals to `message.Intercept(f(g(h())))`.
  1395. func (c *MessageClient) Intercept(interceptors ...Interceptor) {
  1396. c.inters.Message = append(c.inters.Message, interceptors...)
  1397. }
  1398. // Create returns a builder for creating a Message entity.
  1399. func (c *MessageClient) Create() *MessageCreate {
  1400. mutation := newMessageMutation(c.config, OpCreate)
  1401. return &MessageCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1402. }
  1403. // CreateBulk returns a builder for creating a bulk of Message entities.
  1404. func (c *MessageClient) CreateBulk(builders ...*MessageCreate) *MessageCreateBulk {
  1405. return &MessageCreateBulk{config: c.config, builders: builders}
  1406. }
  1407. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1408. // a builder and applies setFunc on it.
  1409. func (c *MessageClient) MapCreateBulk(slice any, setFunc func(*MessageCreate, int)) *MessageCreateBulk {
  1410. rv := reflect.ValueOf(slice)
  1411. if rv.Kind() != reflect.Slice {
  1412. return &MessageCreateBulk{err: fmt.Errorf("calling to MessageClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1413. }
  1414. builders := make([]*MessageCreate, rv.Len())
  1415. for i := 0; i < rv.Len(); i++ {
  1416. builders[i] = c.Create()
  1417. setFunc(builders[i], i)
  1418. }
  1419. return &MessageCreateBulk{config: c.config, builders: builders}
  1420. }
  1421. // Update returns an update builder for Message.
  1422. func (c *MessageClient) Update() *MessageUpdate {
  1423. mutation := newMessageMutation(c.config, OpUpdate)
  1424. return &MessageUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1425. }
  1426. // UpdateOne returns an update builder for the given entity.
  1427. func (c *MessageClient) UpdateOne(m *Message) *MessageUpdateOne {
  1428. mutation := newMessageMutation(c.config, OpUpdateOne, withMessage(m))
  1429. return &MessageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1430. }
  1431. // UpdateOneID returns an update builder for the given id.
  1432. func (c *MessageClient) UpdateOneID(id int) *MessageUpdateOne {
  1433. mutation := newMessageMutation(c.config, OpUpdateOne, withMessageID(id))
  1434. return &MessageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1435. }
  1436. // Delete returns a delete builder for Message.
  1437. func (c *MessageClient) Delete() *MessageDelete {
  1438. mutation := newMessageMutation(c.config, OpDelete)
  1439. return &MessageDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1440. }
  1441. // DeleteOne returns a builder for deleting the given entity.
  1442. func (c *MessageClient) DeleteOne(m *Message) *MessageDeleteOne {
  1443. return c.DeleteOneID(m.ID)
  1444. }
  1445. // DeleteOneID returns a builder for deleting the given entity by its id.
  1446. func (c *MessageClient) DeleteOneID(id int) *MessageDeleteOne {
  1447. builder := c.Delete().Where(message.ID(id))
  1448. builder.mutation.id = &id
  1449. builder.mutation.op = OpDeleteOne
  1450. return &MessageDeleteOne{builder}
  1451. }
  1452. // Query returns a query builder for Message.
  1453. func (c *MessageClient) Query() *MessageQuery {
  1454. return &MessageQuery{
  1455. config: c.config,
  1456. ctx: &QueryContext{Type: TypeMessage},
  1457. inters: c.Interceptors(),
  1458. }
  1459. }
  1460. // Get returns a Message entity by its id.
  1461. func (c *MessageClient) Get(ctx context.Context, id int) (*Message, error) {
  1462. return c.Query().Where(message.ID(id)).Only(ctx)
  1463. }
  1464. // GetX is like Get, but panics if an error occurs.
  1465. func (c *MessageClient) GetX(ctx context.Context, id int) *Message {
  1466. obj, err := c.Get(ctx, id)
  1467. if err != nil {
  1468. panic(err)
  1469. }
  1470. return obj
  1471. }
  1472. // Hooks returns the client hooks.
  1473. func (c *MessageClient) Hooks() []Hook {
  1474. return c.hooks.Message
  1475. }
  1476. // Interceptors returns the client interceptors.
  1477. func (c *MessageClient) Interceptors() []Interceptor {
  1478. return c.inters.Message
  1479. }
  1480. func (c *MessageClient) mutate(ctx context.Context, m *MessageMutation) (Value, error) {
  1481. switch m.Op() {
  1482. case OpCreate:
  1483. return (&MessageCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1484. case OpUpdate:
  1485. return (&MessageUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1486. case OpUpdateOne:
  1487. return (&MessageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1488. case OpDelete, OpDeleteOne:
  1489. return (&MessageDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1490. default:
  1491. return nil, fmt.Errorf("ent: unknown Message mutation op: %q", m.Op())
  1492. }
  1493. }
  1494. // MessageRecordsClient is a client for the MessageRecords schema.
  1495. type MessageRecordsClient struct {
  1496. config
  1497. }
  1498. // NewMessageRecordsClient returns a client for the MessageRecords from the given config.
  1499. func NewMessageRecordsClient(c config) *MessageRecordsClient {
  1500. return &MessageRecordsClient{config: c}
  1501. }
  1502. // Use adds a list of mutation hooks to the hooks stack.
  1503. // A call to `Use(f, g, h)` equals to `messagerecords.Hooks(f(g(h())))`.
  1504. func (c *MessageRecordsClient) Use(hooks ...Hook) {
  1505. c.hooks.MessageRecords = append(c.hooks.MessageRecords, hooks...)
  1506. }
  1507. // Intercept adds a list of query interceptors to the interceptors stack.
  1508. // A call to `Intercept(f, g, h)` equals to `messagerecords.Intercept(f(g(h())))`.
  1509. func (c *MessageRecordsClient) Intercept(interceptors ...Interceptor) {
  1510. c.inters.MessageRecords = append(c.inters.MessageRecords, interceptors...)
  1511. }
  1512. // Create returns a builder for creating a MessageRecords entity.
  1513. func (c *MessageRecordsClient) Create() *MessageRecordsCreate {
  1514. mutation := newMessageRecordsMutation(c.config, OpCreate)
  1515. return &MessageRecordsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1516. }
  1517. // CreateBulk returns a builder for creating a bulk of MessageRecords entities.
  1518. func (c *MessageRecordsClient) CreateBulk(builders ...*MessageRecordsCreate) *MessageRecordsCreateBulk {
  1519. return &MessageRecordsCreateBulk{config: c.config, builders: builders}
  1520. }
  1521. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1522. // a builder and applies setFunc on it.
  1523. func (c *MessageRecordsClient) MapCreateBulk(slice any, setFunc func(*MessageRecordsCreate, int)) *MessageRecordsCreateBulk {
  1524. rv := reflect.ValueOf(slice)
  1525. if rv.Kind() != reflect.Slice {
  1526. return &MessageRecordsCreateBulk{err: fmt.Errorf("calling to MessageRecordsClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1527. }
  1528. builders := make([]*MessageRecordsCreate, rv.Len())
  1529. for i := 0; i < rv.Len(); i++ {
  1530. builders[i] = c.Create()
  1531. setFunc(builders[i], i)
  1532. }
  1533. return &MessageRecordsCreateBulk{config: c.config, builders: builders}
  1534. }
  1535. // Update returns an update builder for MessageRecords.
  1536. func (c *MessageRecordsClient) Update() *MessageRecordsUpdate {
  1537. mutation := newMessageRecordsMutation(c.config, OpUpdate)
  1538. return &MessageRecordsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1539. }
  1540. // UpdateOne returns an update builder for the given entity.
  1541. func (c *MessageRecordsClient) UpdateOne(mr *MessageRecords) *MessageRecordsUpdateOne {
  1542. mutation := newMessageRecordsMutation(c.config, OpUpdateOne, withMessageRecords(mr))
  1543. return &MessageRecordsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1544. }
  1545. // UpdateOneID returns an update builder for the given id.
  1546. func (c *MessageRecordsClient) UpdateOneID(id uint64) *MessageRecordsUpdateOne {
  1547. mutation := newMessageRecordsMutation(c.config, OpUpdateOne, withMessageRecordsID(id))
  1548. return &MessageRecordsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1549. }
  1550. // Delete returns a delete builder for MessageRecords.
  1551. func (c *MessageRecordsClient) Delete() *MessageRecordsDelete {
  1552. mutation := newMessageRecordsMutation(c.config, OpDelete)
  1553. return &MessageRecordsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1554. }
  1555. // DeleteOne returns a builder for deleting the given entity.
  1556. func (c *MessageRecordsClient) DeleteOne(mr *MessageRecords) *MessageRecordsDeleteOne {
  1557. return c.DeleteOneID(mr.ID)
  1558. }
  1559. // DeleteOneID returns a builder for deleting the given entity by its id.
  1560. func (c *MessageRecordsClient) DeleteOneID(id uint64) *MessageRecordsDeleteOne {
  1561. builder := c.Delete().Where(messagerecords.ID(id))
  1562. builder.mutation.id = &id
  1563. builder.mutation.op = OpDeleteOne
  1564. return &MessageRecordsDeleteOne{builder}
  1565. }
  1566. // Query returns a query builder for MessageRecords.
  1567. func (c *MessageRecordsClient) Query() *MessageRecordsQuery {
  1568. return &MessageRecordsQuery{
  1569. config: c.config,
  1570. ctx: &QueryContext{Type: TypeMessageRecords},
  1571. inters: c.Interceptors(),
  1572. }
  1573. }
  1574. // Get returns a MessageRecords entity by its id.
  1575. func (c *MessageRecordsClient) Get(ctx context.Context, id uint64) (*MessageRecords, error) {
  1576. return c.Query().Where(messagerecords.ID(id)).Only(ctx)
  1577. }
  1578. // GetX is like Get, but panics if an error occurs.
  1579. func (c *MessageRecordsClient) GetX(ctx context.Context, id uint64) *MessageRecords {
  1580. obj, err := c.Get(ctx, id)
  1581. if err != nil {
  1582. panic(err)
  1583. }
  1584. return obj
  1585. }
  1586. // QuerySopStage queries the sop_stage edge of a MessageRecords.
  1587. func (c *MessageRecordsClient) QuerySopStage(mr *MessageRecords) *SopStageQuery {
  1588. query := (&SopStageClient{config: c.config}).Query()
  1589. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1590. id := mr.ID
  1591. step := sqlgraph.NewStep(
  1592. sqlgraph.From(messagerecords.Table, messagerecords.FieldID, id),
  1593. sqlgraph.To(sopstage.Table, sopstage.FieldID),
  1594. sqlgraph.Edge(sqlgraph.M2O, true, messagerecords.SopStageTable, messagerecords.SopStageColumn),
  1595. )
  1596. fromV = sqlgraph.Neighbors(mr.driver.Dialect(), step)
  1597. return fromV, nil
  1598. }
  1599. return query
  1600. }
  1601. // QuerySopNode queries the sop_node edge of a MessageRecords.
  1602. func (c *MessageRecordsClient) QuerySopNode(mr *MessageRecords) *SopNodeQuery {
  1603. query := (&SopNodeClient{config: c.config}).Query()
  1604. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1605. id := mr.ID
  1606. step := sqlgraph.NewStep(
  1607. sqlgraph.From(messagerecords.Table, messagerecords.FieldID, id),
  1608. sqlgraph.To(sopnode.Table, sopnode.FieldID),
  1609. sqlgraph.Edge(sqlgraph.M2O, true, messagerecords.SopNodeTable, messagerecords.SopNodeColumn),
  1610. )
  1611. fromV = sqlgraph.Neighbors(mr.driver.Dialect(), step)
  1612. return fromV, nil
  1613. }
  1614. return query
  1615. }
  1616. // QueryMessageContact queries the message_contact edge of a MessageRecords.
  1617. func (c *MessageRecordsClient) QueryMessageContact(mr *MessageRecords) *ContactQuery {
  1618. query := (&ContactClient{config: c.config}).Query()
  1619. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1620. id := mr.ID
  1621. step := sqlgraph.NewStep(
  1622. sqlgraph.From(messagerecords.Table, messagerecords.FieldID, id),
  1623. sqlgraph.To(contact.Table, contact.FieldID),
  1624. sqlgraph.Edge(sqlgraph.M2O, true, messagerecords.MessageContactTable, messagerecords.MessageContactColumn),
  1625. )
  1626. fromV = sqlgraph.Neighbors(mr.driver.Dialect(), step)
  1627. return fromV, nil
  1628. }
  1629. return query
  1630. }
  1631. // Hooks returns the client hooks.
  1632. func (c *MessageRecordsClient) Hooks() []Hook {
  1633. hooks := c.hooks.MessageRecords
  1634. return append(hooks[:len(hooks):len(hooks)], messagerecords.Hooks[:]...)
  1635. }
  1636. // Interceptors returns the client interceptors.
  1637. func (c *MessageRecordsClient) Interceptors() []Interceptor {
  1638. inters := c.inters.MessageRecords
  1639. return append(inters[:len(inters):len(inters)], messagerecords.Interceptors[:]...)
  1640. }
  1641. func (c *MessageRecordsClient) mutate(ctx context.Context, m *MessageRecordsMutation) (Value, error) {
  1642. switch m.Op() {
  1643. case OpCreate:
  1644. return (&MessageRecordsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1645. case OpUpdate:
  1646. return (&MessageRecordsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1647. case OpUpdateOne:
  1648. return (&MessageRecordsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1649. case OpDelete, OpDeleteOne:
  1650. return (&MessageRecordsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1651. default:
  1652. return nil, fmt.Errorf("ent: unknown MessageRecords mutation op: %q", m.Op())
  1653. }
  1654. }
  1655. // MsgClient is a client for the Msg schema.
  1656. type MsgClient struct {
  1657. config
  1658. }
  1659. // NewMsgClient returns a client for the Msg from the given config.
  1660. func NewMsgClient(c config) *MsgClient {
  1661. return &MsgClient{config: c}
  1662. }
  1663. // Use adds a list of mutation hooks to the hooks stack.
  1664. // A call to `Use(f, g, h)` equals to `msg.Hooks(f(g(h())))`.
  1665. func (c *MsgClient) Use(hooks ...Hook) {
  1666. c.hooks.Msg = append(c.hooks.Msg, hooks...)
  1667. }
  1668. // Intercept adds a list of query interceptors to the interceptors stack.
  1669. // A call to `Intercept(f, g, h)` equals to `msg.Intercept(f(g(h())))`.
  1670. func (c *MsgClient) Intercept(interceptors ...Interceptor) {
  1671. c.inters.Msg = append(c.inters.Msg, interceptors...)
  1672. }
  1673. // Create returns a builder for creating a Msg entity.
  1674. func (c *MsgClient) Create() *MsgCreate {
  1675. mutation := newMsgMutation(c.config, OpCreate)
  1676. return &MsgCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1677. }
  1678. // CreateBulk returns a builder for creating a bulk of Msg entities.
  1679. func (c *MsgClient) CreateBulk(builders ...*MsgCreate) *MsgCreateBulk {
  1680. return &MsgCreateBulk{config: c.config, builders: builders}
  1681. }
  1682. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1683. // a builder and applies setFunc on it.
  1684. func (c *MsgClient) MapCreateBulk(slice any, setFunc func(*MsgCreate, int)) *MsgCreateBulk {
  1685. rv := reflect.ValueOf(slice)
  1686. if rv.Kind() != reflect.Slice {
  1687. return &MsgCreateBulk{err: fmt.Errorf("calling to MsgClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1688. }
  1689. builders := make([]*MsgCreate, rv.Len())
  1690. for i := 0; i < rv.Len(); i++ {
  1691. builders[i] = c.Create()
  1692. setFunc(builders[i], i)
  1693. }
  1694. return &MsgCreateBulk{config: c.config, builders: builders}
  1695. }
  1696. // Update returns an update builder for Msg.
  1697. func (c *MsgClient) Update() *MsgUpdate {
  1698. mutation := newMsgMutation(c.config, OpUpdate)
  1699. return &MsgUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1700. }
  1701. // UpdateOne returns an update builder for the given entity.
  1702. func (c *MsgClient) UpdateOne(m *Msg) *MsgUpdateOne {
  1703. mutation := newMsgMutation(c.config, OpUpdateOne, withMsg(m))
  1704. return &MsgUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1705. }
  1706. // UpdateOneID returns an update builder for the given id.
  1707. func (c *MsgClient) UpdateOneID(id uint64) *MsgUpdateOne {
  1708. mutation := newMsgMutation(c.config, OpUpdateOne, withMsgID(id))
  1709. return &MsgUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1710. }
  1711. // Delete returns a delete builder for Msg.
  1712. func (c *MsgClient) Delete() *MsgDelete {
  1713. mutation := newMsgMutation(c.config, OpDelete)
  1714. return &MsgDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1715. }
  1716. // DeleteOne returns a builder for deleting the given entity.
  1717. func (c *MsgClient) DeleteOne(m *Msg) *MsgDeleteOne {
  1718. return c.DeleteOneID(m.ID)
  1719. }
  1720. // DeleteOneID returns a builder for deleting the given entity by its id.
  1721. func (c *MsgClient) DeleteOneID(id uint64) *MsgDeleteOne {
  1722. builder := c.Delete().Where(msg.ID(id))
  1723. builder.mutation.id = &id
  1724. builder.mutation.op = OpDeleteOne
  1725. return &MsgDeleteOne{builder}
  1726. }
  1727. // Query returns a query builder for Msg.
  1728. func (c *MsgClient) Query() *MsgQuery {
  1729. return &MsgQuery{
  1730. config: c.config,
  1731. ctx: &QueryContext{Type: TypeMsg},
  1732. inters: c.Interceptors(),
  1733. }
  1734. }
  1735. // Get returns a Msg entity by its id.
  1736. func (c *MsgClient) Get(ctx context.Context, id uint64) (*Msg, error) {
  1737. return c.Query().Where(msg.ID(id)).Only(ctx)
  1738. }
  1739. // GetX is like Get, but panics if an error occurs.
  1740. func (c *MsgClient) GetX(ctx context.Context, id uint64) *Msg {
  1741. obj, err := c.Get(ctx, id)
  1742. if err != nil {
  1743. panic(err)
  1744. }
  1745. return obj
  1746. }
  1747. // Hooks returns the client hooks.
  1748. func (c *MsgClient) Hooks() []Hook {
  1749. hooks := c.hooks.Msg
  1750. return append(hooks[:len(hooks):len(hooks)], msg.Hooks[:]...)
  1751. }
  1752. // Interceptors returns the client interceptors.
  1753. func (c *MsgClient) Interceptors() []Interceptor {
  1754. inters := c.inters.Msg
  1755. return append(inters[:len(inters):len(inters)], msg.Interceptors[:]...)
  1756. }
  1757. func (c *MsgClient) mutate(ctx context.Context, m *MsgMutation) (Value, error) {
  1758. switch m.Op() {
  1759. case OpCreate:
  1760. return (&MsgCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1761. case OpUpdate:
  1762. return (&MsgUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1763. case OpUpdateOne:
  1764. return (&MsgUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1765. case OpDelete, OpDeleteOne:
  1766. return (&MsgDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1767. default:
  1768. return nil, fmt.Errorf("ent: unknown Msg mutation op: %q", m.Op())
  1769. }
  1770. }
  1771. // ServerClient is a client for the Server schema.
  1772. type ServerClient struct {
  1773. config
  1774. }
  1775. // NewServerClient returns a client for the Server from the given config.
  1776. func NewServerClient(c config) *ServerClient {
  1777. return &ServerClient{config: c}
  1778. }
  1779. // Use adds a list of mutation hooks to the hooks stack.
  1780. // A call to `Use(f, g, h)` equals to `server.Hooks(f(g(h())))`.
  1781. func (c *ServerClient) Use(hooks ...Hook) {
  1782. c.hooks.Server = append(c.hooks.Server, hooks...)
  1783. }
  1784. // Intercept adds a list of query interceptors to the interceptors stack.
  1785. // A call to `Intercept(f, g, h)` equals to `server.Intercept(f(g(h())))`.
  1786. func (c *ServerClient) Intercept(interceptors ...Interceptor) {
  1787. c.inters.Server = append(c.inters.Server, interceptors...)
  1788. }
  1789. // Create returns a builder for creating a Server entity.
  1790. func (c *ServerClient) Create() *ServerCreate {
  1791. mutation := newServerMutation(c.config, OpCreate)
  1792. return &ServerCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1793. }
  1794. // CreateBulk returns a builder for creating a bulk of Server entities.
  1795. func (c *ServerClient) CreateBulk(builders ...*ServerCreate) *ServerCreateBulk {
  1796. return &ServerCreateBulk{config: c.config, builders: builders}
  1797. }
  1798. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1799. // a builder and applies setFunc on it.
  1800. func (c *ServerClient) MapCreateBulk(slice any, setFunc func(*ServerCreate, int)) *ServerCreateBulk {
  1801. rv := reflect.ValueOf(slice)
  1802. if rv.Kind() != reflect.Slice {
  1803. return &ServerCreateBulk{err: fmt.Errorf("calling to ServerClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1804. }
  1805. builders := make([]*ServerCreate, rv.Len())
  1806. for i := 0; i < rv.Len(); i++ {
  1807. builders[i] = c.Create()
  1808. setFunc(builders[i], i)
  1809. }
  1810. return &ServerCreateBulk{config: c.config, builders: builders}
  1811. }
  1812. // Update returns an update builder for Server.
  1813. func (c *ServerClient) Update() *ServerUpdate {
  1814. mutation := newServerMutation(c.config, OpUpdate)
  1815. return &ServerUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1816. }
  1817. // UpdateOne returns an update builder for the given entity.
  1818. func (c *ServerClient) UpdateOne(s *Server) *ServerUpdateOne {
  1819. mutation := newServerMutation(c.config, OpUpdateOne, withServer(s))
  1820. return &ServerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1821. }
  1822. // UpdateOneID returns an update builder for the given id.
  1823. func (c *ServerClient) UpdateOneID(id uint64) *ServerUpdateOne {
  1824. mutation := newServerMutation(c.config, OpUpdateOne, withServerID(id))
  1825. return &ServerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1826. }
  1827. // Delete returns a delete builder for Server.
  1828. func (c *ServerClient) Delete() *ServerDelete {
  1829. mutation := newServerMutation(c.config, OpDelete)
  1830. return &ServerDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1831. }
  1832. // DeleteOne returns a builder for deleting the given entity.
  1833. func (c *ServerClient) DeleteOne(s *Server) *ServerDeleteOne {
  1834. return c.DeleteOneID(s.ID)
  1835. }
  1836. // DeleteOneID returns a builder for deleting the given entity by its id.
  1837. func (c *ServerClient) DeleteOneID(id uint64) *ServerDeleteOne {
  1838. builder := c.Delete().Where(server.ID(id))
  1839. builder.mutation.id = &id
  1840. builder.mutation.op = OpDeleteOne
  1841. return &ServerDeleteOne{builder}
  1842. }
  1843. // Query returns a query builder for Server.
  1844. func (c *ServerClient) Query() *ServerQuery {
  1845. return &ServerQuery{
  1846. config: c.config,
  1847. ctx: &QueryContext{Type: TypeServer},
  1848. inters: c.Interceptors(),
  1849. }
  1850. }
  1851. // Get returns a Server entity by its id.
  1852. func (c *ServerClient) Get(ctx context.Context, id uint64) (*Server, error) {
  1853. return c.Query().Where(server.ID(id)).Only(ctx)
  1854. }
  1855. // GetX is like Get, but panics if an error occurs.
  1856. func (c *ServerClient) GetX(ctx context.Context, id uint64) *Server {
  1857. obj, err := c.Get(ctx, id)
  1858. if err != nil {
  1859. panic(err)
  1860. }
  1861. return obj
  1862. }
  1863. // QueryWxs queries the wxs edge of a Server.
  1864. func (c *ServerClient) QueryWxs(s *Server) *WxQuery {
  1865. query := (&WxClient{config: c.config}).Query()
  1866. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1867. id := s.ID
  1868. step := sqlgraph.NewStep(
  1869. sqlgraph.From(server.Table, server.FieldID, id),
  1870. sqlgraph.To(wx.Table, wx.FieldID),
  1871. sqlgraph.Edge(sqlgraph.O2M, false, server.WxsTable, server.WxsColumn),
  1872. )
  1873. fromV = sqlgraph.Neighbors(s.driver.Dialect(), step)
  1874. return fromV, nil
  1875. }
  1876. return query
  1877. }
  1878. // Hooks returns the client hooks.
  1879. func (c *ServerClient) Hooks() []Hook {
  1880. hooks := c.hooks.Server
  1881. return append(hooks[:len(hooks):len(hooks)], server.Hooks[:]...)
  1882. }
  1883. // Interceptors returns the client interceptors.
  1884. func (c *ServerClient) Interceptors() []Interceptor {
  1885. inters := c.inters.Server
  1886. return append(inters[:len(inters):len(inters)], server.Interceptors[:]...)
  1887. }
  1888. func (c *ServerClient) mutate(ctx context.Context, m *ServerMutation) (Value, error) {
  1889. switch m.Op() {
  1890. case OpCreate:
  1891. return (&ServerCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1892. case OpUpdate:
  1893. return (&ServerUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1894. case OpUpdateOne:
  1895. return (&ServerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  1896. case OpDelete, OpDeleteOne:
  1897. return (&ServerDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  1898. default:
  1899. return nil, fmt.Errorf("ent: unknown Server mutation op: %q", m.Op())
  1900. }
  1901. }
  1902. // SopNodeClient is a client for the SopNode schema.
  1903. type SopNodeClient struct {
  1904. config
  1905. }
  1906. // NewSopNodeClient returns a client for the SopNode from the given config.
  1907. func NewSopNodeClient(c config) *SopNodeClient {
  1908. return &SopNodeClient{config: c}
  1909. }
  1910. // Use adds a list of mutation hooks to the hooks stack.
  1911. // A call to `Use(f, g, h)` equals to `sopnode.Hooks(f(g(h())))`.
  1912. func (c *SopNodeClient) Use(hooks ...Hook) {
  1913. c.hooks.SopNode = append(c.hooks.SopNode, hooks...)
  1914. }
  1915. // Intercept adds a list of query interceptors to the interceptors stack.
  1916. // A call to `Intercept(f, g, h)` equals to `sopnode.Intercept(f(g(h())))`.
  1917. func (c *SopNodeClient) Intercept(interceptors ...Interceptor) {
  1918. c.inters.SopNode = append(c.inters.SopNode, interceptors...)
  1919. }
  1920. // Create returns a builder for creating a SopNode entity.
  1921. func (c *SopNodeClient) Create() *SopNodeCreate {
  1922. mutation := newSopNodeMutation(c.config, OpCreate)
  1923. return &SopNodeCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1924. }
  1925. // CreateBulk returns a builder for creating a bulk of SopNode entities.
  1926. func (c *SopNodeClient) CreateBulk(builders ...*SopNodeCreate) *SopNodeCreateBulk {
  1927. return &SopNodeCreateBulk{config: c.config, builders: builders}
  1928. }
  1929. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  1930. // a builder and applies setFunc on it.
  1931. func (c *SopNodeClient) MapCreateBulk(slice any, setFunc func(*SopNodeCreate, int)) *SopNodeCreateBulk {
  1932. rv := reflect.ValueOf(slice)
  1933. if rv.Kind() != reflect.Slice {
  1934. return &SopNodeCreateBulk{err: fmt.Errorf("calling to SopNodeClient.MapCreateBulk with wrong type %T, need slice", slice)}
  1935. }
  1936. builders := make([]*SopNodeCreate, rv.Len())
  1937. for i := 0; i < rv.Len(); i++ {
  1938. builders[i] = c.Create()
  1939. setFunc(builders[i], i)
  1940. }
  1941. return &SopNodeCreateBulk{config: c.config, builders: builders}
  1942. }
  1943. // Update returns an update builder for SopNode.
  1944. func (c *SopNodeClient) Update() *SopNodeUpdate {
  1945. mutation := newSopNodeMutation(c.config, OpUpdate)
  1946. return &SopNodeUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1947. }
  1948. // UpdateOne returns an update builder for the given entity.
  1949. func (c *SopNodeClient) UpdateOne(sn *SopNode) *SopNodeUpdateOne {
  1950. mutation := newSopNodeMutation(c.config, OpUpdateOne, withSopNode(sn))
  1951. return &SopNodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1952. }
  1953. // UpdateOneID returns an update builder for the given id.
  1954. func (c *SopNodeClient) UpdateOneID(id uint64) *SopNodeUpdateOne {
  1955. mutation := newSopNodeMutation(c.config, OpUpdateOne, withSopNodeID(id))
  1956. return &SopNodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1957. }
  1958. // Delete returns a delete builder for SopNode.
  1959. func (c *SopNodeClient) Delete() *SopNodeDelete {
  1960. mutation := newSopNodeMutation(c.config, OpDelete)
  1961. return &SopNodeDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  1962. }
  1963. // DeleteOne returns a builder for deleting the given entity.
  1964. func (c *SopNodeClient) DeleteOne(sn *SopNode) *SopNodeDeleteOne {
  1965. return c.DeleteOneID(sn.ID)
  1966. }
  1967. // DeleteOneID returns a builder for deleting the given entity by its id.
  1968. func (c *SopNodeClient) DeleteOneID(id uint64) *SopNodeDeleteOne {
  1969. builder := c.Delete().Where(sopnode.ID(id))
  1970. builder.mutation.id = &id
  1971. builder.mutation.op = OpDeleteOne
  1972. return &SopNodeDeleteOne{builder}
  1973. }
  1974. // Query returns a query builder for SopNode.
  1975. func (c *SopNodeClient) Query() *SopNodeQuery {
  1976. return &SopNodeQuery{
  1977. config: c.config,
  1978. ctx: &QueryContext{Type: TypeSopNode},
  1979. inters: c.Interceptors(),
  1980. }
  1981. }
  1982. // Get returns a SopNode entity by its id.
  1983. func (c *SopNodeClient) Get(ctx context.Context, id uint64) (*SopNode, error) {
  1984. return c.Query().Where(sopnode.ID(id)).Only(ctx)
  1985. }
  1986. // GetX is like Get, but panics if an error occurs.
  1987. func (c *SopNodeClient) GetX(ctx context.Context, id uint64) *SopNode {
  1988. obj, err := c.Get(ctx, id)
  1989. if err != nil {
  1990. panic(err)
  1991. }
  1992. return obj
  1993. }
  1994. // QuerySopStage queries the sop_stage edge of a SopNode.
  1995. func (c *SopNodeClient) QuerySopStage(sn *SopNode) *SopStageQuery {
  1996. query := (&SopStageClient{config: c.config}).Query()
  1997. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  1998. id := sn.ID
  1999. step := sqlgraph.NewStep(
  2000. sqlgraph.From(sopnode.Table, sopnode.FieldID, id),
  2001. sqlgraph.To(sopstage.Table, sopstage.FieldID),
  2002. sqlgraph.Edge(sqlgraph.M2O, true, sopnode.SopStageTable, sopnode.SopStageColumn),
  2003. )
  2004. fromV = sqlgraph.Neighbors(sn.driver.Dialect(), step)
  2005. return fromV, nil
  2006. }
  2007. return query
  2008. }
  2009. // QueryNodeMessages queries the node_messages edge of a SopNode.
  2010. func (c *SopNodeClient) QueryNodeMessages(sn *SopNode) *MessageRecordsQuery {
  2011. query := (&MessageRecordsClient{config: c.config}).Query()
  2012. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  2013. id := sn.ID
  2014. step := sqlgraph.NewStep(
  2015. sqlgraph.From(sopnode.Table, sopnode.FieldID, id),
  2016. sqlgraph.To(messagerecords.Table, messagerecords.FieldID),
  2017. sqlgraph.Edge(sqlgraph.O2M, false, sopnode.NodeMessagesTable, sopnode.NodeMessagesColumn),
  2018. )
  2019. fromV = sqlgraph.Neighbors(sn.driver.Dialect(), step)
  2020. return fromV, nil
  2021. }
  2022. return query
  2023. }
  2024. // Hooks returns the client hooks.
  2025. func (c *SopNodeClient) Hooks() []Hook {
  2026. hooks := c.hooks.SopNode
  2027. return append(hooks[:len(hooks):len(hooks)], sopnode.Hooks[:]...)
  2028. }
  2029. // Interceptors returns the client interceptors.
  2030. func (c *SopNodeClient) Interceptors() []Interceptor {
  2031. inters := c.inters.SopNode
  2032. return append(inters[:len(inters):len(inters)], sopnode.Interceptors[:]...)
  2033. }
  2034. func (c *SopNodeClient) mutate(ctx context.Context, m *SopNodeMutation) (Value, error) {
  2035. switch m.Op() {
  2036. case OpCreate:
  2037. return (&SopNodeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2038. case OpUpdate:
  2039. return (&SopNodeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2040. case OpUpdateOne:
  2041. return (&SopNodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2042. case OpDelete, OpDeleteOne:
  2043. return (&SopNodeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  2044. default:
  2045. return nil, fmt.Errorf("ent: unknown SopNode mutation op: %q", m.Op())
  2046. }
  2047. }
  2048. // SopStageClient is a client for the SopStage schema.
  2049. type SopStageClient struct {
  2050. config
  2051. }
  2052. // NewSopStageClient returns a client for the SopStage from the given config.
  2053. func NewSopStageClient(c config) *SopStageClient {
  2054. return &SopStageClient{config: c}
  2055. }
  2056. // Use adds a list of mutation hooks to the hooks stack.
  2057. // A call to `Use(f, g, h)` equals to `sopstage.Hooks(f(g(h())))`.
  2058. func (c *SopStageClient) Use(hooks ...Hook) {
  2059. c.hooks.SopStage = append(c.hooks.SopStage, hooks...)
  2060. }
  2061. // Intercept adds a list of query interceptors to the interceptors stack.
  2062. // A call to `Intercept(f, g, h)` equals to `sopstage.Intercept(f(g(h())))`.
  2063. func (c *SopStageClient) Intercept(interceptors ...Interceptor) {
  2064. c.inters.SopStage = append(c.inters.SopStage, interceptors...)
  2065. }
  2066. // Create returns a builder for creating a SopStage entity.
  2067. func (c *SopStageClient) Create() *SopStageCreate {
  2068. mutation := newSopStageMutation(c.config, OpCreate)
  2069. return &SopStageCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2070. }
  2071. // CreateBulk returns a builder for creating a bulk of SopStage entities.
  2072. func (c *SopStageClient) CreateBulk(builders ...*SopStageCreate) *SopStageCreateBulk {
  2073. return &SopStageCreateBulk{config: c.config, builders: builders}
  2074. }
  2075. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  2076. // a builder and applies setFunc on it.
  2077. func (c *SopStageClient) MapCreateBulk(slice any, setFunc func(*SopStageCreate, int)) *SopStageCreateBulk {
  2078. rv := reflect.ValueOf(slice)
  2079. if rv.Kind() != reflect.Slice {
  2080. return &SopStageCreateBulk{err: fmt.Errorf("calling to SopStageClient.MapCreateBulk with wrong type %T, need slice", slice)}
  2081. }
  2082. builders := make([]*SopStageCreate, rv.Len())
  2083. for i := 0; i < rv.Len(); i++ {
  2084. builders[i] = c.Create()
  2085. setFunc(builders[i], i)
  2086. }
  2087. return &SopStageCreateBulk{config: c.config, builders: builders}
  2088. }
  2089. // Update returns an update builder for SopStage.
  2090. func (c *SopStageClient) Update() *SopStageUpdate {
  2091. mutation := newSopStageMutation(c.config, OpUpdate)
  2092. return &SopStageUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2093. }
  2094. // UpdateOne returns an update builder for the given entity.
  2095. func (c *SopStageClient) UpdateOne(ss *SopStage) *SopStageUpdateOne {
  2096. mutation := newSopStageMutation(c.config, OpUpdateOne, withSopStage(ss))
  2097. return &SopStageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2098. }
  2099. // UpdateOneID returns an update builder for the given id.
  2100. func (c *SopStageClient) UpdateOneID(id uint64) *SopStageUpdateOne {
  2101. mutation := newSopStageMutation(c.config, OpUpdateOne, withSopStageID(id))
  2102. return &SopStageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2103. }
  2104. // Delete returns a delete builder for SopStage.
  2105. func (c *SopStageClient) Delete() *SopStageDelete {
  2106. mutation := newSopStageMutation(c.config, OpDelete)
  2107. return &SopStageDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2108. }
  2109. // DeleteOne returns a builder for deleting the given entity.
  2110. func (c *SopStageClient) DeleteOne(ss *SopStage) *SopStageDeleteOne {
  2111. return c.DeleteOneID(ss.ID)
  2112. }
  2113. // DeleteOneID returns a builder for deleting the given entity by its id.
  2114. func (c *SopStageClient) DeleteOneID(id uint64) *SopStageDeleteOne {
  2115. builder := c.Delete().Where(sopstage.ID(id))
  2116. builder.mutation.id = &id
  2117. builder.mutation.op = OpDeleteOne
  2118. return &SopStageDeleteOne{builder}
  2119. }
  2120. // Query returns a query builder for SopStage.
  2121. func (c *SopStageClient) Query() *SopStageQuery {
  2122. return &SopStageQuery{
  2123. config: c.config,
  2124. ctx: &QueryContext{Type: TypeSopStage},
  2125. inters: c.Interceptors(),
  2126. }
  2127. }
  2128. // Get returns a SopStage entity by its id.
  2129. func (c *SopStageClient) Get(ctx context.Context, id uint64) (*SopStage, error) {
  2130. return c.Query().Where(sopstage.ID(id)).Only(ctx)
  2131. }
  2132. // GetX is like Get, but panics if an error occurs.
  2133. func (c *SopStageClient) GetX(ctx context.Context, id uint64) *SopStage {
  2134. obj, err := c.Get(ctx, id)
  2135. if err != nil {
  2136. panic(err)
  2137. }
  2138. return obj
  2139. }
  2140. // QuerySopTask queries the sop_task edge of a SopStage.
  2141. func (c *SopStageClient) QuerySopTask(ss *SopStage) *SopTaskQuery {
  2142. query := (&SopTaskClient{config: c.config}).Query()
  2143. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  2144. id := ss.ID
  2145. step := sqlgraph.NewStep(
  2146. sqlgraph.From(sopstage.Table, sopstage.FieldID, id),
  2147. sqlgraph.To(soptask.Table, soptask.FieldID),
  2148. sqlgraph.Edge(sqlgraph.M2O, true, sopstage.SopTaskTable, sopstage.SopTaskColumn),
  2149. )
  2150. fromV = sqlgraph.Neighbors(ss.driver.Dialect(), step)
  2151. return fromV, nil
  2152. }
  2153. return query
  2154. }
  2155. // QueryStageNodes queries the stage_nodes edge of a SopStage.
  2156. func (c *SopStageClient) QueryStageNodes(ss *SopStage) *SopNodeQuery {
  2157. query := (&SopNodeClient{config: c.config}).Query()
  2158. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  2159. id := ss.ID
  2160. step := sqlgraph.NewStep(
  2161. sqlgraph.From(sopstage.Table, sopstage.FieldID, id),
  2162. sqlgraph.To(sopnode.Table, sopnode.FieldID),
  2163. sqlgraph.Edge(sqlgraph.O2M, false, sopstage.StageNodesTable, sopstage.StageNodesColumn),
  2164. )
  2165. fromV = sqlgraph.Neighbors(ss.driver.Dialect(), step)
  2166. return fromV, nil
  2167. }
  2168. return query
  2169. }
  2170. // QueryStageMessages queries the stage_messages edge of a SopStage.
  2171. func (c *SopStageClient) QueryStageMessages(ss *SopStage) *MessageRecordsQuery {
  2172. query := (&MessageRecordsClient{config: c.config}).Query()
  2173. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  2174. id := ss.ID
  2175. step := sqlgraph.NewStep(
  2176. sqlgraph.From(sopstage.Table, sopstage.FieldID, id),
  2177. sqlgraph.To(messagerecords.Table, messagerecords.FieldID),
  2178. sqlgraph.Edge(sqlgraph.O2M, false, sopstage.StageMessagesTable, sopstage.StageMessagesColumn),
  2179. )
  2180. fromV = sqlgraph.Neighbors(ss.driver.Dialect(), step)
  2181. return fromV, nil
  2182. }
  2183. return query
  2184. }
  2185. // Hooks returns the client hooks.
  2186. func (c *SopStageClient) Hooks() []Hook {
  2187. hooks := c.hooks.SopStage
  2188. return append(hooks[:len(hooks):len(hooks)], sopstage.Hooks[:]...)
  2189. }
  2190. // Interceptors returns the client interceptors.
  2191. func (c *SopStageClient) Interceptors() []Interceptor {
  2192. inters := c.inters.SopStage
  2193. return append(inters[:len(inters):len(inters)], sopstage.Interceptors[:]...)
  2194. }
  2195. func (c *SopStageClient) mutate(ctx context.Context, m *SopStageMutation) (Value, error) {
  2196. switch m.Op() {
  2197. case OpCreate:
  2198. return (&SopStageCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2199. case OpUpdate:
  2200. return (&SopStageUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2201. case OpUpdateOne:
  2202. return (&SopStageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2203. case OpDelete, OpDeleteOne:
  2204. return (&SopStageDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  2205. default:
  2206. return nil, fmt.Errorf("ent: unknown SopStage mutation op: %q", m.Op())
  2207. }
  2208. }
  2209. // SopTaskClient is a client for the SopTask schema.
  2210. type SopTaskClient struct {
  2211. config
  2212. }
  2213. // NewSopTaskClient returns a client for the SopTask from the given config.
  2214. func NewSopTaskClient(c config) *SopTaskClient {
  2215. return &SopTaskClient{config: c}
  2216. }
  2217. // Use adds a list of mutation hooks to the hooks stack.
  2218. // A call to `Use(f, g, h)` equals to `soptask.Hooks(f(g(h())))`.
  2219. func (c *SopTaskClient) Use(hooks ...Hook) {
  2220. c.hooks.SopTask = append(c.hooks.SopTask, hooks...)
  2221. }
  2222. // Intercept adds a list of query interceptors to the interceptors stack.
  2223. // A call to `Intercept(f, g, h)` equals to `soptask.Intercept(f(g(h())))`.
  2224. func (c *SopTaskClient) Intercept(interceptors ...Interceptor) {
  2225. c.inters.SopTask = append(c.inters.SopTask, interceptors...)
  2226. }
  2227. // Create returns a builder for creating a SopTask entity.
  2228. func (c *SopTaskClient) Create() *SopTaskCreate {
  2229. mutation := newSopTaskMutation(c.config, OpCreate)
  2230. return &SopTaskCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2231. }
  2232. // CreateBulk returns a builder for creating a bulk of SopTask entities.
  2233. func (c *SopTaskClient) CreateBulk(builders ...*SopTaskCreate) *SopTaskCreateBulk {
  2234. return &SopTaskCreateBulk{config: c.config, builders: builders}
  2235. }
  2236. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  2237. // a builder and applies setFunc on it.
  2238. func (c *SopTaskClient) MapCreateBulk(slice any, setFunc func(*SopTaskCreate, int)) *SopTaskCreateBulk {
  2239. rv := reflect.ValueOf(slice)
  2240. if rv.Kind() != reflect.Slice {
  2241. return &SopTaskCreateBulk{err: fmt.Errorf("calling to SopTaskClient.MapCreateBulk with wrong type %T, need slice", slice)}
  2242. }
  2243. builders := make([]*SopTaskCreate, rv.Len())
  2244. for i := 0; i < rv.Len(); i++ {
  2245. builders[i] = c.Create()
  2246. setFunc(builders[i], i)
  2247. }
  2248. return &SopTaskCreateBulk{config: c.config, builders: builders}
  2249. }
  2250. // Update returns an update builder for SopTask.
  2251. func (c *SopTaskClient) Update() *SopTaskUpdate {
  2252. mutation := newSopTaskMutation(c.config, OpUpdate)
  2253. return &SopTaskUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2254. }
  2255. // UpdateOne returns an update builder for the given entity.
  2256. func (c *SopTaskClient) UpdateOne(st *SopTask) *SopTaskUpdateOne {
  2257. mutation := newSopTaskMutation(c.config, OpUpdateOne, withSopTask(st))
  2258. return &SopTaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2259. }
  2260. // UpdateOneID returns an update builder for the given id.
  2261. func (c *SopTaskClient) UpdateOneID(id uint64) *SopTaskUpdateOne {
  2262. mutation := newSopTaskMutation(c.config, OpUpdateOne, withSopTaskID(id))
  2263. return &SopTaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2264. }
  2265. // Delete returns a delete builder for SopTask.
  2266. func (c *SopTaskClient) Delete() *SopTaskDelete {
  2267. mutation := newSopTaskMutation(c.config, OpDelete)
  2268. return &SopTaskDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2269. }
  2270. // DeleteOne returns a builder for deleting the given entity.
  2271. func (c *SopTaskClient) DeleteOne(st *SopTask) *SopTaskDeleteOne {
  2272. return c.DeleteOneID(st.ID)
  2273. }
  2274. // DeleteOneID returns a builder for deleting the given entity by its id.
  2275. func (c *SopTaskClient) DeleteOneID(id uint64) *SopTaskDeleteOne {
  2276. builder := c.Delete().Where(soptask.ID(id))
  2277. builder.mutation.id = &id
  2278. builder.mutation.op = OpDeleteOne
  2279. return &SopTaskDeleteOne{builder}
  2280. }
  2281. // Query returns a query builder for SopTask.
  2282. func (c *SopTaskClient) Query() *SopTaskQuery {
  2283. return &SopTaskQuery{
  2284. config: c.config,
  2285. ctx: &QueryContext{Type: TypeSopTask},
  2286. inters: c.Interceptors(),
  2287. }
  2288. }
  2289. // Get returns a SopTask entity by its id.
  2290. func (c *SopTaskClient) Get(ctx context.Context, id uint64) (*SopTask, error) {
  2291. return c.Query().Where(soptask.ID(id)).Only(ctx)
  2292. }
  2293. // GetX is like Get, but panics if an error occurs.
  2294. func (c *SopTaskClient) GetX(ctx context.Context, id uint64) *SopTask {
  2295. obj, err := c.Get(ctx, id)
  2296. if err != nil {
  2297. panic(err)
  2298. }
  2299. return obj
  2300. }
  2301. // QueryTaskStages queries the task_stages edge of a SopTask.
  2302. func (c *SopTaskClient) QueryTaskStages(st *SopTask) *SopStageQuery {
  2303. query := (&SopStageClient{config: c.config}).Query()
  2304. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  2305. id := st.ID
  2306. step := sqlgraph.NewStep(
  2307. sqlgraph.From(soptask.Table, soptask.FieldID, id),
  2308. sqlgraph.To(sopstage.Table, sopstage.FieldID),
  2309. sqlgraph.Edge(sqlgraph.O2M, false, soptask.TaskStagesTable, soptask.TaskStagesColumn),
  2310. )
  2311. fromV = sqlgraph.Neighbors(st.driver.Dialect(), step)
  2312. return fromV, nil
  2313. }
  2314. return query
  2315. }
  2316. // Hooks returns the client hooks.
  2317. func (c *SopTaskClient) Hooks() []Hook {
  2318. hooks := c.hooks.SopTask
  2319. return append(hooks[:len(hooks):len(hooks)], soptask.Hooks[:]...)
  2320. }
  2321. // Interceptors returns the client interceptors.
  2322. func (c *SopTaskClient) Interceptors() []Interceptor {
  2323. inters := c.inters.SopTask
  2324. return append(inters[:len(inters):len(inters)], soptask.Interceptors[:]...)
  2325. }
  2326. func (c *SopTaskClient) mutate(ctx context.Context, m *SopTaskMutation) (Value, error) {
  2327. switch m.Op() {
  2328. case OpCreate:
  2329. return (&SopTaskCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2330. case OpUpdate:
  2331. return (&SopTaskUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2332. case OpUpdateOne:
  2333. return (&SopTaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2334. case OpDelete, OpDeleteOne:
  2335. return (&SopTaskDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  2336. default:
  2337. return nil, fmt.Errorf("ent: unknown SopTask mutation op: %q", m.Op())
  2338. }
  2339. }
  2340. // TokenClient is a client for the Token schema.
  2341. type TokenClient struct {
  2342. config
  2343. }
  2344. // NewTokenClient returns a client for the Token from the given config.
  2345. func NewTokenClient(c config) *TokenClient {
  2346. return &TokenClient{config: c}
  2347. }
  2348. // Use adds a list of mutation hooks to the hooks stack.
  2349. // A call to `Use(f, g, h)` equals to `token.Hooks(f(g(h())))`.
  2350. func (c *TokenClient) Use(hooks ...Hook) {
  2351. c.hooks.Token = append(c.hooks.Token, hooks...)
  2352. }
  2353. // Intercept adds a list of query interceptors to the interceptors stack.
  2354. // A call to `Intercept(f, g, h)` equals to `token.Intercept(f(g(h())))`.
  2355. func (c *TokenClient) Intercept(interceptors ...Interceptor) {
  2356. c.inters.Token = append(c.inters.Token, interceptors...)
  2357. }
  2358. // Create returns a builder for creating a Token entity.
  2359. func (c *TokenClient) Create() *TokenCreate {
  2360. mutation := newTokenMutation(c.config, OpCreate)
  2361. return &TokenCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2362. }
  2363. // CreateBulk returns a builder for creating a bulk of Token entities.
  2364. func (c *TokenClient) CreateBulk(builders ...*TokenCreate) *TokenCreateBulk {
  2365. return &TokenCreateBulk{config: c.config, builders: builders}
  2366. }
  2367. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  2368. // a builder and applies setFunc on it.
  2369. func (c *TokenClient) MapCreateBulk(slice any, setFunc func(*TokenCreate, int)) *TokenCreateBulk {
  2370. rv := reflect.ValueOf(slice)
  2371. if rv.Kind() != reflect.Slice {
  2372. return &TokenCreateBulk{err: fmt.Errorf("calling to TokenClient.MapCreateBulk with wrong type %T, need slice", slice)}
  2373. }
  2374. builders := make([]*TokenCreate, rv.Len())
  2375. for i := 0; i < rv.Len(); i++ {
  2376. builders[i] = c.Create()
  2377. setFunc(builders[i], i)
  2378. }
  2379. return &TokenCreateBulk{config: c.config, builders: builders}
  2380. }
  2381. // Update returns an update builder for Token.
  2382. func (c *TokenClient) Update() *TokenUpdate {
  2383. mutation := newTokenMutation(c.config, OpUpdate)
  2384. return &TokenUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2385. }
  2386. // UpdateOne returns an update builder for the given entity.
  2387. func (c *TokenClient) UpdateOne(t *Token) *TokenUpdateOne {
  2388. mutation := newTokenMutation(c.config, OpUpdateOne, withToken(t))
  2389. return &TokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2390. }
  2391. // UpdateOneID returns an update builder for the given id.
  2392. func (c *TokenClient) UpdateOneID(id uint64) *TokenUpdateOne {
  2393. mutation := newTokenMutation(c.config, OpUpdateOne, withTokenID(id))
  2394. return &TokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2395. }
  2396. // Delete returns a delete builder for Token.
  2397. func (c *TokenClient) Delete() *TokenDelete {
  2398. mutation := newTokenMutation(c.config, OpDelete)
  2399. return &TokenDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2400. }
  2401. // DeleteOne returns a builder for deleting the given entity.
  2402. func (c *TokenClient) DeleteOne(t *Token) *TokenDeleteOne {
  2403. return c.DeleteOneID(t.ID)
  2404. }
  2405. // DeleteOneID returns a builder for deleting the given entity by its id.
  2406. func (c *TokenClient) DeleteOneID(id uint64) *TokenDeleteOne {
  2407. builder := c.Delete().Where(token.ID(id))
  2408. builder.mutation.id = &id
  2409. builder.mutation.op = OpDeleteOne
  2410. return &TokenDeleteOne{builder}
  2411. }
  2412. // Query returns a query builder for Token.
  2413. func (c *TokenClient) Query() *TokenQuery {
  2414. return &TokenQuery{
  2415. config: c.config,
  2416. ctx: &QueryContext{Type: TypeToken},
  2417. inters: c.Interceptors(),
  2418. }
  2419. }
  2420. // Get returns a Token entity by its id.
  2421. func (c *TokenClient) Get(ctx context.Context, id uint64) (*Token, error) {
  2422. return c.Query().Where(token.ID(id)).Only(ctx)
  2423. }
  2424. // GetX is like Get, but panics if an error occurs.
  2425. func (c *TokenClient) GetX(ctx context.Context, id uint64) *Token {
  2426. obj, err := c.Get(ctx, id)
  2427. if err != nil {
  2428. panic(err)
  2429. }
  2430. return obj
  2431. }
  2432. // Hooks returns the client hooks.
  2433. func (c *TokenClient) Hooks() []Hook {
  2434. hooks := c.hooks.Token
  2435. return append(hooks[:len(hooks):len(hooks)], token.Hooks[:]...)
  2436. }
  2437. // Interceptors returns the client interceptors.
  2438. func (c *TokenClient) Interceptors() []Interceptor {
  2439. inters := c.inters.Token
  2440. return append(inters[:len(inters):len(inters)], token.Interceptors[:]...)
  2441. }
  2442. func (c *TokenClient) mutate(ctx context.Context, m *TokenMutation) (Value, error) {
  2443. switch m.Op() {
  2444. case OpCreate:
  2445. return (&TokenCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2446. case OpUpdate:
  2447. return (&TokenUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2448. case OpUpdateOne:
  2449. return (&TokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2450. case OpDelete, OpDeleteOne:
  2451. return (&TokenDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  2452. default:
  2453. return nil, fmt.Errorf("ent: unknown Token mutation op: %q", m.Op())
  2454. }
  2455. }
  2456. // TutorialClient is a client for the Tutorial schema.
  2457. type TutorialClient struct {
  2458. config
  2459. }
  2460. // NewTutorialClient returns a client for the Tutorial from the given config.
  2461. func NewTutorialClient(c config) *TutorialClient {
  2462. return &TutorialClient{config: c}
  2463. }
  2464. // Use adds a list of mutation hooks to the hooks stack.
  2465. // A call to `Use(f, g, h)` equals to `tutorial.Hooks(f(g(h())))`.
  2466. func (c *TutorialClient) Use(hooks ...Hook) {
  2467. c.hooks.Tutorial = append(c.hooks.Tutorial, hooks...)
  2468. }
  2469. // Intercept adds a list of query interceptors to the interceptors stack.
  2470. // A call to `Intercept(f, g, h)` equals to `tutorial.Intercept(f(g(h())))`.
  2471. func (c *TutorialClient) Intercept(interceptors ...Interceptor) {
  2472. c.inters.Tutorial = append(c.inters.Tutorial, interceptors...)
  2473. }
  2474. // Create returns a builder for creating a Tutorial entity.
  2475. func (c *TutorialClient) Create() *TutorialCreate {
  2476. mutation := newTutorialMutation(c.config, OpCreate)
  2477. return &TutorialCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2478. }
  2479. // CreateBulk returns a builder for creating a bulk of Tutorial entities.
  2480. func (c *TutorialClient) CreateBulk(builders ...*TutorialCreate) *TutorialCreateBulk {
  2481. return &TutorialCreateBulk{config: c.config, builders: builders}
  2482. }
  2483. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  2484. // a builder and applies setFunc on it.
  2485. func (c *TutorialClient) MapCreateBulk(slice any, setFunc func(*TutorialCreate, int)) *TutorialCreateBulk {
  2486. rv := reflect.ValueOf(slice)
  2487. if rv.Kind() != reflect.Slice {
  2488. return &TutorialCreateBulk{err: fmt.Errorf("calling to TutorialClient.MapCreateBulk with wrong type %T, need slice", slice)}
  2489. }
  2490. builders := make([]*TutorialCreate, rv.Len())
  2491. for i := 0; i < rv.Len(); i++ {
  2492. builders[i] = c.Create()
  2493. setFunc(builders[i], i)
  2494. }
  2495. return &TutorialCreateBulk{config: c.config, builders: builders}
  2496. }
  2497. // Update returns an update builder for Tutorial.
  2498. func (c *TutorialClient) Update() *TutorialUpdate {
  2499. mutation := newTutorialMutation(c.config, OpUpdate)
  2500. return &TutorialUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2501. }
  2502. // UpdateOne returns an update builder for the given entity.
  2503. func (c *TutorialClient) UpdateOne(t *Tutorial) *TutorialUpdateOne {
  2504. mutation := newTutorialMutation(c.config, OpUpdateOne, withTutorial(t))
  2505. return &TutorialUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2506. }
  2507. // UpdateOneID returns an update builder for the given id.
  2508. func (c *TutorialClient) UpdateOneID(id uint64) *TutorialUpdateOne {
  2509. mutation := newTutorialMutation(c.config, OpUpdateOne, withTutorialID(id))
  2510. return &TutorialUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2511. }
  2512. // Delete returns a delete builder for Tutorial.
  2513. func (c *TutorialClient) Delete() *TutorialDelete {
  2514. mutation := newTutorialMutation(c.config, OpDelete)
  2515. return &TutorialDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2516. }
  2517. // DeleteOne returns a builder for deleting the given entity.
  2518. func (c *TutorialClient) DeleteOne(t *Tutorial) *TutorialDeleteOne {
  2519. return c.DeleteOneID(t.ID)
  2520. }
  2521. // DeleteOneID returns a builder for deleting the given entity by its id.
  2522. func (c *TutorialClient) DeleteOneID(id uint64) *TutorialDeleteOne {
  2523. builder := c.Delete().Where(tutorial.ID(id))
  2524. builder.mutation.id = &id
  2525. builder.mutation.op = OpDeleteOne
  2526. return &TutorialDeleteOne{builder}
  2527. }
  2528. // Query returns a query builder for Tutorial.
  2529. func (c *TutorialClient) Query() *TutorialQuery {
  2530. return &TutorialQuery{
  2531. config: c.config,
  2532. ctx: &QueryContext{Type: TypeTutorial},
  2533. inters: c.Interceptors(),
  2534. }
  2535. }
  2536. // Get returns a Tutorial entity by its id.
  2537. func (c *TutorialClient) Get(ctx context.Context, id uint64) (*Tutorial, error) {
  2538. return c.Query().Where(tutorial.ID(id)).Only(ctx)
  2539. }
  2540. // GetX is like Get, but panics if an error occurs.
  2541. func (c *TutorialClient) GetX(ctx context.Context, id uint64) *Tutorial {
  2542. obj, err := c.Get(ctx, id)
  2543. if err != nil {
  2544. panic(err)
  2545. }
  2546. return obj
  2547. }
  2548. // QueryEmployee queries the employee edge of a Tutorial.
  2549. func (c *TutorialClient) QueryEmployee(t *Tutorial) *EmployeeQuery {
  2550. query := (&EmployeeClient{config: c.config}).Query()
  2551. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  2552. id := t.ID
  2553. step := sqlgraph.NewStep(
  2554. sqlgraph.From(tutorial.Table, tutorial.FieldID, id),
  2555. sqlgraph.To(employee.Table, employee.FieldID),
  2556. sqlgraph.Edge(sqlgraph.M2O, true, tutorial.EmployeeTable, tutorial.EmployeeColumn),
  2557. )
  2558. fromV = sqlgraph.Neighbors(t.driver.Dialect(), step)
  2559. return fromV, nil
  2560. }
  2561. return query
  2562. }
  2563. // Hooks returns the client hooks.
  2564. func (c *TutorialClient) Hooks() []Hook {
  2565. hooks := c.hooks.Tutorial
  2566. return append(hooks[:len(hooks):len(hooks)], tutorial.Hooks[:]...)
  2567. }
  2568. // Interceptors returns the client interceptors.
  2569. func (c *TutorialClient) Interceptors() []Interceptor {
  2570. inters := c.inters.Tutorial
  2571. return append(inters[:len(inters):len(inters)], tutorial.Interceptors[:]...)
  2572. }
  2573. func (c *TutorialClient) mutate(ctx context.Context, m *TutorialMutation) (Value, error) {
  2574. switch m.Op() {
  2575. case OpCreate:
  2576. return (&TutorialCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2577. case OpUpdate:
  2578. return (&TutorialUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2579. case OpUpdateOne:
  2580. return (&TutorialUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2581. case OpDelete, OpDeleteOne:
  2582. return (&TutorialDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  2583. default:
  2584. return nil, fmt.Errorf("ent: unknown Tutorial mutation op: %q", m.Op())
  2585. }
  2586. }
  2587. // WorkExperienceClient is a client for the WorkExperience schema.
  2588. type WorkExperienceClient struct {
  2589. config
  2590. }
  2591. // NewWorkExperienceClient returns a client for the WorkExperience from the given config.
  2592. func NewWorkExperienceClient(c config) *WorkExperienceClient {
  2593. return &WorkExperienceClient{config: c}
  2594. }
  2595. // Use adds a list of mutation hooks to the hooks stack.
  2596. // A call to `Use(f, g, h)` equals to `workexperience.Hooks(f(g(h())))`.
  2597. func (c *WorkExperienceClient) Use(hooks ...Hook) {
  2598. c.hooks.WorkExperience = append(c.hooks.WorkExperience, hooks...)
  2599. }
  2600. // Intercept adds a list of query interceptors to the interceptors stack.
  2601. // A call to `Intercept(f, g, h)` equals to `workexperience.Intercept(f(g(h())))`.
  2602. func (c *WorkExperienceClient) Intercept(interceptors ...Interceptor) {
  2603. c.inters.WorkExperience = append(c.inters.WorkExperience, interceptors...)
  2604. }
  2605. // Create returns a builder for creating a WorkExperience entity.
  2606. func (c *WorkExperienceClient) Create() *WorkExperienceCreate {
  2607. mutation := newWorkExperienceMutation(c.config, OpCreate)
  2608. return &WorkExperienceCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2609. }
  2610. // CreateBulk returns a builder for creating a bulk of WorkExperience entities.
  2611. func (c *WorkExperienceClient) CreateBulk(builders ...*WorkExperienceCreate) *WorkExperienceCreateBulk {
  2612. return &WorkExperienceCreateBulk{config: c.config, builders: builders}
  2613. }
  2614. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  2615. // a builder and applies setFunc on it.
  2616. func (c *WorkExperienceClient) MapCreateBulk(slice any, setFunc func(*WorkExperienceCreate, int)) *WorkExperienceCreateBulk {
  2617. rv := reflect.ValueOf(slice)
  2618. if rv.Kind() != reflect.Slice {
  2619. return &WorkExperienceCreateBulk{err: fmt.Errorf("calling to WorkExperienceClient.MapCreateBulk with wrong type %T, need slice", slice)}
  2620. }
  2621. builders := make([]*WorkExperienceCreate, rv.Len())
  2622. for i := 0; i < rv.Len(); i++ {
  2623. builders[i] = c.Create()
  2624. setFunc(builders[i], i)
  2625. }
  2626. return &WorkExperienceCreateBulk{config: c.config, builders: builders}
  2627. }
  2628. // Update returns an update builder for WorkExperience.
  2629. func (c *WorkExperienceClient) Update() *WorkExperienceUpdate {
  2630. mutation := newWorkExperienceMutation(c.config, OpUpdate)
  2631. return &WorkExperienceUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2632. }
  2633. // UpdateOne returns an update builder for the given entity.
  2634. func (c *WorkExperienceClient) UpdateOne(we *WorkExperience) *WorkExperienceUpdateOne {
  2635. mutation := newWorkExperienceMutation(c.config, OpUpdateOne, withWorkExperience(we))
  2636. return &WorkExperienceUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2637. }
  2638. // UpdateOneID returns an update builder for the given id.
  2639. func (c *WorkExperienceClient) UpdateOneID(id uint64) *WorkExperienceUpdateOne {
  2640. mutation := newWorkExperienceMutation(c.config, OpUpdateOne, withWorkExperienceID(id))
  2641. return &WorkExperienceUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2642. }
  2643. // Delete returns a delete builder for WorkExperience.
  2644. func (c *WorkExperienceClient) Delete() *WorkExperienceDelete {
  2645. mutation := newWorkExperienceMutation(c.config, OpDelete)
  2646. return &WorkExperienceDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2647. }
  2648. // DeleteOne returns a builder for deleting the given entity.
  2649. func (c *WorkExperienceClient) DeleteOne(we *WorkExperience) *WorkExperienceDeleteOne {
  2650. return c.DeleteOneID(we.ID)
  2651. }
  2652. // DeleteOneID returns a builder for deleting the given entity by its id.
  2653. func (c *WorkExperienceClient) DeleteOneID(id uint64) *WorkExperienceDeleteOne {
  2654. builder := c.Delete().Where(workexperience.ID(id))
  2655. builder.mutation.id = &id
  2656. builder.mutation.op = OpDeleteOne
  2657. return &WorkExperienceDeleteOne{builder}
  2658. }
  2659. // Query returns a query builder for WorkExperience.
  2660. func (c *WorkExperienceClient) Query() *WorkExperienceQuery {
  2661. return &WorkExperienceQuery{
  2662. config: c.config,
  2663. ctx: &QueryContext{Type: TypeWorkExperience},
  2664. inters: c.Interceptors(),
  2665. }
  2666. }
  2667. // Get returns a WorkExperience entity by its id.
  2668. func (c *WorkExperienceClient) Get(ctx context.Context, id uint64) (*WorkExperience, error) {
  2669. return c.Query().Where(workexperience.ID(id)).Only(ctx)
  2670. }
  2671. // GetX is like Get, but panics if an error occurs.
  2672. func (c *WorkExperienceClient) GetX(ctx context.Context, id uint64) *WorkExperience {
  2673. obj, err := c.Get(ctx, id)
  2674. if err != nil {
  2675. panic(err)
  2676. }
  2677. return obj
  2678. }
  2679. // QueryEmployee queries the employee edge of a WorkExperience.
  2680. func (c *WorkExperienceClient) QueryEmployee(we *WorkExperience) *EmployeeQuery {
  2681. query := (&EmployeeClient{config: c.config}).Query()
  2682. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  2683. id := we.ID
  2684. step := sqlgraph.NewStep(
  2685. sqlgraph.From(workexperience.Table, workexperience.FieldID, id),
  2686. sqlgraph.To(employee.Table, employee.FieldID),
  2687. sqlgraph.Edge(sqlgraph.M2O, true, workexperience.EmployeeTable, workexperience.EmployeeColumn),
  2688. )
  2689. fromV = sqlgraph.Neighbors(we.driver.Dialect(), step)
  2690. return fromV, nil
  2691. }
  2692. return query
  2693. }
  2694. // Hooks returns the client hooks.
  2695. func (c *WorkExperienceClient) Hooks() []Hook {
  2696. hooks := c.hooks.WorkExperience
  2697. return append(hooks[:len(hooks):len(hooks)], workexperience.Hooks[:]...)
  2698. }
  2699. // Interceptors returns the client interceptors.
  2700. func (c *WorkExperienceClient) Interceptors() []Interceptor {
  2701. inters := c.inters.WorkExperience
  2702. return append(inters[:len(inters):len(inters)], workexperience.Interceptors[:]...)
  2703. }
  2704. func (c *WorkExperienceClient) mutate(ctx context.Context, m *WorkExperienceMutation) (Value, error) {
  2705. switch m.Op() {
  2706. case OpCreate:
  2707. return (&WorkExperienceCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2708. case OpUpdate:
  2709. return (&WorkExperienceUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2710. case OpUpdateOne:
  2711. return (&WorkExperienceUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2712. case OpDelete, OpDeleteOne:
  2713. return (&WorkExperienceDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  2714. default:
  2715. return nil, fmt.Errorf("ent: unknown WorkExperience mutation op: %q", m.Op())
  2716. }
  2717. }
  2718. // WxClient is a client for the Wx schema.
  2719. type WxClient struct {
  2720. config
  2721. }
  2722. // NewWxClient returns a client for the Wx from the given config.
  2723. func NewWxClient(c config) *WxClient {
  2724. return &WxClient{config: c}
  2725. }
  2726. // Use adds a list of mutation hooks to the hooks stack.
  2727. // A call to `Use(f, g, h)` equals to `wx.Hooks(f(g(h())))`.
  2728. func (c *WxClient) Use(hooks ...Hook) {
  2729. c.hooks.Wx = append(c.hooks.Wx, hooks...)
  2730. }
  2731. // Intercept adds a list of query interceptors to the interceptors stack.
  2732. // A call to `Intercept(f, g, h)` equals to `wx.Intercept(f(g(h())))`.
  2733. func (c *WxClient) Intercept(interceptors ...Interceptor) {
  2734. c.inters.Wx = append(c.inters.Wx, interceptors...)
  2735. }
  2736. // Create returns a builder for creating a Wx entity.
  2737. func (c *WxClient) Create() *WxCreate {
  2738. mutation := newWxMutation(c.config, OpCreate)
  2739. return &WxCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2740. }
  2741. // CreateBulk returns a builder for creating a bulk of Wx entities.
  2742. func (c *WxClient) CreateBulk(builders ...*WxCreate) *WxCreateBulk {
  2743. return &WxCreateBulk{config: c.config, builders: builders}
  2744. }
  2745. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  2746. // a builder and applies setFunc on it.
  2747. func (c *WxClient) MapCreateBulk(slice any, setFunc func(*WxCreate, int)) *WxCreateBulk {
  2748. rv := reflect.ValueOf(slice)
  2749. if rv.Kind() != reflect.Slice {
  2750. return &WxCreateBulk{err: fmt.Errorf("calling to WxClient.MapCreateBulk with wrong type %T, need slice", slice)}
  2751. }
  2752. builders := make([]*WxCreate, rv.Len())
  2753. for i := 0; i < rv.Len(); i++ {
  2754. builders[i] = c.Create()
  2755. setFunc(builders[i], i)
  2756. }
  2757. return &WxCreateBulk{config: c.config, builders: builders}
  2758. }
  2759. // Update returns an update builder for Wx.
  2760. func (c *WxClient) Update() *WxUpdate {
  2761. mutation := newWxMutation(c.config, OpUpdate)
  2762. return &WxUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2763. }
  2764. // UpdateOne returns an update builder for the given entity.
  2765. func (c *WxClient) UpdateOne(w *Wx) *WxUpdateOne {
  2766. mutation := newWxMutation(c.config, OpUpdateOne, withWx(w))
  2767. return &WxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2768. }
  2769. // UpdateOneID returns an update builder for the given id.
  2770. func (c *WxClient) UpdateOneID(id uint64) *WxUpdateOne {
  2771. mutation := newWxMutation(c.config, OpUpdateOne, withWxID(id))
  2772. return &WxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2773. }
  2774. // Delete returns a delete builder for Wx.
  2775. func (c *WxClient) Delete() *WxDelete {
  2776. mutation := newWxMutation(c.config, OpDelete)
  2777. return &WxDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  2778. }
  2779. // DeleteOne returns a builder for deleting the given entity.
  2780. func (c *WxClient) DeleteOne(w *Wx) *WxDeleteOne {
  2781. return c.DeleteOneID(w.ID)
  2782. }
  2783. // DeleteOneID returns a builder for deleting the given entity by its id.
  2784. func (c *WxClient) DeleteOneID(id uint64) *WxDeleteOne {
  2785. builder := c.Delete().Where(wx.ID(id))
  2786. builder.mutation.id = &id
  2787. builder.mutation.op = OpDeleteOne
  2788. return &WxDeleteOne{builder}
  2789. }
  2790. // Query returns a query builder for Wx.
  2791. func (c *WxClient) Query() *WxQuery {
  2792. return &WxQuery{
  2793. config: c.config,
  2794. ctx: &QueryContext{Type: TypeWx},
  2795. inters: c.Interceptors(),
  2796. }
  2797. }
  2798. // Get returns a Wx entity by its id.
  2799. func (c *WxClient) Get(ctx context.Context, id uint64) (*Wx, error) {
  2800. return c.Query().Where(wx.ID(id)).Only(ctx)
  2801. }
  2802. // GetX is like Get, but panics if an error occurs.
  2803. func (c *WxClient) GetX(ctx context.Context, id uint64) *Wx {
  2804. obj, err := c.Get(ctx, id)
  2805. if err != nil {
  2806. panic(err)
  2807. }
  2808. return obj
  2809. }
  2810. // QueryServer queries the server edge of a Wx.
  2811. func (c *WxClient) QueryServer(w *Wx) *ServerQuery {
  2812. query := (&ServerClient{config: c.config}).Query()
  2813. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  2814. id := w.ID
  2815. step := sqlgraph.NewStep(
  2816. sqlgraph.From(wx.Table, wx.FieldID, id),
  2817. sqlgraph.To(server.Table, server.FieldID),
  2818. sqlgraph.Edge(sqlgraph.M2O, true, wx.ServerTable, wx.ServerColumn),
  2819. )
  2820. fromV = sqlgraph.Neighbors(w.driver.Dialect(), step)
  2821. return fromV, nil
  2822. }
  2823. return query
  2824. }
  2825. // QueryAgent queries the agent edge of a Wx.
  2826. func (c *WxClient) QueryAgent(w *Wx) *AgentQuery {
  2827. query := (&AgentClient{config: c.config}).Query()
  2828. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  2829. id := w.ID
  2830. step := sqlgraph.NewStep(
  2831. sqlgraph.From(wx.Table, wx.FieldID, id),
  2832. sqlgraph.To(agent.Table, agent.FieldID),
  2833. sqlgraph.Edge(sqlgraph.M2O, true, wx.AgentTable, wx.AgentColumn),
  2834. )
  2835. fromV = sqlgraph.Neighbors(w.driver.Dialect(), step)
  2836. return fromV, nil
  2837. }
  2838. return query
  2839. }
  2840. // Hooks returns the client hooks.
  2841. func (c *WxClient) Hooks() []Hook {
  2842. hooks := c.hooks.Wx
  2843. return append(hooks[:len(hooks):len(hooks)], wx.Hooks[:]...)
  2844. }
  2845. // Interceptors returns the client interceptors.
  2846. func (c *WxClient) Interceptors() []Interceptor {
  2847. inters := c.inters.Wx
  2848. return append(inters[:len(inters):len(inters)], wx.Interceptors[:]...)
  2849. }
  2850. func (c *WxClient) mutate(ctx context.Context, m *WxMutation) (Value, error) {
  2851. switch m.Op() {
  2852. case OpCreate:
  2853. return (&WxCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2854. case OpUpdate:
  2855. return (&WxUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2856. case OpUpdateOne:
  2857. return (&WxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  2858. case OpDelete, OpDeleteOne:
  2859. return (&WxDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  2860. default:
  2861. return nil, fmt.Errorf("ent: unknown Wx mutation op: %q", m.Op())
  2862. }
  2863. }
  2864. // hooks and interceptors per client, for fast access.
  2865. type (
  2866. hooks struct {
  2867. Agent, BatchMsg, Category, Contact, Employee, EmployeeConfig, Label,
  2868. LabelRelationship, Message, MessageRecords, Msg, Server, SopNode, SopStage,
  2869. SopTask, Token, Tutorial, WorkExperience, Wx []ent.Hook
  2870. }
  2871. inters struct {
  2872. Agent, BatchMsg, Category, Contact, Employee, EmployeeConfig, Label,
  2873. LabelRelationship, Message, MessageRecords, Msg, Server, SopNode, SopStage,
  2874. SopTask, Token, Tutorial, WorkExperience, Wx []ent.Interceptor
  2875. }
  2876. )
  2877. // ExecContext allows calling the underlying ExecContext method of the driver if it is supported by it.
  2878. // See, database/sql#DB.ExecContext for more information.
  2879. func (c *config) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) {
  2880. ex, ok := c.driver.(interface {
  2881. ExecContext(context.Context, string, ...any) (stdsql.Result, error)
  2882. })
  2883. if !ok {
  2884. return nil, fmt.Errorf("Driver.ExecContext is not supported")
  2885. }
  2886. return ex.ExecContext(ctx, query, args...)
  2887. }
  2888. // QueryContext allows calling the underlying QueryContext method of the driver if it is supported by it.
  2889. // See, database/sql#DB.QueryContext for more information.
  2890. func (c *config) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) {
  2891. q, ok := c.driver.(interface {
  2892. QueryContext(context.Context, string, ...any) (*stdsql.Rows, error)
  2893. })
  2894. if !ok {
  2895. return nil, fmt.Errorf("Driver.QueryContext is not supported")
  2896. }
  2897. return q.QueryContext(ctx, query, args...)
  2898. }