tasklog_update.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "entgo.io/ent/dialect/sql"
  9. "entgo.io/ent/dialect/sql/sqlgraph"
  10. "entgo.io/ent/schema/field"
  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. // TaskLogUpdate is the builder for updating TaskLog entities.
  16. type TaskLogUpdate struct {
  17. config
  18. hooks []Hook
  19. mutation *TaskLogMutation
  20. }
  21. // Where appends a list predicates to the TaskLogUpdate builder.
  22. func (tlu *TaskLogUpdate) Where(ps ...predicate.TaskLog) *TaskLogUpdate {
  23. tlu.mutation.Where(ps...)
  24. return tlu
  25. }
  26. // SetFinishedAt sets the "finished_at" field.
  27. func (tlu *TaskLogUpdate) SetFinishedAt(t time.Time) *TaskLogUpdate {
  28. tlu.mutation.SetFinishedAt(t)
  29. return tlu
  30. }
  31. // SetNillableFinishedAt sets the "finished_at" field if the given value is not nil.
  32. func (tlu *TaskLogUpdate) SetNillableFinishedAt(t *time.Time) *TaskLogUpdate {
  33. if t != nil {
  34. tlu.SetFinishedAt(*t)
  35. }
  36. return tlu
  37. }
  38. // SetResult sets the "result" field.
  39. func (tlu *TaskLogUpdate) SetResult(u uint8) *TaskLogUpdate {
  40. tlu.mutation.ResetResult()
  41. tlu.mutation.SetResult(u)
  42. return tlu
  43. }
  44. // SetNillableResult sets the "result" field if the given value is not nil.
  45. func (tlu *TaskLogUpdate) SetNillableResult(u *uint8) *TaskLogUpdate {
  46. if u != nil {
  47. tlu.SetResult(*u)
  48. }
  49. return tlu
  50. }
  51. // AddResult adds u to the "result" field.
  52. func (tlu *TaskLogUpdate) AddResult(u int8) *TaskLogUpdate {
  53. tlu.mutation.AddResult(u)
  54. return tlu
  55. }
  56. // SetTasksID sets the "tasks" edge to the Task entity by ID.
  57. func (tlu *TaskLogUpdate) SetTasksID(id uint64) *TaskLogUpdate {
  58. tlu.mutation.SetTasksID(id)
  59. return tlu
  60. }
  61. // SetNillableTasksID sets the "tasks" edge to the Task entity by ID if the given value is not nil.
  62. func (tlu *TaskLogUpdate) SetNillableTasksID(id *uint64) *TaskLogUpdate {
  63. if id != nil {
  64. tlu = tlu.SetTasksID(*id)
  65. }
  66. return tlu
  67. }
  68. // SetTasks sets the "tasks" edge to the Task entity.
  69. func (tlu *TaskLogUpdate) SetTasks(t *Task) *TaskLogUpdate {
  70. return tlu.SetTasksID(t.ID)
  71. }
  72. // Mutation returns the TaskLogMutation object of the builder.
  73. func (tlu *TaskLogUpdate) Mutation() *TaskLogMutation {
  74. return tlu.mutation
  75. }
  76. // ClearTasks clears the "tasks" edge to the Task entity.
  77. func (tlu *TaskLogUpdate) ClearTasks() *TaskLogUpdate {
  78. tlu.mutation.ClearTasks()
  79. return tlu
  80. }
  81. // Save executes the query and returns the number of nodes affected by the update operation.
  82. func (tlu *TaskLogUpdate) Save(ctx context.Context) (int, error) {
  83. return withHooks(ctx, tlu.sqlSave, tlu.mutation, tlu.hooks)
  84. }
  85. // SaveX is like Save, but panics if an error occurs.
  86. func (tlu *TaskLogUpdate) SaveX(ctx context.Context) int {
  87. affected, err := tlu.Save(ctx)
  88. if err != nil {
  89. panic(err)
  90. }
  91. return affected
  92. }
  93. // Exec executes the query.
  94. func (tlu *TaskLogUpdate) Exec(ctx context.Context) error {
  95. _, err := tlu.Save(ctx)
  96. return err
  97. }
  98. // ExecX is like Exec, but panics if an error occurs.
  99. func (tlu *TaskLogUpdate) ExecX(ctx context.Context) {
  100. if err := tlu.Exec(ctx); err != nil {
  101. panic(err)
  102. }
  103. }
  104. func (tlu *TaskLogUpdate) sqlSave(ctx context.Context) (n int, err error) {
  105. _spec := sqlgraph.NewUpdateSpec(tasklog.Table, tasklog.Columns, sqlgraph.NewFieldSpec(tasklog.FieldID, field.TypeUint64))
  106. if ps := tlu.mutation.predicates; len(ps) > 0 {
  107. _spec.Predicate = func(selector *sql.Selector) {
  108. for i := range ps {
  109. ps[i](selector)
  110. }
  111. }
  112. }
  113. if value, ok := tlu.mutation.FinishedAt(); ok {
  114. _spec.SetField(tasklog.FieldFinishedAt, field.TypeTime, value)
  115. }
  116. if value, ok := tlu.mutation.Result(); ok {
  117. _spec.SetField(tasklog.FieldResult, field.TypeUint8, value)
  118. }
  119. if value, ok := tlu.mutation.AddedResult(); ok {
  120. _spec.AddField(tasklog.FieldResult, field.TypeUint8, value)
  121. }
  122. if tlu.mutation.TasksCleared() {
  123. edge := &sqlgraph.EdgeSpec{
  124. Rel: sqlgraph.M2O,
  125. Inverse: true,
  126. Table: tasklog.TasksTable,
  127. Columns: []string{tasklog.TasksColumn},
  128. Bidi: false,
  129. Target: &sqlgraph.EdgeTarget{
  130. IDSpec: sqlgraph.NewFieldSpec(task.FieldID, field.TypeUint64),
  131. },
  132. }
  133. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  134. }
  135. if nodes := tlu.mutation.TasksIDs(); len(nodes) > 0 {
  136. edge := &sqlgraph.EdgeSpec{
  137. Rel: sqlgraph.M2O,
  138. Inverse: true,
  139. Table: tasklog.TasksTable,
  140. Columns: []string{tasklog.TasksColumn},
  141. Bidi: false,
  142. Target: &sqlgraph.EdgeTarget{
  143. IDSpec: sqlgraph.NewFieldSpec(task.FieldID, field.TypeUint64),
  144. },
  145. }
  146. for _, k := range nodes {
  147. edge.Target.Nodes = append(edge.Target.Nodes, k)
  148. }
  149. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  150. }
  151. if n, err = sqlgraph.UpdateNodes(ctx, tlu.driver, _spec); err != nil {
  152. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  153. err = &NotFoundError{tasklog.Label}
  154. } else if sqlgraph.IsConstraintError(err) {
  155. err = &ConstraintError{msg: err.Error(), wrap: err}
  156. }
  157. return 0, err
  158. }
  159. tlu.mutation.done = true
  160. return n, nil
  161. }
  162. // TaskLogUpdateOne is the builder for updating a single TaskLog entity.
  163. type TaskLogUpdateOne struct {
  164. config
  165. fields []string
  166. hooks []Hook
  167. mutation *TaskLogMutation
  168. }
  169. // SetFinishedAt sets the "finished_at" field.
  170. func (tluo *TaskLogUpdateOne) SetFinishedAt(t time.Time) *TaskLogUpdateOne {
  171. tluo.mutation.SetFinishedAt(t)
  172. return tluo
  173. }
  174. // SetNillableFinishedAt sets the "finished_at" field if the given value is not nil.
  175. func (tluo *TaskLogUpdateOne) SetNillableFinishedAt(t *time.Time) *TaskLogUpdateOne {
  176. if t != nil {
  177. tluo.SetFinishedAt(*t)
  178. }
  179. return tluo
  180. }
  181. // SetResult sets the "result" field.
  182. func (tluo *TaskLogUpdateOne) SetResult(u uint8) *TaskLogUpdateOne {
  183. tluo.mutation.ResetResult()
  184. tluo.mutation.SetResult(u)
  185. return tluo
  186. }
  187. // SetNillableResult sets the "result" field if the given value is not nil.
  188. func (tluo *TaskLogUpdateOne) SetNillableResult(u *uint8) *TaskLogUpdateOne {
  189. if u != nil {
  190. tluo.SetResult(*u)
  191. }
  192. return tluo
  193. }
  194. // AddResult adds u to the "result" field.
  195. func (tluo *TaskLogUpdateOne) AddResult(u int8) *TaskLogUpdateOne {
  196. tluo.mutation.AddResult(u)
  197. return tluo
  198. }
  199. // SetTasksID sets the "tasks" edge to the Task entity by ID.
  200. func (tluo *TaskLogUpdateOne) SetTasksID(id uint64) *TaskLogUpdateOne {
  201. tluo.mutation.SetTasksID(id)
  202. return tluo
  203. }
  204. // SetNillableTasksID sets the "tasks" edge to the Task entity by ID if the given value is not nil.
  205. func (tluo *TaskLogUpdateOne) SetNillableTasksID(id *uint64) *TaskLogUpdateOne {
  206. if id != nil {
  207. tluo = tluo.SetTasksID(*id)
  208. }
  209. return tluo
  210. }
  211. // SetTasks sets the "tasks" edge to the Task entity.
  212. func (tluo *TaskLogUpdateOne) SetTasks(t *Task) *TaskLogUpdateOne {
  213. return tluo.SetTasksID(t.ID)
  214. }
  215. // Mutation returns the TaskLogMutation object of the builder.
  216. func (tluo *TaskLogUpdateOne) Mutation() *TaskLogMutation {
  217. return tluo.mutation
  218. }
  219. // ClearTasks clears the "tasks" edge to the Task entity.
  220. func (tluo *TaskLogUpdateOne) ClearTasks() *TaskLogUpdateOne {
  221. tluo.mutation.ClearTasks()
  222. return tluo
  223. }
  224. // Where appends a list predicates to the TaskLogUpdate builder.
  225. func (tluo *TaskLogUpdateOne) Where(ps ...predicate.TaskLog) *TaskLogUpdateOne {
  226. tluo.mutation.Where(ps...)
  227. return tluo
  228. }
  229. // Select allows selecting one or more fields (columns) of the returned entity.
  230. // The default is selecting all fields defined in the entity schema.
  231. func (tluo *TaskLogUpdateOne) Select(field string, fields ...string) *TaskLogUpdateOne {
  232. tluo.fields = append([]string{field}, fields...)
  233. return tluo
  234. }
  235. // Save executes the query and returns the updated TaskLog entity.
  236. func (tluo *TaskLogUpdateOne) Save(ctx context.Context) (*TaskLog, error) {
  237. return withHooks(ctx, tluo.sqlSave, tluo.mutation, tluo.hooks)
  238. }
  239. // SaveX is like Save, but panics if an error occurs.
  240. func (tluo *TaskLogUpdateOne) SaveX(ctx context.Context) *TaskLog {
  241. node, err := tluo.Save(ctx)
  242. if err != nil {
  243. panic(err)
  244. }
  245. return node
  246. }
  247. // Exec executes the query on the entity.
  248. func (tluo *TaskLogUpdateOne) Exec(ctx context.Context) error {
  249. _, err := tluo.Save(ctx)
  250. return err
  251. }
  252. // ExecX is like Exec, but panics if an error occurs.
  253. func (tluo *TaskLogUpdateOne) ExecX(ctx context.Context) {
  254. if err := tluo.Exec(ctx); err != nil {
  255. panic(err)
  256. }
  257. }
  258. func (tluo *TaskLogUpdateOne) sqlSave(ctx context.Context) (_node *TaskLog, err error) {
  259. _spec := sqlgraph.NewUpdateSpec(tasklog.Table, tasklog.Columns, sqlgraph.NewFieldSpec(tasklog.FieldID, field.TypeUint64))
  260. id, ok := tluo.mutation.ID()
  261. if !ok {
  262. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "TaskLog.id" for update`)}
  263. }
  264. _spec.Node.ID.Value = id
  265. if fields := tluo.fields; len(fields) > 0 {
  266. _spec.Node.Columns = make([]string, 0, len(fields))
  267. _spec.Node.Columns = append(_spec.Node.Columns, tasklog.FieldID)
  268. for _, f := range fields {
  269. if !tasklog.ValidColumn(f) {
  270. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  271. }
  272. if f != tasklog.FieldID {
  273. _spec.Node.Columns = append(_spec.Node.Columns, f)
  274. }
  275. }
  276. }
  277. if ps := tluo.mutation.predicates; len(ps) > 0 {
  278. _spec.Predicate = func(selector *sql.Selector) {
  279. for i := range ps {
  280. ps[i](selector)
  281. }
  282. }
  283. }
  284. if value, ok := tluo.mutation.FinishedAt(); ok {
  285. _spec.SetField(tasklog.FieldFinishedAt, field.TypeTime, value)
  286. }
  287. if value, ok := tluo.mutation.Result(); ok {
  288. _spec.SetField(tasklog.FieldResult, field.TypeUint8, value)
  289. }
  290. if value, ok := tluo.mutation.AddedResult(); ok {
  291. _spec.AddField(tasklog.FieldResult, field.TypeUint8, value)
  292. }
  293. if tluo.mutation.TasksCleared() {
  294. edge := &sqlgraph.EdgeSpec{
  295. Rel: sqlgraph.M2O,
  296. Inverse: true,
  297. Table: tasklog.TasksTable,
  298. Columns: []string{tasklog.TasksColumn},
  299. Bidi: false,
  300. Target: &sqlgraph.EdgeTarget{
  301. IDSpec: sqlgraph.NewFieldSpec(task.FieldID, field.TypeUint64),
  302. },
  303. }
  304. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  305. }
  306. if nodes := tluo.mutation.TasksIDs(); len(nodes) > 0 {
  307. edge := &sqlgraph.EdgeSpec{
  308. Rel: sqlgraph.M2O,
  309. Inverse: true,
  310. Table: tasklog.TasksTable,
  311. Columns: []string{tasklog.TasksColumn},
  312. Bidi: false,
  313. Target: &sqlgraph.EdgeTarget{
  314. IDSpec: sqlgraph.NewFieldSpec(task.FieldID, field.TypeUint64),
  315. },
  316. }
  317. for _, k := range nodes {
  318. edge.Target.Nodes = append(edge.Target.Nodes, k)
  319. }
  320. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  321. }
  322. _node = &TaskLog{config: tluo.config}
  323. _spec.Assign = _node.assignValues
  324. _spec.ScanValues = _node.scanValues
  325. if err = sqlgraph.UpdateNode(ctx, tluo.driver, _spec); err != nil {
  326. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  327. err = &NotFoundError{tasklog.Label}
  328. } else if sqlgraph.IsConstraintError(err) {
  329. err = &ConstraintError{msg: err.Error(), wrap: err}
  330. }
  331. return nil, err
  332. }
  333. tluo.mutation.done = true
  334. return _node, nil
  335. }