tasklog.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "entgo.io/ent"
  8. "entgo.io/ent/dialect/sql"
  9. "github.com/suyuan32/simple-admin-job/ent/task"
  10. "github.com/suyuan32/simple-admin-job/ent/tasklog"
  11. )
  12. // TaskLog is the model entity for the TaskLog schema.
  13. type TaskLog struct {
  14. config `json:"-"`
  15. // ID of the ent.
  16. ID uint64 `json:"id,omitempty"`
  17. // Task Started Time | 任务启动时间
  18. StartedAt time.Time `json:"started_at,omitempty"`
  19. // Task Finished Time | 任务完成时间
  20. FinishedAt time.Time `json:"finished_at,omitempty"`
  21. // The Task Process Result | 任务执行结果
  22. Result uint8 `json:"result,omitempty"`
  23. // Edges holds the relations/edges for other nodes in the graph.
  24. // The values are being populated by the TaskLogQuery when eager-loading is set.
  25. Edges TaskLogEdges `json:"edges"`
  26. task_task_logs *uint64
  27. selectValues sql.SelectValues
  28. }
  29. // TaskLogEdges holds the relations/edges for other nodes in the graph.
  30. type TaskLogEdges struct {
  31. // Tasks holds the value of the tasks edge.
  32. Tasks *Task `json:"tasks,omitempty"`
  33. // loadedTypes holds the information for reporting if a
  34. // type was loaded (or requested) in eager-loading or not.
  35. loadedTypes [1]bool
  36. }
  37. // TasksOrErr returns the Tasks value or an error if the edge
  38. // was not loaded in eager-loading, or loaded but was not found.
  39. func (e TaskLogEdges) TasksOrErr() (*Task, error) {
  40. if e.Tasks != nil {
  41. return e.Tasks, nil
  42. } else if e.loadedTypes[0] {
  43. return nil, &NotFoundError{label: task.Label}
  44. }
  45. return nil, &NotLoadedError{edge: "tasks"}
  46. }
  47. // scanValues returns the types for scanning values from sql.Rows.
  48. func (*TaskLog) scanValues(columns []string) ([]any, error) {
  49. values := make([]any, len(columns))
  50. for i := range columns {
  51. switch columns[i] {
  52. case tasklog.FieldID, tasklog.FieldResult:
  53. values[i] = new(sql.NullInt64)
  54. case tasklog.FieldStartedAt, tasklog.FieldFinishedAt:
  55. values[i] = new(sql.NullTime)
  56. case tasklog.ForeignKeys[0]: // task_task_logs
  57. values[i] = new(sql.NullInt64)
  58. default:
  59. values[i] = new(sql.UnknownType)
  60. }
  61. }
  62. return values, nil
  63. }
  64. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  65. // to the TaskLog fields.
  66. func (tl *TaskLog) assignValues(columns []string, values []any) error {
  67. if m, n := len(values), len(columns); m < n {
  68. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  69. }
  70. for i := range columns {
  71. switch columns[i] {
  72. case tasklog.FieldID:
  73. value, ok := values[i].(*sql.NullInt64)
  74. if !ok {
  75. return fmt.Errorf("unexpected type %T for field id", value)
  76. }
  77. tl.ID = uint64(value.Int64)
  78. case tasklog.FieldStartedAt:
  79. if value, ok := values[i].(*sql.NullTime); !ok {
  80. return fmt.Errorf("unexpected type %T for field started_at", values[i])
  81. } else if value.Valid {
  82. tl.StartedAt = value.Time
  83. }
  84. case tasklog.FieldFinishedAt:
  85. if value, ok := values[i].(*sql.NullTime); !ok {
  86. return fmt.Errorf("unexpected type %T for field finished_at", values[i])
  87. } else if value.Valid {
  88. tl.FinishedAt = value.Time
  89. }
  90. case tasklog.FieldResult:
  91. if value, ok := values[i].(*sql.NullInt64); !ok {
  92. return fmt.Errorf("unexpected type %T for field result", values[i])
  93. } else if value.Valid {
  94. tl.Result = uint8(value.Int64)
  95. }
  96. case tasklog.ForeignKeys[0]:
  97. if value, ok := values[i].(*sql.NullInt64); !ok {
  98. return fmt.Errorf("unexpected type %T for edge-field task_task_logs", value)
  99. } else if value.Valid {
  100. tl.task_task_logs = new(uint64)
  101. *tl.task_task_logs = uint64(value.Int64)
  102. }
  103. default:
  104. tl.selectValues.Set(columns[i], values[i])
  105. }
  106. }
  107. return nil
  108. }
  109. // Value returns the ent.Value that was dynamically selected and assigned to the TaskLog.
  110. // This includes values selected through modifiers, order, etc.
  111. func (tl *TaskLog) Value(name string) (ent.Value, error) {
  112. return tl.selectValues.Get(name)
  113. }
  114. // QueryTasks queries the "tasks" edge of the TaskLog entity.
  115. func (tl *TaskLog) QueryTasks() *TaskQuery {
  116. return NewTaskLogClient(tl.config).QueryTasks(tl)
  117. }
  118. // Update returns a builder for updating this TaskLog.
  119. // Note that you need to call TaskLog.Unwrap() before calling this method if this TaskLog
  120. // was returned from a transaction, and the transaction was committed or rolled back.
  121. func (tl *TaskLog) Update() *TaskLogUpdateOne {
  122. return NewTaskLogClient(tl.config).UpdateOne(tl)
  123. }
  124. // Unwrap unwraps the TaskLog entity that was returned from a transaction after it was closed,
  125. // so that all future queries will be executed through the driver which created the transaction.
  126. func (tl *TaskLog) Unwrap() *TaskLog {
  127. _tx, ok := tl.config.driver.(*txDriver)
  128. if !ok {
  129. panic("ent: TaskLog is not a transactional entity")
  130. }
  131. tl.config.driver = _tx.drv
  132. return tl
  133. }
  134. // String implements the fmt.Stringer.
  135. func (tl *TaskLog) String() string {
  136. var builder strings.Builder
  137. builder.WriteString("TaskLog(")
  138. builder.WriteString(fmt.Sprintf("id=%v, ", tl.ID))
  139. builder.WriteString("started_at=")
  140. builder.WriteString(tl.StartedAt.Format(time.ANSIC))
  141. builder.WriteString(", ")
  142. builder.WriteString("finished_at=")
  143. builder.WriteString(tl.FinishedAt.Format(time.ANSIC))
  144. builder.WriteString(", ")
  145. builder.WriteString("result=")
  146. builder.WriteString(fmt.Sprintf("%v", tl.Result))
  147. builder.WriteByte(')')
  148. return builder.String()
  149. }
  150. // TaskLogs is a parsable slice of TaskLog.
  151. type TaskLogs []*TaskLog