msg.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "wechat-api/ent/msg"
  8. "entgo.io/ent"
  9. "entgo.io/ent/dialect/sql"
  10. )
  11. // Msg is the model entity for the Msg schema.
  12. type Msg struct {
  13. config `json:"-"`
  14. // ID of the ent.
  15. ID uint64 `json:"id,omitempty"`
  16. // Create Time | 创建日期
  17. CreatedAt time.Time `json:"created_at,omitempty"`
  18. // Update Time | 修改日期
  19. UpdatedAt time.Time `json:"updated_at,omitempty"`
  20. // Delete Time | 删除日期
  21. DeletedAt time.Time `json:"deleted_at,omitempty"`
  22. // Status 1: normal 2: ban | 状态 1 正常 2 禁用
  23. Status uint8 `json:"status,omitempty"`
  24. // 发送方微信ID
  25. Fromwxid string `json:"fromwxid,omitempty"`
  26. // 接收人微信ID/群ID
  27. Toid string `json:"toid,omitempty"`
  28. // 消息类型
  29. Msgtype int32 `json:"msgtype,omitempty"`
  30. // 消息
  31. Msg string `json:"msg,omitempty"`
  32. // 批次号
  33. BatchNo string `json:"batch_no,omitempty"`
  34. selectValues sql.SelectValues
  35. }
  36. // scanValues returns the types for scanning values from sql.Rows.
  37. func (*Msg) scanValues(columns []string) ([]any, error) {
  38. values := make([]any, len(columns))
  39. for i := range columns {
  40. switch columns[i] {
  41. case msg.FieldID, msg.FieldStatus, msg.FieldMsgtype:
  42. values[i] = new(sql.NullInt64)
  43. case msg.FieldFromwxid, msg.FieldToid, msg.FieldMsg, msg.FieldBatchNo:
  44. values[i] = new(sql.NullString)
  45. case msg.FieldCreatedAt, msg.FieldUpdatedAt, msg.FieldDeletedAt:
  46. values[i] = new(sql.NullTime)
  47. default:
  48. values[i] = new(sql.UnknownType)
  49. }
  50. }
  51. return values, nil
  52. }
  53. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  54. // to the Msg fields.
  55. func (m *Msg) assignValues(columns []string, values []any) error {
  56. if m, n := len(values), len(columns); m < n {
  57. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  58. }
  59. for i := range columns {
  60. switch columns[i] {
  61. case msg.FieldID:
  62. value, ok := values[i].(*sql.NullInt64)
  63. if !ok {
  64. return fmt.Errorf("unexpected type %T for field id", value)
  65. }
  66. m.ID = uint64(value.Int64)
  67. case msg.FieldCreatedAt:
  68. if value, ok := values[i].(*sql.NullTime); !ok {
  69. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  70. } else if value.Valid {
  71. m.CreatedAt = value.Time
  72. }
  73. case msg.FieldUpdatedAt:
  74. if value, ok := values[i].(*sql.NullTime); !ok {
  75. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  76. } else if value.Valid {
  77. m.UpdatedAt = value.Time
  78. }
  79. case msg.FieldDeletedAt:
  80. if value, ok := values[i].(*sql.NullTime); !ok {
  81. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  82. } else if value.Valid {
  83. m.DeletedAt = value.Time
  84. }
  85. case msg.FieldStatus:
  86. if value, ok := values[i].(*sql.NullInt64); !ok {
  87. return fmt.Errorf("unexpected type %T for field status", values[i])
  88. } else if value.Valid {
  89. m.Status = uint8(value.Int64)
  90. }
  91. case msg.FieldFromwxid:
  92. if value, ok := values[i].(*sql.NullString); !ok {
  93. return fmt.Errorf("unexpected type %T for field fromwxid", values[i])
  94. } else if value.Valid {
  95. m.Fromwxid = value.String
  96. }
  97. case msg.FieldToid:
  98. if value, ok := values[i].(*sql.NullString); !ok {
  99. return fmt.Errorf("unexpected type %T for field toid", values[i])
  100. } else if value.Valid {
  101. m.Toid = value.String
  102. }
  103. case msg.FieldMsgtype:
  104. if value, ok := values[i].(*sql.NullInt64); !ok {
  105. return fmt.Errorf("unexpected type %T for field msgtype", values[i])
  106. } else if value.Valid {
  107. m.Msgtype = int32(value.Int64)
  108. }
  109. case msg.FieldMsg:
  110. if value, ok := values[i].(*sql.NullString); !ok {
  111. return fmt.Errorf("unexpected type %T for field msg", values[i])
  112. } else if value.Valid {
  113. m.Msg = value.String
  114. }
  115. case msg.FieldBatchNo:
  116. if value, ok := values[i].(*sql.NullString); !ok {
  117. return fmt.Errorf("unexpected type %T for field batch_no", values[i])
  118. } else if value.Valid {
  119. m.BatchNo = value.String
  120. }
  121. default:
  122. m.selectValues.Set(columns[i], values[i])
  123. }
  124. }
  125. return nil
  126. }
  127. // Value returns the ent.Value that was dynamically selected and assigned to the Msg.
  128. // This includes values selected through modifiers, order, etc.
  129. func (m *Msg) Value(name string) (ent.Value, error) {
  130. return m.selectValues.Get(name)
  131. }
  132. // Update returns a builder for updating this Msg.
  133. // Note that you need to call Msg.Unwrap() before calling this method if this Msg
  134. // was returned from a transaction, and the transaction was committed or rolled back.
  135. func (m *Msg) Update() *MsgUpdateOne {
  136. return NewMsgClient(m.config).UpdateOne(m)
  137. }
  138. // Unwrap unwraps the Msg entity that was returned from a transaction after it was closed,
  139. // so that all future queries will be executed through the driver which created the transaction.
  140. func (m *Msg) Unwrap() *Msg {
  141. _tx, ok := m.config.driver.(*txDriver)
  142. if !ok {
  143. panic("ent: Msg is not a transactional entity")
  144. }
  145. m.config.driver = _tx.drv
  146. return m
  147. }
  148. // String implements the fmt.Stringer.
  149. func (m *Msg) String() string {
  150. var builder strings.Builder
  151. builder.WriteString("Msg(")
  152. builder.WriteString(fmt.Sprintf("id=%v, ", m.ID))
  153. builder.WriteString("created_at=")
  154. builder.WriteString(m.CreatedAt.Format(time.ANSIC))
  155. builder.WriteString(", ")
  156. builder.WriteString("updated_at=")
  157. builder.WriteString(m.UpdatedAt.Format(time.ANSIC))
  158. builder.WriteString(", ")
  159. builder.WriteString("deleted_at=")
  160. builder.WriteString(m.DeletedAt.Format(time.ANSIC))
  161. builder.WriteString(", ")
  162. builder.WriteString("status=")
  163. builder.WriteString(fmt.Sprintf("%v", m.Status))
  164. builder.WriteString(", ")
  165. builder.WriteString("fromwxid=")
  166. builder.WriteString(m.Fromwxid)
  167. builder.WriteString(", ")
  168. builder.WriteString("toid=")
  169. builder.WriteString(m.Toid)
  170. builder.WriteString(", ")
  171. builder.WriteString("msgtype=")
  172. builder.WriteString(fmt.Sprintf("%v", m.Msgtype))
  173. builder.WriteString(", ")
  174. builder.WriteString("msg=")
  175. builder.WriteString(m.Msg)
  176. builder.WriteString(", ")
  177. builder.WriteString("batch_no=")
  178. builder.WriteString(m.BatchNo)
  179. builder.WriteByte(')')
  180. return builder.String()
  181. }
  182. // Msgs is a parsable slice of Msg.
  183. type Msgs []*Msg