client.go 41 KB

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