mutation.go 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "sync"
  8. "time"
  9. "entgo.io/ent"
  10. "entgo.io/ent/dialect/sql"
  11. "github.com/suyuan32/simple-admin-job/ent/predicate"
  12. "github.com/suyuan32/simple-admin-job/ent/task"
  13. "github.com/suyuan32/simple-admin-job/ent/tasklog"
  14. )
  15. const (
  16. // Operation types.
  17. OpCreate = ent.OpCreate
  18. OpDelete = ent.OpDelete
  19. OpDeleteOne = ent.OpDeleteOne
  20. OpUpdate = ent.OpUpdate
  21. OpUpdateOne = ent.OpUpdateOne
  22. // Node types.
  23. TypeTask = "Task"
  24. TypeTaskLog = "TaskLog"
  25. )
  26. // TaskMutation represents an operation that mutates the Task nodes in the graph.
  27. type TaskMutation struct {
  28. config
  29. op Op
  30. typ string
  31. id *uint64
  32. created_at *time.Time
  33. updated_at *time.Time
  34. status *uint8
  35. addstatus *int8
  36. name *string
  37. task_group *string
  38. cron_expression *string
  39. pattern *string
  40. payload *string
  41. clearedFields map[string]struct{}
  42. task_logs map[uint64]struct{}
  43. removedtask_logs map[uint64]struct{}
  44. clearedtask_logs bool
  45. done bool
  46. oldValue func(context.Context) (*Task, error)
  47. predicates []predicate.Task
  48. }
  49. var _ ent.Mutation = (*TaskMutation)(nil)
  50. // taskOption allows management of the mutation configuration using functional options.
  51. type taskOption func(*TaskMutation)
  52. // newTaskMutation creates new mutation for the Task entity.
  53. func newTaskMutation(c config, op Op, opts ...taskOption) *TaskMutation {
  54. m := &TaskMutation{
  55. config: c,
  56. op: op,
  57. typ: TypeTask,
  58. clearedFields: make(map[string]struct{}),
  59. }
  60. for _, opt := range opts {
  61. opt(m)
  62. }
  63. return m
  64. }
  65. // withTaskID sets the ID field of the mutation.
  66. func withTaskID(id uint64) taskOption {
  67. return func(m *TaskMutation) {
  68. var (
  69. err error
  70. once sync.Once
  71. value *Task
  72. )
  73. m.oldValue = func(ctx context.Context) (*Task, error) {
  74. once.Do(func() {
  75. if m.done {
  76. err = errors.New("querying old values post mutation is not allowed")
  77. } else {
  78. value, err = m.Client().Task.Get(ctx, id)
  79. }
  80. })
  81. return value, err
  82. }
  83. m.id = &id
  84. }
  85. }
  86. // withTask sets the old Task of the mutation.
  87. func withTask(node *Task) taskOption {
  88. return func(m *TaskMutation) {
  89. m.oldValue = func(context.Context) (*Task, error) {
  90. return node, nil
  91. }
  92. m.id = &node.ID
  93. }
  94. }
  95. // Client returns a new `ent.Client` from the mutation. If the mutation was
  96. // executed in a transaction (ent.Tx), a transactional client is returned.
  97. func (m TaskMutation) Client() *Client {
  98. client := &Client{config: m.config}
  99. client.init()
  100. return client
  101. }
  102. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  103. // it returns an error otherwise.
  104. func (m TaskMutation) Tx() (*Tx, error) {
  105. if _, ok := m.driver.(*txDriver); !ok {
  106. return nil, errors.New("ent: mutation is not running in a transaction")
  107. }
  108. tx := &Tx{config: m.config}
  109. tx.init()
  110. return tx, nil
  111. }
  112. // SetID sets the value of the id field. Note that this
  113. // operation is only accepted on creation of Task entities.
  114. func (m *TaskMutation) SetID(id uint64) {
  115. m.id = &id
  116. }
  117. // ID returns the ID value in the mutation. Note that the ID is only available
  118. // if it was provided to the builder or after it was returned from the database.
  119. func (m *TaskMutation) ID() (id uint64, exists bool) {
  120. if m.id == nil {
  121. return
  122. }
  123. return *m.id, true
  124. }
  125. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  126. // That means, if the mutation is applied within a transaction with an isolation level such
  127. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  128. // or updated by the mutation.
  129. func (m *TaskMutation) IDs(ctx context.Context) ([]uint64, error) {
  130. switch {
  131. case m.op.Is(OpUpdateOne | OpDeleteOne):
  132. id, exists := m.ID()
  133. if exists {
  134. return []uint64{id}, nil
  135. }
  136. fallthrough
  137. case m.op.Is(OpUpdate | OpDelete):
  138. return m.Client().Task.Query().Where(m.predicates...).IDs(ctx)
  139. default:
  140. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  141. }
  142. }
  143. // SetCreatedAt sets the "created_at" field.
  144. func (m *TaskMutation) SetCreatedAt(t time.Time) {
  145. m.created_at = &t
  146. }
  147. // CreatedAt returns the value of the "created_at" field in the mutation.
  148. func (m *TaskMutation) CreatedAt() (r time.Time, exists bool) {
  149. v := m.created_at
  150. if v == nil {
  151. return
  152. }
  153. return *v, true
  154. }
  155. // OldCreatedAt returns the old "created_at" field's value of the Task entity.
  156. // If the Task object wasn't provided to the builder, the object is fetched from the database.
  157. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  158. func (m *TaskMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  159. if !m.op.Is(OpUpdateOne) {
  160. return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  161. }
  162. if m.id == nil || m.oldValue == nil {
  163. return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  164. }
  165. oldValue, err := m.oldValue(ctx)
  166. if err != nil {
  167. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  168. }
  169. return oldValue.CreatedAt, nil
  170. }
  171. // ResetCreatedAt resets all changes to the "created_at" field.
  172. func (m *TaskMutation) ResetCreatedAt() {
  173. m.created_at = nil
  174. }
  175. // SetUpdatedAt sets the "updated_at" field.
  176. func (m *TaskMutation) SetUpdatedAt(t time.Time) {
  177. m.updated_at = &t
  178. }
  179. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  180. func (m *TaskMutation) UpdatedAt() (r time.Time, exists bool) {
  181. v := m.updated_at
  182. if v == nil {
  183. return
  184. }
  185. return *v, true
  186. }
  187. // OldUpdatedAt returns the old "updated_at" field's value of the Task entity.
  188. // If the Task object wasn't provided to the builder, the object is fetched from the database.
  189. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  190. func (m *TaskMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  191. if !m.op.Is(OpUpdateOne) {
  192. return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  193. }
  194. if m.id == nil || m.oldValue == nil {
  195. return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  196. }
  197. oldValue, err := m.oldValue(ctx)
  198. if err != nil {
  199. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  200. }
  201. return oldValue.UpdatedAt, nil
  202. }
  203. // ResetUpdatedAt resets all changes to the "updated_at" field.
  204. func (m *TaskMutation) ResetUpdatedAt() {
  205. m.updated_at = nil
  206. }
  207. // SetStatus sets the "status" field.
  208. func (m *TaskMutation) SetStatus(u uint8) {
  209. m.status = &u
  210. m.addstatus = nil
  211. }
  212. // Status returns the value of the "status" field in the mutation.
  213. func (m *TaskMutation) Status() (r uint8, exists bool) {
  214. v := m.status
  215. if v == nil {
  216. return
  217. }
  218. return *v, true
  219. }
  220. // OldStatus returns the old "status" field's value of the Task entity.
  221. // If the Task object wasn't provided to the builder, the object is fetched from the database.
  222. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  223. func (m *TaskMutation) OldStatus(ctx context.Context) (v uint8, err error) {
  224. if !m.op.Is(OpUpdateOne) {
  225. return v, errors.New("OldStatus is only allowed on UpdateOne operations")
  226. }
  227. if m.id == nil || m.oldValue == nil {
  228. return v, errors.New("OldStatus requires an ID field in the mutation")
  229. }
  230. oldValue, err := m.oldValue(ctx)
  231. if err != nil {
  232. return v, fmt.Errorf("querying old value for OldStatus: %w", err)
  233. }
  234. return oldValue.Status, nil
  235. }
  236. // AddStatus adds u to the "status" field.
  237. func (m *TaskMutation) AddStatus(u int8) {
  238. if m.addstatus != nil {
  239. *m.addstatus += u
  240. } else {
  241. m.addstatus = &u
  242. }
  243. }
  244. // AddedStatus returns the value that was added to the "status" field in this mutation.
  245. func (m *TaskMutation) AddedStatus() (r int8, exists bool) {
  246. v := m.addstatus
  247. if v == nil {
  248. return
  249. }
  250. return *v, true
  251. }
  252. // ClearStatus clears the value of the "status" field.
  253. func (m *TaskMutation) ClearStatus() {
  254. m.status = nil
  255. m.addstatus = nil
  256. m.clearedFields[task.FieldStatus] = struct{}{}
  257. }
  258. // StatusCleared returns if the "status" field was cleared in this mutation.
  259. func (m *TaskMutation) StatusCleared() bool {
  260. _, ok := m.clearedFields[task.FieldStatus]
  261. return ok
  262. }
  263. // ResetStatus resets all changes to the "status" field.
  264. func (m *TaskMutation) ResetStatus() {
  265. m.status = nil
  266. m.addstatus = nil
  267. delete(m.clearedFields, task.FieldStatus)
  268. }
  269. // SetName sets the "name" field.
  270. func (m *TaskMutation) SetName(s string) {
  271. m.name = &s
  272. }
  273. // Name returns the value of the "name" field in the mutation.
  274. func (m *TaskMutation) Name() (r string, exists bool) {
  275. v := m.name
  276. if v == nil {
  277. return
  278. }
  279. return *v, true
  280. }
  281. // OldName returns the old "name" field's value of the Task entity.
  282. // If the Task object wasn't provided to the builder, the object is fetched from the database.
  283. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  284. func (m *TaskMutation) OldName(ctx context.Context) (v string, err error) {
  285. if !m.op.Is(OpUpdateOne) {
  286. return v, errors.New("OldName is only allowed on UpdateOne operations")
  287. }
  288. if m.id == nil || m.oldValue == nil {
  289. return v, errors.New("OldName requires an ID field in the mutation")
  290. }
  291. oldValue, err := m.oldValue(ctx)
  292. if err != nil {
  293. return v, fmt.Errorf("querying old value for OldName: %w", err)
  294. }
  295. return oldValue.Name, nil
  296. }
  297. // ResetName resets all changes to the "name" field.
  298. func (m *TaskMutation) ResetName() {
  299. m.name = nil
  300. }
  301. // SetTaskGroup sets the "task_group" field.
  302. func (m *TaskMutation) SetTaskGroup(s string) {
  303. m.task_group = &s
  304. }
  305. // TaskGroup returns the value of the "task_group" field in the mutation.
  306. func (m *TaskMutation) TaskGroup() (r string, exists bool) {
  307. v := m.task_group
  308. if v == nil {
  309. return
  310. }
  311. return *v, true
  312. }
  313. // OldTaskGroup returns the old "task_group" field's value of the Task entity.
  314. // If the Task object wasn't provided to the builder, the object is fetched from the database.
  315. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  316. func (m *TaskMutation) OldTaskGroup(ctx context.Context) (v string, err error) {
  317. if !m.op.Is(OpUpdateOne) {
  318. return v, errors.New("OldTaskGroup is only allowed on UpdateOne operations")
  319. }
  320. if m.id == nil || m.oldValue == nil {
  321. return v, errors.New("OldTaskGroup requires an ID field in the mutation")
  322. }
  323. oldValue, err := m.oldValue(ctx)
  324. if err != nil {
  325. return v, fmt.Errorf("querying old value for OldTaskGroup: %w", err)
  326. }
  327. return oldValue.TaskGroup, nil
  328. }
  329. // ResetTaskGroup resets all changes to the "task_group" field.
  330. func (m *TaskMutation) ResetTaskGroup() {
  331. m.task_group = nil
  332. }
  333. // SetCronExpression sets the "cron_expression" field.
  334. func (m *TaskMutation) SetCronExpression(s string) {
  335. m.cron_expression = &s
  336. }
  337. // CronExpression returns the value of the "cron_expression" field in the mutation.
  338. func (m *TaskMutation) CronExpression() (r string, exists bool) {
  339. v := m.cron_expression
  340. if v == nil {
  341. return
  342. }
  343. return *v, true
  344. }
  345. // OldCronExpression returns the old "cron_expression" field's value of the Task entity.
  346. // If the Task object wasn't provided to the builder, the object is fetched from the database.
  347. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  348. func (m *TaskMutation) OldCronExpression(ctx context.Context) (v string, err error) {
  349. if !m.op.Is(OpUpdateOne) {
  350. return v, errors.New("OldCronExpression is only allowed on UpdateOne operations")
  351. }
  352. if m.id == nil || m.oldValue == nil {
  353. return v, errors.New("OldCronExpression requires an ID field in the mutation")
  354. }
  355. oldValue, err := m.oldValue(ctx)
  356. if err != nil {
  357. return v, fmt.Errorf("querying old value for OldCronExpression: %w", err)
  358. }
  359. return oldValue.CronExpression, nil
  360. }
  361. // ResetCronExpression resets all changes to the "cron_expression" field.
  362. func (m *TaskMutation) ResetCronExpression() {
  363. m.cron_expression = nil
  364. }
  365. // SetPattern sets the "pattern" field.
  366. func (m *TaskMutation) SetPattern(s string) {
  367. m.pattern = &s
  368. }
  369. // Pattern returns the value of the "pattern" field in the mutation.
  370. func (m *TaskMutation) Pattern() (r string, exists bool) {
  371. v := m.pattern
  372. if v == nil {
  373. return
  374. }
  375. return *v, true
  376. }
  377. // OldPattern returns the old "pattern" field's value of the Task entity.
  378. // If the Task object wasn't provided to the builder, the object is fetched from the database.
  379. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  380. func (m *TaskMutation) OldPattern(ctx context.Context) (v string, err error) {
  381. if !m.op.Is(OpUpdateOne) {
  382. return v, errors.New("OldPattern is only allowed on UpdateOne operations")
  383. }
  384. if m.id == nil || m.oldValue == nil {
  385. return v, errors.New("OldPattern requires an ID field in the mutation")
  386. }
  387. oldValue, err := m.oldValue(ctx)
  388. if err != nil {
  389. return v, fmt.Errorf("querying old value for OldPattern: %w", err)
  390. }
  391. return oldValue.Pattern, nil
  392. }
  393. // ResetPattern resets all changes to the "pattern" field.
  394. func (m *TaskMutation) ResetPattern() {
  395. m.pattern = nil
  396. }
  397. // SetPayload sets the "payload" field.
  398. func (m *TaskMutation) SetPayload(s string) {
  399. m.payload = &s
  400. }
  401. // Payload returns the value of the "payload" field in the mutation.
  402. func (m *TaskMutation) Payload() (r string, exists bool) {
  403. v := m.payload
  404. if v == nil {
  405. return
  406. }
  407. return *v, true
  408. }
  409. // OldPayload returns the old "payload" field's value of the Task entity.
  410. // If the Task object wasn't provided to the builder, the object is fetched from the database.
  411. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  412. func (m *TaskMutation) OldPayload(ctx context.Context) (v string, err error) {
  413. if !m.op.Is(OpUpdateOne) {
  414. return v, errors.New("OldPayload is only allowed on UpdateOne operations")
  415. }
  416. if m.id == nil || m.oldValue == nil {
  417. return v, errors.New("OldPayload requires an ID field in the mutation")
  418. }
  419. oldValue, err := m.oldValue(ctx)
  420. if err != nil {
  421. return v, fmt.Errorf("querying old value for OldPayload: %w", err)
  422. }
  423. return oldValue.Payload, nil
  424. }
  425. // ResetPayload resets all changes to the "payload" field.
  426. func (m *TaskMutation) ResetPayload() {
  427. m.payload = nil
  428. }
  429. // AddTaskLogIDs adds the "task_logs" edge to the TaskLog entity by ids.
  430. func (m *TaskMutation) AddTaskLogIDs(ids ...uint64) {
  431. if m.task_logs == nil {
  432. m.task_logs = make(map[uint64]struct{})
  433. }
  434. for i := range ids {
  435. m.task_logs[ids[i]] = struct{}{}
  436. }
  437. }
  438. // ClearTaskLogs clears the "task_logs" edge to the TaskLog entity.
  439. func (m *TaskMutation) ClearTaskLogs() {
  440. m.clearedtask_logs = true
  441. }
  442. // TaskLogsCleared reports if the "task_logs" edge to the TaskLog entity was cleared.
  443. func (m *TaskMutation) TaskLogsCleared() bool {
  444. return m.clearedtask_logs
  445. }
  446. // RemoveTaskLogIDs removes the "task_logs" edge to the TaskLog entity by IDs.
  447. func (m *TaskMutation) RemoveTaskLogIDs(ids ...uint64) {
  448. if m.removedtask_logs == nil {
  449. m.removedtask_logs = make(map[uint64]struct{})
  450. }
  451. for i := range ids {
  452. delete(m.task_logs, ids[i])
  453. m.removedtask_logs[ids[i]] = struct{}{}
  454. }
  455. }
  456. // RemovedTaskLogs returns the removed IDs of the "task_logs" edge to the TaskLog entity.
  457. func (m *TaskMutation) RemovedTaskLogsIDs() (ids []uint64) {
  458. for id := range m.removedtask_logs {
  459. ids = append(ids, id)
  460. }
  461. return
  462. }
  463. // TaskLogsIDs returns the "task_logs" edge IDs in the mutation.
  464. func (m *TaskMutation) TaskLogsIDs() (ids []uint64) {
  465. for id := range m.task_logs {
  466. ids = append(ids, id)
  467. }
  468. return
  469. }
  470. // ResetTaskLogs resets all changes to the "task_logs" edge.
  471. func (m *TaskMutation) ResetTaskLogs() {
  472. m.task_logs = nil
  473. m.clearedtask_logs = false
  474. m.removedtask_logs = nil
  475. }
  476. // Where appends a list predicates to the TaskMutation builder.
  477. func (m *TaskMutation) Where(ps ...predicate.Task) {
  478. m.predicates = append(m.predicates, ps...)
  479. }
  480. // WhereP appends storage-level predicates to the TaskMutation builder. Using this method,
  481. // users can use type-assertion to append predicates that do not depend on any generated package.
  482. func (m *TaskMutation) WhereP(ps ...func(*sql.Selector)) {
  483. p := make([]predicate.Task, len(ps))
  484. for i := range ps {
  485. p[i] = ps[i]
  486. }
  487. m.Where(p...)
  488. }
  489. // Op returns the operation name.
  490. func (m *TaskMutation) Op() Op {
  491. return m.op
  492. }
  493. // SetOp allows setting the mutation operation.
  494. func (m *TaskMutation) SetOp(op Op) {
  495. m.op = op
  496. }
  497. // Type returns the node type of this mutation (Task).
  498. func (m *TaskMutation) Type() string {
  499. return m.typ
  500. }
  501. // Fields returns all fields that were changed during this mutation. Note that in
  502. // order to get all numeric fields that were incremented/decremented, call
  503. // AddedFields().
  504. func (m *TaskMutation) Fields() []string {
  505. fields := make([]string, 0, 8)
  506. if m.created_at != nil {
  507. fields = append(fields, task.FieldCreatedAt)
  508. }
  509. if m.updated_at != nil {
  510. fields = append(fields, task.FieldUpdatedAt)
  511. }
  512. if m.status != nil {
  513. fields = append(fields, task.FieldStatus)
  514. }
  515. if m.name != nil {
  516. fields = append(fields, task.FieldName)
  517. }
  518. if m.task_group != nil {
  519. fields = append(fields, task.FieldTaskGroup)
  520. }
  521. if m.cron_expression != nil {
  522. fields = append(fields, task.FieldCronExpression)
  523. }
  524. if m.pattern != nil {
  525. fields = append(fields, task.FieldPattern)
  526. }
  527. if m.payload != nil {
  528. fields = append(fields, task.FieldPayload)
  529. }
  530. return fields
  531. }
  532. // Field returns the value of a field with the given name. The second boolean
  533. // return value indicates that this field was not set, or was not defined in the
  534. // schema.
  535. func (m *TaskMutation) Field(name string) (ent.Value, bool) {
  536. switch name {
  537. case task.FieldCreatedAt:
  538. return m.CreatedAt()
  539. case task.FieldUpdatedAt:
  540. return m.UpdatedAt()
  541. case task.FieldStatus:
  542. return m.Status()
  543. case task.FieldName:
  544. return m.Name()
  545. case task.FieldTaskGroup:
  546. return m.TaskGroup()
  547. case task.FieldCronExpression:
  548. return m.CronExpression()
  549. case task.FieldPattern:
  550. return m.Pattern()
  551. case task.FieldPayload:
  552. return m.Payload()
  553. }
  554. return nil, false
  555. }
  556. // OldField returns the old value of the field from the database. An error is
  557. // returned if the mutation operation is not UpdateOne, or the query to the
  558. // database failed.
  559. func (m *TaskMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  560. switch name {
  561. case task.FieldCreatedAt:
  562. return m.OldCreatedAt(ctx)
  563. case task.FieldUpdatedAt:
  564. return m.OldUpdatedAt(ctx)
  565. case task.FieldStatus:
  566. return m.OldStatus(ctx)
  567. case task.FieldName:
  568. return m.OldName(ctx)
  569. case task.FieldTaskGroup:
  570. return m.OldTaskGroup(ctx)
  571. case task.FieldCronExpression:
  572. return m.OldCronExpression(ctx)
  573. case task.FieldPattern:
  574. return m.OldPattern(ctx)
  575. case task.FieldPayload:
  576. return m.OldPayload(ctx)
  577. }
  578. return nil, fmt.Errorf("unknown Task field %s", name)
  579. }
  580. // SetField sets the value of a field with the given name. It returns an error if
  581. // the field is not defined in the schema, or if the type mismatched the field
  582. // type.
  583. func (m *TaskMutation) SetField(name string, value ent.Value) error {
  584. switch name {
  585. case task.FieldCreatedAt:
  586. v, ok := value.(time.Time)
  587. if !ok {
  588. return fmt.Errorf("unexpected type %T for field %s", value, name)
  589. }
  590. m.SetCreatedAt(v)
  591. return nil
  592. case task.FieldUpdatedAt:
  593. v, ok := value.(time.Time)
  594. if !ok {
  595. return fmt.Errorf("unexpected type %T for field %s", value, name)
  596. }
  597. m.SetUpdatedAt(v)
  598. return nil
  599. case task.FieldStatus:
  600. v, ok := value.(uint8)
  601. if !ok {
  602. return fmt.Errorf("unexpected type %T for field %s", value, name)
  603. }
  604. m.SetStatus(v)
  605. return nil
  606. case task.FieldName:
  607. v, ok := value.(string)
  608. if !ok {
  609. return fmt.Errorf("unexpected type %T for field %s", value, name)
  610. }
  611. m.SetName(v)
  612. return nil
  613. case task.FieldTaskGroup:
  614. v, ok := value.(string)
  615. if !ok {
  616. return fmt.Errorf("unexpected type %T for field %s", value, name)
  617. }
  618. m.SetTaskGroup(v)
  619. return nil
  620. case task.FieldCronExpression:
  621. v, ok := value.(string)
  622. if !ok {
  623. return fmt.Errorf("unexpected type %T for field %s", value, name)
  624. }
  625. m.SetCronExpression(v)
  626. return nil
  627. case task.FieldPattern:
  628. v, ok := value.(string)
  629. if !ok {
  630. return fmt.Errorf("unexpected type %T for field %s", value, name)
  631. }
  632. m.SetPattern(v)
  633. return nil
  634. case task.FieldPayload:
  635. v, ok := value.(string)
  636. if !ok {
  637. return fmt.Errorf("unexpected type %T for field %s", value, name)
  638. }
  639. m.SetPayload(v)
  640. return nil
  641. }
  642. return fmt.Errorf("unknown Task field %s", name)
  643. }
  644. // AddedFields returns all numeric fields that were incremented/decremented during
  645. // this mutation.
  646. func (m *TaskMutation) AddedFields() []string {
  647. var fields []string
  648. if m.addstatus != nil {
  649. fields = append(fields, task.FieldStatus)
  650. }
  651. return fields
  652. }
  653. // AddedField returns the numeric value that was incremented/decremented on a field
  654. // with the given name. The second boolean return value indicates that this field
  655. // was not set, or was not defined in the schema.
  656. func (m *TaskMutation) AddedField(name string) (ent.Value, bool) {
  657. switch name {
  658. case task.FieldStatus:
  659. return m.AddedStatus()
  660. }
  661. return nil, false
  662. }
  663. // AddField adds the value to the field with the given name. It returns an error if
  664. // the field is not defined in the schema, or if the type mismatched the field
  665. // type.
  666. func (m *TaskMutation) AddField(name string, value ent.Value) error {
  667. switch name {
  668. case task.FieldStatus:
  669. v, ok := value.(int8)
  670. if !ok {
  671. return fmt.Errorf("unexpected type %T for field %s", value, name)
  672. }
  673. m.AddStatus(v)
  674. return nil
  675. }
  676. return fmt.Errorf("unknown Task numeric field %s", name)
  677. }
  678. // ClearedFields returns all nullable fields that were cleared during this
  679. // mutation.
  680. func (m *TaskMutation) ClearedFields() []string {
  681. var fields []string
  682. if m.FieldCleared(task.FieldStatus) {
  683. fields = append(fields, task.FieldStatus)
  684. }
  685. return fields
  686. }
  687. // FieldCleared returns a boolean indicating if a field with the given name was
  688. // cleared in this mutation.
  689. func (m *TaskMutation) FieldCleared(name string) bool {
  690. _, ok := m.clearedFields[name]
  691. return ok
  692. }
  693. // ClearField clears the value of the field with the given name. It returns an
  694. // error if the field is not defined in the schema.
  695. func (m *TaskMutation) ClearField(name string) error {
  696. switch name {
  697. case task.FieldStatus:
  698. m.ClearStatus()
  699. return nil
  700. }
  701. return fmt.Errorf("unknown Task nullable field %s", name)
  702. }
  703. // ResetField resets all changes in the mutation for the field with the given name.
  704. // It returns an error if the field is not defined in the schema.
  705. func (m *TaskMutation) ResetField(name string) error {
  706. switch name {
  707. case task.FieldCreatedAt:
  708. m.ResetCreatedAt()
  709. return nil
  710. case task.FieldUpdatedAt:
  711. m.ResetUpdatedAt()
  712. return nil
  713. case task.FieldStatus:
  714. m.ResetStatus()
  715. return nil
  716. case task.FieldName:
  717. m.ResetName()
  718. return nil
  719. case task.FieldTaskGroup:
  720. m.ResetTaskGroup()
  721. return nil
  722. case task.FieldCronExpression:
  723. m.ResetCronExpression()
  724. return nil
  725. case task.FieldPattern:
  726. m.ResetPattern()
  727. return nil
  728. case task.FieldPayload:
  729. m.ResetPayload()
  730. return nil
  731. }
  732. return fmt.Errorf("unknown Task field %s", name)
  733. }
  734. // AddedEdges returns all edge names that were set/added in this mutation.
  735. func (m *TaskMutation) AddedEdges() []string {
  736. edges := make([]string, 0, 1)
  737. if m.task_logs != nil {
  738. edges = append(edges, task.EdgeTaskLogs)
  739. }
  740. return edges
  741. }
  742. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  743. // name in this mutation.
  744. func (m *TaskMutation) AddedIDs(name string) []ent.Value {
  745. switch name {
  746. case task.EdgeTaskLogs:
  747. ids := make([]ent.Value, 0, len(m.task_logs))
  748. for id := range m.task_logs {
  749. ids = append(ids, id)
  750. }
  751. return ids
  752. }
  753. return nil
  754. }
  755. // RemovedEdges returns all edge names that were removed in this mutation.
  756. func (m *TaskMutation) RemovedEdges() []string {
  757. edges := make([]string, 0, 1)
  758. if m.removedtask_logs != nil {
  759. edges = append(edges, task.EdgeTaskLogs)
  760. }
  761. return edges
  762. }
  763. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  764. // the given name in this mutation.
  765. func (m *TaskMutation) RemovedIDs(name string) []ent.Value {
  766. switch name {
  767. case task.EdgeTaskLogs:
  768. ids := make([]ent.Value, 0, len(m.removedtask_logs))
  769. for id := range m.removedtask_logs {
  770. ids = append(ids, id)
  771. }
  772. return ids
  773. }
  774. return nil
  775. }
  776. // ClearedEdges returns all edge names that were cleared in this mutation.
  777. func (m *TaskMutation) ClearedEdges() []string {
  778. edges := make([]string, 0, 1)
  779. if m.clearedtask_logs {
  780. edges = append(edges, task.EdgeTaskLogs)
  781. }
  782. return edges
  783. }
  784. // EdgeCleared returns a boolean which indicates if the edge with the given name
  785. // was cleared in this mutation.
  786. func (m *TaskMutation) EdgeCleared(name string) bool {
  787. switch name {
  788. case task.EdgeTaskLogs:
  789. return m.clearedtask_logs
  790. }
  791. return false
  792. }
  793. // ClearEdge clears the value of the edge with the given name. It returns an error
  794. // if that edge is not defined in the schema.
  795. func (m *TaskMutation) ClearEdge(name string) error {
  796. switch name {
  797. }
  798. return fmt.Errorf("unknown Task unique edge %s", name)
  799. }
  800. // ResetEdge resets all changes to the edge with the given name in this mutation.
  801. // It returns an error if the edge is not defined in the schema.
  802. func (m *TaskMutation) ResetEdge(name string) error {
  803. switch name {
  804. case task.EdgeTaskLogs:
  805. m.ResetTaskLogs()
  806. return nil
  807. }
  808. return fmt.Errorf("unknown Task edge %s", name)
  809. }
  810. // TaskLogMutation represents an operation that mutates the TaskLog nodes in the graph.
  811. type TaskLogMutation struct {
  812. config
  813. op Op
  814. typ string
  815. id *uint64
  816. started_at *time.Time
  817. finished_at *time.Time
  818. result *uint8
  819. addresult *int8
  820. clearedFields map[string]struct{}
  821. tasks *uint64
  822. clearedtasks bool
  823. done bool
  824. oldValue func(context.Context) (*TaskLog, error)
  825. predicates []predicate.TaskLog
  826. }
  827. var _ ent.Mutation = (*TaskLogMutation)(nil)
  828. // tasklogOption allows management of the mutation configuration using functional options.
  829. type tasklogOption func(*TaskLogMutation)
  830. // newTaskLogMutation creates new mutation for the TaskLog entity.
  831. func newTaskLogMutation(c config, op Op, opts ...tasklogOption) *TaskLogMutation {
  832. m := &TaskLogMutation{
  833. config: c,
  834. op: op,
  835. typ: TypeTaskLog,
  836. clearedFields: make(map[string]struct{}),
  837. }
  838. for _, opt := range opts {
  839. opt(m)
  840. }
  841. return m
  842. }
  843. // withTaskLogID sets the ID field of the mutation.
  844. func withTaskLogID(id uint64) tasklogOption {
  845. return func(m *TaskLogMutation) {
  846. var (
  847. err error
  848. once sync.Once
  849. value *TaskLog
  850. )
  851. m.oldValue = func(ctx context.Context) (*TaskLog, error) {
  852. once.Do(func() {
  853. if m.done {
  854. err = errors.New("querying old values post mutation is not allowed")
  855. } else {
  856. value, err = m.Client().TaskLog.Get(ctx, id)
  857. }
  858. })
  859. return value, err
  860. }
  861. m.id = &id
  862. }
  863. }
  864. // withTaskLog sets the old TaskLog of the mutation.
  865. func withTaskLog(node *TaskLog) tasklogOption {
  866. return func(m *TaskLogMutation) {
  867. m.oldValue = func(context.Context) (*TaskLog, error) {
  868. return node, nil
  869. }
  870. m.id = &node.ID
  871. }
  872. }
  873. // Client returns a new `ent.Client` from the mutation. If the mutation was
  874. // executed in a transaction (ent.Tx), a transactional client is returned.
  875. func (m TaskLogMutation) Client() *Client {
  876. client := &Client{config: m.config}
  877. client.init()
  878. return client
  879. }
  880. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  881. // it returns an error otherwise.
  882. func (m TaskLogMutation) Tx() (*Tx, error) {
  883. if _, ok := m.driver.(*txDriver); !ok {
  884. return nil, errors.New("ent: mutation is not running in a transaction")
  885. }
  886. tx := &Tx{config: m.config}
  887. tx.init()
  888. return tx, nil
  889. }
  890. // SetID sets the value of the id field. Note that this
  891. // operation is only accepted on creation of TaskLog entities.
  892. func (m *TaskLogMutation) SetID(id uint64) {
  893. m.id = &id
  894. }
  895. // ID returns the ID value in the mutation. Note that the ID is only available
  896. // if it was provided to the builder or after it was returned from the database.
  897. func (m *TaskLogMutation) ID() (id uint64, exists bool) {
  898. if m.id == nil {
  899. return
  900. }
  901. return *m.id, true
  902. }
  903. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  904. // That means, if the mutation is applied within a transaction with an isolation level such
  905. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  906. // or updated by the mutation.
  907. func (m *TaskLogMutation) IDs(ctx context.Context) ([]uint64, error) {
  908. switch {
  909. case m.op.Is(OpUpdateOne | OpDeleteOne):
  910. id, exists := m.ID()
  911. if exists {
  912. return []uint64{id}, nil
  913. }
  914. fallthrough
  915. case m.op.Is(OpUpdate | OpDelete):
  916. return m.Client().TaskLog.Query().Where(m.predicates...).IDs(ctx)
  917. default:
  918. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  919. }
  920. }
  921. // SetStartedAt sets the "started_at" field.
  922. func (m *TaskLogMutation) SetStartedAt(t time.Time) {
  923. m.started_at = &t
  924. }
  925. // StartedAt returns the value of the "started_at" field in the mutation.
  926. func (m *TaskLogMutation) StartedAt() (r time.Time, exists bool) {
  927. v := m.started_at
  928. if v == nil {
  929. return
  930. }
  931. return *v, true
  932. }
  933. // OldStartedAt returns the old "started_at" field's value of the TaskLog entity.
  934. // If the TaskLog object wasn't provided to the builder, the object is fetched from the database.
  935. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  936. func (m *TaskLogMutation) OldStartedAt(ctx context.Context) (v time.Time, err error) {
  937. if !m.op.Is(OpUpdateOne) {
  938. return v, errors.New("OldStartedAt is only allowed on UpdateOne operations")
  939. }
  940. if m.id == nil || m.oldValue == nil {
  941. return v, errors.New("OldStartedAt requires an ID field in the mutation")
  942. }
  943. oldValue, err := m.oldValue(ctx)
  944. if err != nil {
  945. return v, fmt.Errorf("querying old value for OldStartedAt: %w", err)
  946. }
  947. return oldValue.StartedAt, nil
  948. }
  949. // ResetStartedAt resets all changes to the "started_at" field.
  950. func (m *TaskLogMutation) ResetStartedAt() {
  951. m.started_at = nil
  952. }
  953. // SetFinishedAt sets the "finished_at" field.
  954. func (m *TaskLogMutation) SetFinishedAt(t time.Time) {
  955. m.finished_at = &t
  956. }
  957. // FinishedAt returns the value of the "finished_at" field in the mutation.
  958. func (m *TaskLogMutation) FinishedAt() (r time.Time, exists bool) {
  959. v := m.finished_at
  960. if v == nil {
  961. return
  962. }
  963. return *v, true
  964. }
  965. // OldFinishedAt returns the old "finished_at" field's value of the TaskLog entity.
  966. // If the TaskLog object wasn't provided to the builder, the object is fetched from the database.
  967. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  968. func (m *TaskLogMutation) OldFinishedAt(ctx context.Context) (v time.Time, err error) {
  969. if !m.op.Is(OpUpdateOne) {
  970. return v, errors.New("OldFinishedAt is only allowed on UpdateOne operations")
  971. }
  972. if m.id == nil || m.oldValue == nil {
  973. return v, errors.New("OldFinishedAt requires an ID field in the mutation")
  974. }
  975. oldValue, err := m.oldValue(ctx)
  976. if err != nil {
  977. return v, fmt.Errorf("querying old value for OldFinishedAt: %w", err)
  978. }
  979. return oldValue.FinishedAt, nil
  980. }
  981. // ResetFinishedAt resets all changes to the "finished_at" field.
  982. func (m *TaskLogMutation) ResetFinishedAt() {
  983. m.finished_at = nil
  984. }
  985. // SetResult sets the "result" field.
  986. func (m *TaskLogMutation) SetResult(u uint8) {
  987. m.result = &u
  988. m.addresult = nil
  989. }
  990. // Result returns the value of the "result" field in the mutation.
  991. func (m *TaskLogMutation) Result() (r uint8, exists bool) {
  992. v := m.result
  993. if v == nil {
  994. return
  995. }
  996. return *v, true
  997. }
  998. // OldResult returns the old "result" field's value of the TaskLog entity.
  999. // If the TaskLog object wasn't provided to the builder, the object is fetched from the database.
  1000. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1001. func (m *TaskLogMutation) OldResult(ctx context.Context) (v uint8, err error) {
  1002. if !m.op.Is(OpUpdateOne) {
  1003. return v, errors.New("OldResult is only allowed on UpdateOne operations")
  1004. }
  1005. if m.id == nil || m.oldValue == nil {
  1006. return v, errors.New("OldResult requires an ID field in the mutation")
  1007. }
  1008. oldValue, err := m.oldValue(ctx)
  1009. if err != nil {
  1010. return v, fmt.Errorf("querying old value for OldResult: %w", err)
  1011. }
  1012. return oldValue.Result, nil
  1013. }
  1014. // AddResult adds u to the "result" field.
  1015. func (m *TaskLogMutation) AddResult(u int8) {
  1016. if m.addresult != nil {
  1017. *m.addresult += u
  1018. } else {
  1019. m.addresult = &u
  1020. }
  1021. }
  1022. // AddedResult returns the value that was added to the "result" field in this mutation.
  1023. func (m *TaskLogMutation) AddedResult() (r int8, exists bool) {
  1024. v := m.addresult
  1025. if v == nil {
  1026. return
  1027. }
  1028. return *v, true
  1029. }
  1030. // ResetResult resets all changes to the "result" field.
  1031. func (m *TaskLogMutation) ResetResult() {
  1032. m.result = nil
  1033. m.addresult = nil
  1034. }
  1035. // SetTasksID sets the "tasks" edge to the Task entity by id.
  1036. func (m *TaskLogMutation) SetTasksID(id uint64) {
  1037. m.tasks = &id
  1038. }
  1039. // ClearTasks clears the "tasks" edge to the Task entity.
  1040. func (m *TaskLogMutation) ClearTasks() {
  1041. m.clearedtasks = true
  1042. }
  1043. // TasksCleared reports if the "tasks" edge to the Task entity was cleared.
  1044. func (m *TaskLogMutation) TasksCleared() bool {
  1045. return m.clearedtasks
  1046. }
  1047. // TasksID returns the "tasks" edge ID in the mutation.
  1048. func (m *TaskLogMutation) TasksID() (id uint64, exists bool) {
  1049. if m.tasks != nil {
  1050. return *m.tasks, true
  1051. }
  1052. return
  1053. }
  1054. // TasksIDs returns the "tasks" edge IDs in the mutation.
  1055. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  1056. // TasksID instead. It exists only for internal usage by the builders.
  1057. func (m *TaskLogMutation) TasksIDs() (ids []uint64) {
  1058. if id := m.tasks; id != nil {
  1059. ids = append(ids, *id)
  1060. }
  1061. return
  1062. }
  1063. // ResetTasks resets all changes to the "tasks" edge.
  1064. func (m *TaskLogMutation) ResetTasks() {
  1065. m.tasks = nil
  1066. m.clearedtasks = false
  1067. }
  1068. // Where appends a list predicates to the TaskLogMutation builder.
  1069. func (m *TaskLogMutation) Where(ps ...predicate.TaskLog) {
  1070. m.predicates = append(m.predicates, ps...)
  1071. }
  1072. // WhereP appends storage-level predicates to the TaskLogMutation builder. Using this method,
  1073. // users can use type-assertion to append predicates that do not depend on any generated package.
  1074. func (m *TaskLogMutation) WhereP(ps ...func(*sql.Selector)) {
  1075. p := make([]predicate.TaskLog, len(ps))
  1076. for i := range ps {
  1077. p[i] = ps[i]
  1078. }
  1079. m.Where(p...)
  1080. }
  1081. // Op returns the operation name.
  1082. func (m *TaskLogMutation) Op() Op {
  1083. return m.op
  1084. }
  1085. // SetOp allows setting the mutation operation.
  1086. func (m *TaskLogMutation) SetOp(op Op) {
  1087. m.op = op
  1088. }
  1089. // Type returns the node type of this mutation (TaskLog).
  1090. func (m *TaskLogMutation) Type() string {
  1091. return m.typ
  1092. }
  1093. // Fields returns all fields that were changed during this mutation. Note that in
  1094. // order to get all numeric fields that were incremented/decremented, call
  1095. // AddedFields().
  1096. func (m *TaskLogMutation) Fields() []string {
  1097. fields := make([]string, 0, 3)
  1098. if m.started_at != nil {
  1099. fields = append(fields, tasklog.FieldStartedAt)
  1100. }
  1101. if m.finished_at != nil {
  1102. fields = append(fields, tasklog.FieldFinishedAt)
  1103. }
  1104. if m.result != nil {
  1105. fields = append(fields, tasklog.FieldResult)
  1106. }
  1107. return fields
  1108. }
  1109. // Field returns the value of a field with the given name. The second boolean
  1110. // return value indicates that this field was not set, or was not defined in the
  1111. // schema.
  1112. func (m *TaskLogMutation) Field(name string) (ent.Value, bool) {
  1113. switch name {
  1114. case tasklog.FieldStartedAt:
  1115. return m.StartedAt()
  1116. case tasklog.FieldFinishedAt:
  1117. return m.FinishedAt()
  1118. case tasklog.FieldResult:
  1119. return m.Result()
  1120. }
  1121. return nil, false
  1122. }
  1123. // OldField returns the old value of the field from the database. An error is
  1124. // returned if the mutation operation is not UpdateOne, or the query to the
  1125. // database failed.
  1126. func (m *TaskLogMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  1127. switch name {
  1128. case tasklog.FieldStartedAt:
  1129. return m.OldStartedAt(ctx)
  1130. case tasklog.FieldFinishedAt:
  1131. return m.OldFinishedAt(ctx)
  1132. case tasklog.FieldResult:
  1133. return m.OldResult(ctx)
  1134. }
  1135. return nil, fmt.Errorf("unknown TaskLog field %s", name)
  1136. }
  1137. // SetField sets the value of a field with the given name. It returns an error if
  1138. // the field is not defined in the schema, or if the type mismatched the field
  1139. // type.
  1140. func (m *TaskLogMutation) SetField(name string, value ent.Value) error {
  1141. switch name {
  1142. case tasklog.FieldStartedAt:
  1143. v, ok := value.(time.Time)
  1144. if !ok {
  1145. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1146. }
  1147. m.SetStartedAt(v)
  1148. return nil
  1149. case tasklog.FieldFinishedAt:
  1150. v, ok := value.(time.Time)
  1151. if !ok {
  1152. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1153. }
  1154. m.SetFinishedAt(v)
  1155. return nil
  1156. case tasklog.FieldResult:
  1157. v, ok := value.(uint8)
  1158. if !ok {
  1159. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1160. }
  1161. m.SetResult(v)
  1162. return nil
  1163. }
  1164. return fmt.Errorf("unknown TaskLog field %s", name)
  1165. }
  1166. // AddedFields returns all numeric fields that were incremented/decremented during
  1167. // this mutation.
  1168. func (m *TaskLogMutation) AddedFields() []string {
  1169. var fields []string
  1170. if m.addresult != nil {
  1171. fields = append(fields, tasklog.FieldResult)
  1172. }
  1173. return fields
  1174. }
  1175. // AddedField returns the numeric value that was incremented/decremented on a field
  1176. // with the given name. The second boolean return value indicates that this field
  1177. // was not set, or was not defined in the schema.
  1178. func (m *TaskLogMutation) AddedField(name string) (ent.Value, bool) {
  1179. switch name {
  1180. case tasklog.FieldResult:
  1181. return m.AddedResult()
  1182. }
  1183. return nil, false
  1184. }
  1185. // AddField adds the value to the field with the given name. It returns an error if
  1186. // the field is not defined in the schema, or if the type mismatched the field
  1187. // type.
  1188. func (m *TaskLogMutation) AddField(name string, value ent.Value) error {
  1189. switch name {
  1190. case tasklog.FieldResult:
  1191. v, ok := value.(int8)
  1192. if !ok {
  1193. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1194. }
  1195. m.AddResult(v)
  1196. return nil
  1197. }
  1198. return fmt.Errorf("unknown TaskLog numeric field %s", name)
  1199. }
  1200. // ClearedFields returns all nullable fields that were cleared during this
  1201. // mutation.
  1202. func (m *TaskLogMutation) ClearedFields() []string {
  1203. return nil
  1204. }
  1205. // FieldCleared returns a boolean indicating if a field with the given name was
  1206. // cleared in this mutation.
  1207. func (m *TaskLogMutation) FieldCleared(name string) bool {
  1208. _, ok := m.clearedFields[name]
  1209. return ok
  1210. }
  1211. // ClearField clears the value of the field with the given name. It returns an
  1212. // error if the field is not defined in the schema.
  1213. func (m *TaskLogMutation) ClearField(name string) error {
  1214. return fmt.Errorf("unknown TaskLog nullable field %s", name)
  1215. }
  1216. // ResetField resets all changes in the mutation for the field with the given name.
  1217. // It returns an error if the field is not defined in the schema.
  1218. func (m *TaskLogMutation) ResetField(name string) error {
  1219. switch name {
  1220. case tasklog.FieldStartedAt:
  1221. m.ResetStartedAt()
  1222. return nil
  1223. case tasklog.FieldFinishedAt:
  1224. m.ResetFinishedAt()
  1225. return nil
  1226. case tasklog.FieldResult:
  1227. m.ResetResult()
  1228. return nil
  1229. }
  1230. return fmt.Errorf("unknown TaskLog field %s", name)
  1231. }
  1232. // AddedEdges returns all edge names that were set/added in this mutation.
  1233. func (m *TaskLogMutation) AddedEdges() []string {
  1234. edges := make([]string, 0, 1)
  1235. if m.tasks != nil {
  1236. edges = append(edges, tasklog.EdgeTasks)
  1237. }
  1238. return edges
  1239. }
  1240. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  1241. // name in this mutation.
  1242. func (m *TaskLogMutation) AddedIDs(name string) []ent.Value {
  1243. switch name {
  1244. case tasklog.EdgeTasks:
  1245. if id := m.tasks; id != nil {
  1246. return []ent.Value{*id}
  1247. }
  1248. }
  1249. return nil
  1250. }
  1251. // RemovedEdges returns all edge names that were removed in this mutation.
  1252. func (m *TaskLogMutation) RemovedEdges() []string {
  1253. edges := make([]string, 0, 1)
  1254. return edges
  1255. }
  1256. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  1257. // the given name in this mutation.
  1258. func (m *TaskLogMutation) RemovedIDs(name string) []ent.Value {
  1259. return nil
  1260. }
  1261. // ClearedEdges returns all edge names that were cleared in this mutation.
  1262. func (m *TaskLogMutation) ClearedEdges() []string {
  1263. edges := make([]string, 0, 1)
  1264. if m.clearedtasks {
  1265. edges = append(edges, tasklog.EdgeTasks)
  1266. }
  1267. return edges
  1268. }
  1269. // EdgeCleared returns a boolean which indicates if the edge with the given name
  1270. // was cleared in this mutation.
  1271. func (m *TaskLogMutation) EdgeCleared(name string) bool {
  1272. switch name {
  1273. case tasklog.EdgeTasks:
  1274. return m.clearedtasks
  1275. }
  1276. return false
  1277. }
  1278. // ClearEdge clears the value of the edge with the given name. It returns an error
  1279. // if that edge is not defined in the schema.
  1280. func (m *TaskLogMutation) ClearEdge(name string) error {
  1281. switch name {
  1282. case tasklog.EdgeTasks:
  1283. m.ClearTasks()
  1284. return nil
  1285. }
  1286. return fmt.Errorf("unknown TaskLog unique edge %s", name)
  1287. }
  1288. // ResetEdge resets all changes to the edge with the given name in this mutation.
  1289. // It returns an error if the edge is not defined in the schema.
  1290. func (m *TaskLogMutation) ResetEdge(name string) error {
  1291. switch name {
  1292. case tasklog.EdgeTasks:
  1293. m.ResetTasks()
  1294. return nil
  1295. }
  1296. return fmt.Errorf("unknown TaskLog edge %s", name)
  1297. }