client.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  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/task"
  16. "github.com/suyuan32/simple-admin-job/ent/tasklog"
  17. stdsql "database/sql"
  18. )
  19. // Client is the client that holds all ent builders.
  20. type Client struct {
  21. config
  22. // Schema is the client for creating, migrating and dropping schema.
  23. Schema *migrate.Schema
  24. // MessageRecords is the client for interacting with the MessageRecords builders.
  25. MessageRecords *MessageRecordsClient
  26. // Task is the client for interacting with the Task builders.
  27. Task *TaskClient
  28. // TaskLog is the client for interacting with the TaskLog builders.
  29. TaskLog *TaskLogClient
  30. }
  31. // NewClient creates a new client configured with the given options.
  32. func NewClient(opts ...Option) *Client {
  33. client := &Client{config: newConfig(opts...)}
  34. client.init()
  35. return client
  36. }
  37. func (c *Client) init() {
  38. c.Schema = migrate.NewSchema(c.driver)
  39. c.MessageRecords = NewMessageRecordsClient(c.config)
  40. c.Task = NewTaskClient(c.config)
  41. c.TaskLog = NewTaskLogClient(c.config)
  42. }
  43. type (
  44. // config is the configuration for the client and its builder.
  45. config struct {
  46. // driver used for executing database requests.
  47. driver dialect.Driver
  48. // debug enable a debug logging.
  49. debug bool
  50. // log used for logging on debug mode.
  51. log func(...any)
  52. // hooks to execute on mutations.
  53. hooks *hooks
  54. // interceptors to execute on queries.
  55. inters *inters
  56. }
  57. // Option function to configure the client.
  58. Option func(*config)
  59. )
  60. // newConfig creates a new config for the client.
  61. func newConfig(opts ...Option) config {
  62. cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
  63. cfg.options(opts...)
  64. return cfg
  65. }
  66. // options applies the options on the config object.
  67. func (c *config) options(opts ...Option) {
  68. for _, opt := range opts {
  69. opt(c)
  70. }
  71. if c.debug {
  72. c.driver = dialect.Debug(c.driver, c.log)
  73. }
  74. }
  75. // Debug enables debug logging on the ent.Driver.
  76. func Debug() Option {
  77. return func(c *config) {
  78. c.debug = true
  79. }
  80. }
  81. // Log sets the logging function for debug mode.
  82. func Log(fn func(...any)) Option {
  83. return func(c *config) {
  84. c.log = fn
  85. }
  86. }
  87. // Driver configures the client driver.
  88. func Driver(driver dialect.Driver) Option {
  89. return func(c *config) {
  90. c.driver = driver
  91. }
  92. }
  93. // Open opens a database/sql.DB specified by the driver name and
  94. // the data source name, and returns a new client attached to it.
  95. // Optional parameters can be added for configuring the client.
  96. func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
  97. switch driverName {
  98. case dialect.MySQL, dialect.Postgres, dialect.SQLite:
  99. drv, err := sql.Open(driverName, dataSourceName)
  100. if err != nil {
  101. return nil, err
  102. }
  103. return NewClient(append(options, Driver(drv))...), nil
  104. default:
  105. return nil, fmt.Errorf("unsupported driver: %q", driverName)
  106. }
  107. }
  108. // ErrTxStarted is returned when trying to start a new transaction from a transactional client.
  109. var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction")
  110. // Tx returns a new transactional client. The provided context
  111. // is used until the transaction is committed or rolled back.
  112. func (c *Client) Tx(ctx context.Context) (*Tx, error) {
  113. if _, ok := c.driver.(*txDriver); ok {
  114. return nil, ErrTxStarted
  115. }
  116. tx, err := newTx(ctx, c.driver)
  117. if err != nil {
  118. return nil, fmt.Errorf("ent: starting a transaction: %w", err)
  119. }
  120. cfg := c.config
  121. cfg.driver = tx
  122. return &Tx{
  123. ctx: ctx,
  124. config: cfg,
  125. MessageRecords: NewMessageRecordsClient(cfg),
  126. Task: NewTaskClient(cfg),
  127. TaskLog: NewTaskLogClient(cfg),
  128. }, nil
  129. }
  130. // BeginTx returns a transactional client with specified options.
  131. func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
  132. if _, ok := c.driver.(*txDriver); ok {
  133. return nil, errors.New("ent: cannot start a transaction within a transaction")
  134. }
  135. tx, err := c.driver.(interface {
  136. BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)
  137. }).BeginTx(ctx, opts)
  138. if err != nil {
  139. return nil, fmt.Errorf("ent: starting a transaction: %w", err)
  140. }
  141. cfg := c.config
  142. cfg.driver = &txDriver{tx: tx, drv: c.driver}
  143. return &Tx{
  144. ctx: ctx,
  145. config: cfg,
  146. MessageRecords: NewMessageRecordsClient(cfg),
  147. Task: NewTaskClient(cfg),
  148. TaskLog: NewTaskLogClient(cfg),
  149. }, nil
  150. }
  151. // Debug returns a new debug-client. It's used to get verbose logging on specific operations.
  152. //
  153. // client.Debug().
  154. // MessageRecords.
  155. // Query().
  156. // Count(ctx)
  157. func (c *Client) Debug() *Client {
  158. if c.debug {
  159. return c
  160. }
  161. cfg := c.config
  162. cfg.driver = dialect.Debug(c.driver, c.log)
  163. client := &Client{config: cfg}
  164. client.init()
  165. return client
  166. }
  167. // Close closes the database connection and prevents new queries from starting.
  168. func (c *Client) Close() error {
  169. return c.driver.Close()
  170. }
  171. // Use adds the mutation hooks to all the entity clients.
  172. // In order to add hooks to a specific client, call: `client.Node.Use(...)`.
  173. func (c *Client) Use(hooks ...Hook) {
  174. c.MessageRecords.Use(hooks...)
  175. c.Task.Use(hooks...)
  176. c.TaskLog.Use(hooks...)
  177. }
  178. // Intercept adds the query interceptors to all the entity clients.
  179. // In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
  180. func (c *Client) Intercept(interceptors ...Interceptor) {
  181. c.MessageRecords.Intercept(interceptors...)
  182. c.Task.Intercept(interceptors...)
  183. c.TaskLog.Intercept(interceptors...)
  184. }
  185. // Mutate implements the ent.Mutator interface.
  186. func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
  187. switch m := m.(type) {
  188. case *MessageRecordsMutation:
  189. return c.MessageRecords.mutate(ctx, m)
  190. case *TaskMutation:
  191. return c.Task.mutate(ctx, m)
  192. case *TaskLogMutation:
  193. return c.TaskLog.mutate(ctx, m)
  194. default:
  195. return nil, fmt.Errorf("ent: unknown mutation type %T", m)
  196. }
  197. }
  198. // MessageRecordsClient is a client for the MessageRecords schema.
  199. type MessageRecordsClient struct {
  200. config
  201. }
  202. // NewMessageRecordsClient returns a client for the MessageRecords from the given config.
  203. func NewMessageRecordsClient(c config) *MessageRecordsClient {
  204. return &MessageRecordsClient{config: c}
  205. }
  206. // Use adds a list of mutation hooks to the hooks stack.
  207. // A call to `Use(f, g, h)` equals to `messagerecords.Hooks(f(g(h())))`.
  208. func (c *MessageRecordsClient) Use(hooks ...Hook) {
  209. c.hooks.MessageRecords = append(c.hooks.MessageRecords, hooks...)
  210. }
  211. // Intercept adds a list of query interceptors to the interceptors stack.
  212. // A call to `Intercept(f, g, h)` equals to `messagerecords.Intercept(f(g(h())))`.
  213. func (c *MessageRecordsClient) Intercept(interceptors ...Interceptor) {
  214. c.inters.MessageRecords = append(c.inters.MessageRecords, interceptors...)
  215. }
  216. // Create returns a builder for creating a MessageRecords entity.
  217. func (c *MessageRecordsClient) Create() *MessageRecordsCreate {
  218. mutation := newMessageRecordsMutation(c.config, OpCreate)
  219. return &MessageRecordsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  220. }
  221. // CreateBulk returns a builder for creating a bulk of MessageRecords entities.
  222. func (c *MessageRecordsClient) CreateBulk(builders ...*MessageRecordsCreate) *MessageRecordsCreateBulk {
  223. return &MessageRecordsCreateBulk{config: c.config, builders: builders}
  224. }
  225. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  226. // a builder and applies setFunc on it.
  227. func (c *MessageRecordsClient) MapCreateBulk(slice any, setFunc func(*MessageRecordsCreate, int)) *MessageRecordsCreateBulk {
  228. rv := reflect.ValueOf(slice)
  229. if rv.Kind() != reflect.Slice {
  230. return &MessageRecordsCreateBulk{err: fmt.Errorf("calling to MessageRecordsClient.MapCreateBulk with wrong type %T, need slice", slice)}
  231. }
  232. builders := make([]*MessageRecordsCreate, rv.Len())
  233. for i := 0; i < rv.Len(); i++ {
  234. builders[i] = c.Create()
  235. setFunc(builders[i], i)
  236. }
  237. return &MessageRecordsCreateBulk{config: c.config, builders: builders}
  238. }
  239. // Update returns an update builder for MessageRecords.
  240. func (c *MessageRecordsClient) Update() *MessageRecordsUpdate {
  241. mutation := newMessageRecordsMutation(c.config, OpUpdate)
  242. return &MessageRecordsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  243. }
  244. // UpdateOne returns an update builder for the given entity.
  245. func (c *MessageRecordsClient) UpdateOne(mr *MessageRecords) *MessageRecordsUpdateOne {
  246. mutation := newMessageRecordsMutation(c.config, OpUpdateOne, withMessageRecords(mr))
  247. return &MessageRecordsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  248. }
  249. // UpdateOneID returns an update builder for the given id.
  250. func (c *MessageRecordsClient) UpdateOneID(id uint64) *MessageRecordsUpdateOne {
  251. mutation := newMessageRecordsMutation(c.config, OpUpdateOne, withMessageRecordsID(id))
  252. return &MessageRecordsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  253. }
  254. // Delete returns a delete builder for MessageRecords.
  255. func (c *MessageRecordsClient) Delete() *MessageRecordsDelete {
  256. mutation := newMessageRecordsMutation(c.config, OpDelete)
  257. return &MessageRecordsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  258. }
  259. // DeleteOne returns a builder for deleting the given entity.
  260. func (c *MessageRecordsClient) DeleteOne(mr *MessageRecords) *MessageRecordsDeleteOne {
  261. return c.DeleteOneID(mr.ID)
  262. }
  263. // DeleteOneID returns a builder for deleting the given entity by its id.
  264. func (c *MessageRecordsClient) DeleteOneID(id uint64) *MessageRecordsDeleteOne {
  265. builder := c.Delete().Where(messagerecords.ID(id))
  266. builder.mutation.id = &id
  267. builder.mutation.op = OpDeleteOne
  268. return &MessageRecordsDeleteOne{builder}
  269. }
  270. // Query returns a query builder for MessageRecords.
  271. func (c *MessageRecordsClient) Query() *MessageRecordsQuery {
  272. return &MessageRecordsQuery{
  273. config: c.config,
  274. ctx: &QueryContext{Type: TypeMessageRecords},
  275. inters: c.Interceptors(),
  276. }
  277. }
  278. // Get returns a MessageRecords entity by its id.
  279. func (c *MessageRecordsClient) Get(ctx context.Context, id uint64) (*MessageRecords, error) {
  280. return c.Query().Where(messagerecords.ID(id)).Only(ctx)
  281. }
  282. // GetX is like Get, but panics if an error occurs.
  283. func (c *MessageRecordsClient) GetX(ctx context.Context, id uint64) *MessageRecords {
  284. obj, err := c.Get(ctx, id)
  285. if err != nil {
  286. panic(err)
  287. }
  288. return obj
  289. }
  290. // Hooks returns the client hooks.
  291. func (c *MessageRecordsClient) Hooks() []Hook {
  292. return c.hooks.MessageRecords
  293. }
  294. // Interceptors returns the client interceptors.
  295. func (c *MessageRecordsClient) Interceptors() []Interceptor {
  296. return c.inters.MessageRecords
  297. }
  298. func (c *MessageRecordsClient) mutate(ctx context.Context, m *MessageRecordsMutation) (Value, error) {
  299. switch m.Op() {
  300. case OpCreate:
  301. return (&MessageRecordsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  302. case OpUpdate:
  303. return (&MessageRecordsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  304. case OpUpdateOne:
  305. return (&MessageRecordsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  306. case OpDelete, OpDeleteOne:
  307. return (&MessageRecordsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  308. default:
  309. return nil, fmt.Errorf("ent: unknown MessageRecords mutation op: %q", m.Op())
  310. }
  311. }
  312. // TaskClient is a client for the Task schema.
  313. type TaskClient struct {
  314. config
  315. }
  316. // NewTaskClient returns a client for the Task from the given config.
  317. func NewTaskClient(c config) *TaskClient {
  318. return &TaskClient{config: c}
  319. }
  320. // Use adds a list of mutation hooks to the hooks stack.
  321. // A call to `Use(f, g, h)` equals to `task.Hooks(f(g(h())))`.
  322. func (c *TaskClient) Use(hooks ...Hook) {
  323. c.hooks.Task = append(c.hooks.Task, hooks...)
  324. }
  325. // Intercept adds a list of query interceptors to the interceptors stack.
  326. // A call to `Intercept(f, g, h)` equals to `task.Intercept(f(g(h())))`.
  327. func (c *TaskClient) Intercept(interceptors ...Interceptor) {
  328. c.inters.Task = append(c.inters.Task, interceptors...)
  329. }
  330. // Create returns a builder for creating a Task entity.
  331. func (c *TaskClient) Create() *TaskCreate {
  332. mutation := newTaskMutation(c.config, OpCreate)
  333. return &TaskCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  334. }
  335. // CreateBulk returns a builder for creating a bulk of Task entities.
  336. func (c *TaskClient) CreateBulk(builders ...*TaskCreate) *TaskCreateBulk {
  337. return &TaskCreateBulk{config: c.config, builders: builders}
  338. }
  339. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  340. // a builder and applies setFunc on it.
  341. func (c *TaskClient) MapCreateBulk(slice any, setFunc func(*TaskCreate, int)) *TaskCreateBulk {
  342. rv := reflect.ValueOf(slice)
  343. if rv.Kind() != reflect.Slice {
  344. return &TaskCreateBulk{err: fmt.Errorf("calling to TaskClient.MapCreateBulk with wrong type %T, need slice", slice)}
  345. }
  346. builders := make([]*TaskCreate, rv.Len())
  347. for i := 0; i < rv.Len(); i++ {
  348. builders[i] = c.Create()
  349. setFunc(builders[i], i)
  350. }
  351. return &TaskCreateBulk{config: c.config, builders: builders}
  352. }
  353. // Update returns an update builder for Task.
  354. func (c *TaskClient) Update() *TaskUpdate {
  355. mutation := newTaskMutation(c.config, OpUpdate)
  356. return &TaskUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  357. }
  358. // UpdateOne returns an update builder for the given entity.
  359. func (c *TaskClient) UpdateOne(t *Task) *TaskUpdateOne {
  360. mutation := newTaskMutation(c.config, OpUpdateOne, withTask(t))
  361. return &TaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  362. }
  363. // UpdateOneID returns an update builder for the given id.
  364. func (c *TaskClient) UpdateOneID(id uint64) *TaskUpdateOne {
  365. mutation := newTaskMutation(c.config, OpUpdateOne, withTaskID(id))
  366. return &TaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  367. }
  368. // Delete returns a delete builder for Task.
  369. func (c *TaskClient) Delete() *TaskDelete {
  370. mutation := newTaskMutation(c.config, OpDelete)
  371. return &TaskDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  372. }
  373. // DeleteOne returns a builder for deleting the given entity.
  374. func (c *TaskClient) DeleteOne(t *Task) *TaskDeleteOne {
  375. return c.DeleteOneID(t.ID)
  376. }
  377. // DeleteOneID returns a builder for deleting the given entity by its id.
  378. func (c *TaskClient) DeleteOneID(id uint64) *TaskDeleteOne {
  379. builder := c.Delete().Where(task.ID(id))
  380. builder.mutation.id = &id
  381. builder.mutation.op = OpDeleteOne
  382. return &TaskDeleteOne{builder}
  383. }
  384. // Query returns a query builder for Task.
  385. func (c *TaskClient) Query() *TaskQuery {
  386. return &TaskQuery{
  387. config: c.config,
  388. ctx: &QueryContext{Type: TypeTask},
  389. inters: c.Interceptors(),
  390. }
  391. }
  392. // Get returns a Task entity by its id.
  393. func (c *TaskClient) Get(ctx context.Context, id uint64) (*Task, error) {
  394. return c.Query().Where(task.ID(id)).Only(ctx)
  395. }
  396. // GetX is like Get, but panics if an error occurs.
  397. func (c *TaskClient) GetX(ctx context.Context, id uint64) *Task {
  398. obj, err := c.Get(ctx, id)
  399. if err != nil {
  400. panic(err)
  401. }
  402. return obj
  403. }
  404. // QueryTaskLogs queries the task_logs edge of a Task.
  405. func (c *TaskClient) QueryTaskLogs(t *Task) *TaskLogQuery {
  406. query := (&TaskLogClient{config: c.config}).Query()
  407. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  408. id := t.ID
  409. step := sqlgraph.NewStep(
  410. sqlgraph.From(task.Table, task.FieldID, id),
  411. sqlgraph.To(tasklog.Table, tasklog.FieldID),
  412. sqlgraph.Edge(sqlgraph.O2M, false, task.TaskLogsTable, task.TaskLogsColumn),
  413. )
  414. fromV = sqlgraph.Neighbors(t.driver.Dialect(), step)
  415. return fromV, nil
  416. }
  417. return query
  418. }
  419. // Hooks returns the client hooks.
  420. func (c *TaskClient) Hooks() []Hook {
  421. return c.hooks.Task
  422. }
  423. // Interceptors returns the client interceptors.
  424. func (c *TaskClient) Interceptors() []Interceptor {
  425. return c.inters.Task
  426. }
  427. func (c *TaskClient) mutate(ctx context.Context, m *TaskMutation) (Value, error) {
  428. switch m.Op() {
  429. case OpCreate:
  430. return (&TaskCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  431. case OpUpdate:
  432. return (&TaskUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  433. case OpUpdateOne:
  434. return (&TaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  435. case OpDelete, OpDeleteOne:
  436. return (&TaskDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  437. default:
  438. return nil, fmt.Errorf("ent: unknown Task mutation op: %q", m.Op())
  439. }
  440. }
  441. // TaskLogClient is a client for the TaskLog schema.
  442. type TaskLogClient struct {
  443. config
  444. }
  445. // NewTaskLogClient returns a client for the TaskLog from the given config.
  446. func NewTaskLogClient(c config) *TaskLogClient {
  447. return &TaskLogClient{config: c}
  448. }
  449. // Use adds a list of mutation hooks to the hooks stack.
  450. // A call to `Use(f, g, h)` equals to `tasklog.Hooks(f(g(h())))`.
  451. func (c *TaskLogClient) Use(hooks ...Hook) {
  452. c.hooks.TaskLog = append(c.hooks.TaskLog, hooks...)
  453. }
  454. // Intercept adds a list of query interceptors to the interceptors stack.
  455. // A call to `Intercept(f, g, h)` equals to `tasklog.Intercept(f(g(h())))`.
  456. func (c *TaskLogClient) Intercept(interceptors ...Interceptor) {
  457. c.inters.TaskLog = append(c.inters.TaskLog, interceptors...)
  458. }
  459. // Create returns a builder for creating a TaskLog entity.
  460. func (c *TaskLogClient) Create() *TaskLogCreate {
  461. mutation := newTaskLogMutation(c.config, OpCreate)
  462. return &TaskLogCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  463. }
  464. // CreateBulk returns a builder for creating a bulk of TaskLog entities.
  465. func (c *TaskLogClient) CreateBulk(builders ...*TaskLogCreate) *TaskLogCreateBulk {
  466. return &TaskLogCreateBulk{config: c.config, builders: builders}
  467. }
  468. // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
  469. // a builder and applies setFunc on it.
  470. func (c *TaskLogClient) MapCreateBulk(slice any, setFunc func(*TaskLogCreate, int)) *TaskLogCreateBulk {
  471. rv := reflect.ValueOf(slice)
  472. if rv.Kind() != reflect.Slice {
  473. return &TaskLogCreateBulk{err: fmt.Errorf("calling to TaskLogClient.MapCreateBulk with wrong type %T, need slice", slice)}
  474. }
  475. builders := make([]*TaskLogCreate, rv.Len())
  476. for i := 0; i < rv.Len(); i++ {
  477. builders[i] = c.Create()
  478. setFunc(builders[i], i)
  479. }
  480. return &TaskLogCreateBulk{config: c.config, builders: builders}
  481. }
  482. // Update returns an update builder for TaskLog.
  483. func (c *TaskLogClient) Update() *TaskLogUpdate {
  484. mutation := newTaskLogMutation(c.config, OpUpdate)
  485. return &TaskLogUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
  486. }
  487. // UpdateOne returns an update builder for the given entity.
  488. func (c *TaskLogClient) UpdateOne(tl *TaskLog) *TaskLogUpdateOne {
  489. mutation := newTaskLogMutation(c.config, OpUpdateOne, withTaskLog(tl))
  490. return &TaskLogUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  491. }
  492. // UpdateOneID returns an update builder for the given id.
  493. func (c *TaskLogClient) UpdateOneID(id uint64) *TaskLogUpdateOne {
  494. mutation := newTaskLogMutation(c.config, OpUpdateOne, withTaskLogID(id))
  495. return &TaskLogUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
  496. }
  497. // Delete returns a delete builder for TaskLog.
  498. func (c *TaskLogClient) Delete() *TaskLogDelete {
  499. mutation := newTaskLogMutation(c.config, OpDelete)
  500. return &TaskLogDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
  501. }
  502. // DeleteOne returns a builder for deleting the given entity.
  503. func (c *TaskLogClient) DeleteOne(tl *TaskLog) *TaskLogDeleteOne {
  504. return c.DeleteOneID(tl.ID)
  505. }
  506. // DeleteOneID returns a builder for deleting the given entity by its id.
  507. func (c *TaskLogClient) DeleteOneID(id uint64) *TaskLogDeleteOne {
  508. builder := c.Delete().Where(tasklog.ID(id))
  509. builder.mutation.id = &id
  510. builder.mutation.op = OpDeleteOne
  511. return &TaskLogDeleteOne{builder}
  512. }
  513. // Query returns a query builder for TaskLog.
  514. func (c *TaskLogClient) Query() *TaskLogQuery {
  515. return &TaskLogQuery{
  516. config: c.config,
  517. ctx: &QueryContext{Type: TypeTaskLog},
  518. inters: c.Interceptors(),
  519. }
  520. }
  521. // Get returns a TaskLog entity by its id.
  522. func (c *TaskLogClient) Get(ctx context.Context, id uint64) (*TaskLog, error) {
  523. return c.Query().Where(tasklog.ID(id)).Only(ctx)
  524. }
  525. // GetX is like Get, but panics if an error occurs.
  526. func (c *TaskLogClient) GetX(ctx context.Context, id uint64) *TaskLog {
  527. obj, err := c.Get(ctx, id)
  528. if err != nil {
  529. panic(err)
  530. }
  531. return obj
  532. }
  533. // QueryTasks queries the tasks edge of a TaskLog.
  534. func (c *TaskLogClient) QueryTasks(tl *TaskLog) *TaskQuery {
  535. query := (&TaskClient{config: c.config}).Query()
  536. query.path = func(context.Context) (fromV *sql.Selector, _ error) {
  537. id := tl.ID
  538. step := sqlgraph.NewStep(
  539. sqlgraph.From(tasklog.Table, tasklog.FieldID, id),
  540. sqlgraph.To(task.Table, task.FieldID),
  541. sqlgraph.Edge(sqlgraph.M2O, true, tasklog.TasksTable, tasklog.TasksColumn),
  542. )
  543. fromV = sqlgraph.Neighbors(tl.driver.Dialect(), step)
  544. return fromV, nil
  545. }
  546. return query
  547. }
  548. // Hooks returns the client hooks.
  549. func (c *TaskLogClient) Hooks() []Hook {
  550. return c.hooks.TaskLog
  551. }
  552. // Interceptors returns the client interceptors.
  553. func (c *TaskLogClient) Interceptors() []Interceptor {
  554. return c.inters.TaskLog
  555. }
  556. func (c *TaskLogClient) mutate(ctx context.Context, m *TaskLogMutation) (Value, error) {
  557. switch m.Op() {
  558. case OpCreate:
  559. return (&TaskLogCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  560. case OpUpdate:
  561. return (&TaskLogUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  562. case OpUpdateOne:
  563. return (&TaskLogUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
  564. case OpDelete, OpDeleteOne:
  565. return (&TaskLogDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
  566. default:
  567. return nil, fmt.Errorf("ent: unknown TaskLog mutation op: %q", m.Op())
  568. }
  569. }
  570. // hooks and interceptors per client, for fast access.
  571. type (
  572. hooks struct {
  573. MessageRecords, Task, TaskLog []ent.Hook
  574. }
  575. inters struct {
  576. MessageRecords, Task, TaskLog []ent.Interceptor
  577. }
  578. )
  579. // ExecContext allows calling the underlying ExecContext method of the driver if it is supported by it.
  580. // See, database/sql#DB.ExecContext for more information.
  581. func (c *config) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) {
  582. ex, ok := c.driver.(interface {
  583. ExecContext(context.Context, string, ...any) (stdsql.Result, error)
  584. })
  585. if !ok {
  586. return nil, fmt.Errorf("Driver.ExecContext is not supported")
  587. }
  588. return ex.ExecContext(ctx, query, args...)
  589. }
  590. // QueryContext allows calling the underlying QueryContext method of the driver if it is supported by it.
  591. // See, database/sql#DB.QueryContext for more information.
  592. func (c *config) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) {
  593. q, ok := c.driver.(interface {
  594. QueryContext(context.Context, string, ...any) (*stdsql.Rows, error)
  595. })
  596. if !ok {
  597. return nil, fmt.Errorf("Driver.QueryContext is not supported")
  598. }
  599. return q.QueryContext(ctx, query, args...)
  600. }