announcementread.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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/Wei-Shaw/sub2api/ent/announcement"
  10. "github.com/Wei-Shaw/sub2api/ent/announcementread"
  11. "github.com/Wei-Shaw/sub2api/ent/user"
  12. )
  13. // AnnouncementRead is the model entity for the AnnouncementRead schema.
  14. type AnnouncementRead struct {
  15. config `json:"-"`
  16. // ID of the ent.
  17. ID int64 `json:"id,omitempty"`
  18. // AnnouncementID holds the value of the "announcement_id" field.
  19. AnnouncementID int64 `json:"announcement_id,omitempty"`
  20. // UserID holds the value of the "user_id" field.
  21. UserID int64 `json:"user_id,omitempty"`
  22. // 用户首次已读时间
  23. ReadAt time.Time `json:"read_at,omitempty"`
  24. // CreatedAt holds the value of the "created_at" field.
  25. CreatedAt time.Time `json:"created_at,omitempty"`
  26. // Edges holds the relations/edges for other nodes in the graph.
  27. // The values are being populated by the AnnouncementReadQuery when eager-loading is set.
  28. Edges AnnouncementReadEdges `json:"edges"`
  29. selectValues sql.SelectValues
  30. }
  31. // AnnouncementReadEdges holds the relations/edges for other nodes in the graph.
  32. type AnnouncementReadEdges struct {
  33. // Announcement holds the value of the announcement edge.
  34. Announcement *Announcement `json:"announcement,omitempty"`
  35. // User holds the value of the user edge.
  36. User *User `json:"user,omitempty"`
  37. // loadedTypes holds the information for reporting if a
  38. // type was loaded (or requested) in eager-loading or not.
  39. loadedTypes [2]bool
  40. }
  41. // AnnouncementOrErr returns the Announcement value or an error if the edge
  42. // was not loaded in eager-loading, or loaded but was not found.
  43. func (e AnnouncementReadEdges) AnnouncementOrErr() (*Announcement, error) {
  44. if e.Announcement != nil {
  45. return e.Announcement, nil
  46. } else if e.loadedTypes[0] {
  47. return nil, &NotFoundError{label: announcement.Label}
  48. }
  49. return nil, &NotLoadedError{edge: "announcement"}
  50. }
  51. // UserOrErr returns the User value or an error if the edge
  52. // was not loaded in eager-loading, or loaded but was not found.
  53. func (e AnnouncementReadEdges) UserOrErr() (*User, error) {
  54. if e.User != nil {
  55. return e.User, nil
  56. } else if e.loadedTypes[1] {
  57. return nil, &NotFoundError{label: user.Label}
  58. }
  59. return nil, &NotLoadedError{edge: "user"}
  60. }
  61. // scanValues returns the types for scanning values from sql.Rows.
  62. func (*AnnouncementRead) scanValues(columns []string) ([]any, error) {
  63. values := make([]any, len(columns))
  64. for i := range columns {
  65. switch columns[i] {
  66. case announcementread.FieldID, announcementread.FieldAnnouncementID, announcementread.FieldUserID:
  67. values[i] = new(sql.NullInt64)
  68. case announcementread.FieldReadAt, announcementread.FieldCreatedAt:
  69. values[i] = new(sql.NullTime)
  70. default:
  71. values[i] = new(sql.UnknownType)
  72. }
  73. }
  74. return values, nil
  75. }
  76. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  77. // to the AnnouncementRead fields.
  78. func (_m *AnnouncementRead) assignValues(columns []string, values []any) error {
  79. if m, n := len(values), len(columns); m < n {
  80. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  81. }
  82. for i := range columns {
  83. switch columns[i] {
  84. case announcementread.FieldID:
  85. value, ok := values[i].(*sql.NullInt64)
  86. if !ok {
  87. return fmt.Errorf("unexpected type %T for field id", value)
  88. }
  89. _m.ID = int64(value.Int64)
  90. case announcementread.FieldAnnouncementID:
  91. if value, ok := values[i].(*sql.NullInt64); !ok {
  92. return fmt.Errorf("unexpected type %T for field announcement_id", values[i])
  93. } else if value.Valid {
  94. _m.AnnouncementID = value.Int64
  95. }
  96. case announcementread.FieldUserID:
  97. if value, ok := values[i].(*sql.NullInt64); !ok {
  98. return fmt.Errorf("unexpected type %T for field user_id", values[i])
  99. } else if value.Valid {
  100. _m.UserID = value.Int64
  101. }
  102. case announcementread.FieldReadAt:
  103. if value, ok := values[i].(*sql.NullTime); !ok {
  104. return fmt.Errorf("unexpected type %T for field read_at", values[i])
  105. } else if value.Valid {
  106. _m.ReadAt = value.Time
  107. }
  108. case announcementread.FieldCreatedAt:
  109. if value, ok := values[i].(*sql.NullTime); !ok {
  110. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  111. } else if value.Valid {
  112. _m.CreatedAt = value.Time
  113. }
  114. default:
  115. _m.selectValues.Set(columns[i], values[i])
  116. }
  117. }
  118. return nil
  119. }
  120. // Value returns the ent.Value that was dynamically selected and assigned to the AnnouncementRead.
  121. // This includes values selected through modifiers, order, etc.
  122. func (_m *AnnouncementRead) Value(name string) (ent.Value, error) {
  123. return _m.selectValues.Get(name)
  124. }
  125. // QueryAnnouncement queries the "announcement" edge of the AnnouncementRead entity.
  126. func (_m *AnnouncementRead) QueryAnnouncement() *AnnouncementQuery {
  127. return NewAnnouncementReadClient(_m.config).QueryAnnouncement(_m)
  128. }
  129. // QueryUser queries the "user" edge of the AnnouncementRead entity.
  130. func (_m *AnnouncementRead) QueryUser() *UserQuery {
  131. return NewAnnouncementReadClient(_m.config).QueryUser(_m)
  132. }
  133. // Update returns a builder for updating this AnnouncementRead.
  134. // Note that you need to call AnnouncementRead.Unwrap() before calling this method if this AnnouncementRead
  135. // was returned from a transaction, and the transaction was committed or rolled back.
  136. func (_m *AnnouncementRead) Update() *AnnouncementReadUpdateOne {
  137. return NewAnnouncementReadClient(_m.config).UpdateOne(_m)
  138. }
  139. // Unwrap unwraps the AnnouncementRead entity that was returned from a transaction after it was closed,
  140. // so that all future queries will be executed through the driver which created the transaction.
  141. func (_m *AnnouncementRead) Unwrap() *AnnouncementRead {
  142. _tx, ok := _m.config.driver.(*txDriver)
  143. if !ok {
  144. panic("ent: AnnouncementRead is not a transactional entity")
  145. }
  146. _m.config.driver = _tx.drv
  147. return _m
  148. }
  149. // String implements the fmt.Stringer.
  150. func (_m *AnnouncementRead) String() string {
  151. var builder strings.Builder
  152. builder.WriteString("AnnouncementRead(")
  153. builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
  154. builder.WriteString("announcement_id=")
  155. builder.WriteString(fmt.Sprintf("%v", _m.AnnouncementID))
  156. builder.WriteString(", ")
  157. builder.WriteString("user_id=")
  158. builder.WriteString(fmt.Sprintf("%v", _m.UserID))
  159. builder.WriteString(", ")
  160. builder.WriteString("read_at=")
  161. builder.WriteString(_m.ReadAt.Format(time.ANSIC))
  162. builder.WriteString(", ")
  163. builder.WriteString("created_at=")
  164. builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
  165. builder.WriteByte(')')
  166. return builder.String()
  167. }
  168. // AnnouncementReads is a parsable slice of AnnouncementRead.
  169. type AnnouncementReads []*AnnouncementRead