msg.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. // 国家区号
  35. Cc string `json:"cc,omitempty"`
  36. // 手机号
  37. Phone string `json:"phone,omitempty"`
  38. selectValues sql.SelectValues
  39. }
  40. // scanValues returns the types for scanning values from sql.Rows.
  41. func (*Msg) scanValues(columns []string) ([]any, error) {
  42. values := make([]any, len(columns))
  43. for i := range columns {
  44. switch columns[i] {
  45. case msg.FieldID, msg.FieldStatus, msg.FieldMsgtype:
  46. values[i] = new(sql.NullInt64)
  47. case msg.FieldFromwxid, msg.FieldToid, msg.FieldMsg, msg.FieldBatchNo, msg.FieldCc, msg.FieldPhone:
  48. values[i] = new(sql.NullString)
  49. case msg.FieldCreatedAt, msg.FieldUpdatedAt, msg.FieldDeletedAt:
  50. values[i] = new(sql.NullTime)
  51. default:
  52. values[i] = new(sql.UnknownType)
  53. }
  54. }
  55. return values, nil
  56. }
  57. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  58. // to the Msg fields.
  59. func (m *Msg) assignValues(columns []string, values []any) error {
  60. if m, n := len(values), len(columns); m < n {
  61. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  62. }
  63. for i := range columns {
  64. switch columns[i] {
  65. case msg.FieldID:
  66. value, ok := values[i].(*sql.NullInt64)
  67. if !ok {
  68. return fmt.Errorf("unexpected type %T for field id", value)
  69. }
  70. m.ID = uint64(value.Int64)
  71. case msg.FieldCreatedAt:
  72. if value, ok := values[i].(*sql.NullTime); !ok {
  73. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  74. } else if value.Valid {
  75. m.CreatedAt = value.Time
  76. }
  77. case msg.FieldUpdatedAt:
  78. if value, ok := values[i].(*sql.NullTime); !ok {
  79. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  80. } else if value.Valid {
  81. m.UpdatedAt = value.Time
  82. }
  83. case msg.FieldDeletedAt:
  84. if value, ok := values[i].(*sql.NullTime); !ok {
  85. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  86. } else if value.Valid {
  87. m.DeletedAt = value.Time
  88. }
  89. case msg.FieldStatus:
  90. if value, ok := values[i].(*sql.NullInt64); !ok {
  91. return fmt.Errorf("unexpected type %T for field status", values[i])
  92. } else if value.Valid {
  93. m.Status = uint8(value.Int64)
  94. }
  95. case msg.FieldFromwxid:
  96. if value, ok := values[i].(*sql.NullString); !ok {
  97. return fmt.Errorf("unexpected type %T for field fromwxid", values[i])
  98. } else if value.Valid {
  99. m.Fromwxid = value.String
  100. }
  101. case msg.FieldToid:
  102. if value, ok := values[i].(*sql.NullString); !ok {
  103. return fmt.Errorf("unexpected type %T for field toid", values[i])
  104. } else if value.Valid {
  105. m.Toid = value.String
  106. }
  107. case msg.FieldMsgtype:
  108. if value, ok := values[i].(*sql.NullInt64); !ok {
  109. return fmt.Errorf("unexpected type %T for field msgtype", values[i])
  110. } else if value.Valid {
  111. m.Msgtype = int32(value.Int64)
  112. }
  113. case msg.FieldMsg:
  114. if value, ok := values[i].(*sql.NullString); !ok {
  115. return fmt.Errorf("unexpected type %T for field msg", values[i])
  116. } else if value.Valid {
  117. m.Msg = value.String
  118. }
  119. case msg.FieldBatchNo:
  120. if value, ok := values[i].(*sql.NullString); !ok {
  121. return fmt.Errorf("unexpected type %T for field batch_no", values[i])
  122. } else if value.Valid {
  123. m.BatchNo = value.String
  124. }
  125. case msg.FieldCc:
  126. if value, ok := values[i].(*sql.NullString); !ok {
  127. return fmt.Errorf("unexpected type %T for field cc", values[i])
  128. } else if value.Valid {
  129. m.Cc = value.String
  130. }
  131. case msg.FieldPhone:
  132. if value, ok := values[i].(*sql.NullString); !ok {
  133. return fmt.Errorf("unexpected type %T for field phone", values[i])
  134. } else if value.Valid {
  135. m.Phone = value.String
  136. }
  137. default:
  138. m.selectValues.Set(columns[i], values[i])
  139. }
  140. }
  141. return nil
  142. }
  143. // Value returns the ent.Value that was dynamically selected and assigned to the Msg.
  144. // This includes values selected through modifiers, order, etc.
  145. func (m *Msg) Value(name string) (ent.Value, error) {
  146. return m.selectValues.Get(name)
  147. }
  148. // Update returns a builder for updating this Msg.
  149. // Note that you need to call Msg.Unwrap() before calling this method if this Msg
  150. // was returned from a transaction, and the transaction was committed or rolled back.
  151. func (m *Msg) Update() *MsgUpdateOne {
  152. return NewMsgClient(m.config).UpdateOne(m)
  153. }
  154. // Unwrap unwraps the Msg entity that was returned from a transaction after it was closed,
  155. // so that all future queries will be executed through the driver which created the transaction.
  156. func (m *Msg) Unwrap() *Msg {
  157. _tx, ok := m.config.driver.(*txDriver)
  158. if !ok {
  159. panic("ent: Msg is not a transactional entity")
  160. }
  161. m.config.driver = _tx.drv
  162. return m
  163. }
  164. // String implements the fmt.Stringer.
  165. func (m *Msg) String() string {
  166. var builder strings.Builder
  167. builder.WriteString("Msg(")
  168. builder.WriteString(fmt.Sprintf("id=%v, ", m.ID))
  169. builder.WriteString("created_at=")
  170. builder.WriteString(m.CreatedAt.Format(time.ANSIC))
  171. builder.WriteString(", ")
  172. builder.WriteString("updated_at=")
  173. builder.WriteString(m.UpdatedAt.Format(time.ANSIC))
  174. builder.WriteString(", ")
  175. builder.WriteString("deleted_at=")
  176. builder.WriteString(m.DeletedAt.Format(time.ANSIC))
  177. builder.WriteString(", ")
  178. builder.WriteString("status=")
  179. builder.WriteString(fmt.Sprintf("%v", m.Status))
  180. builder.WriteString(", ")
  181. builder.WriteString("fromwxid=")
  182. builder.WriteString(m.Fromwxid)
  183. builder.WriteString(", ")
  184. builder.WriteString("toid=")
  185. builder.WriteString(m.Toid)
  186. builder.WriteString(", ")
  187. builder.WriteString("msgtype=")
  188. builder.WriteString(fmt.Sprintf("%v", m.Msgtype))
  189. builder.WriteString(", ")
  190. builder.WriteString("msg=")
  191. builder.WriteString(m.Msg)
  192. builder.WriteString(", ")
  193. builder.WriteString("batch_no=")
  194. builder.WriteString(m.BatchNo)
  195. builder.WriteString(", ")
  196. builder.WriteString("cc=")
  197. builder.WriteString(m.Cc)
  198. builder.WriteString(", ")
  199. builder.WriteString("phone=")
  200. builder.WriteString(m.Phone)
  201. builder.WriteByte(')')
  202. return builder.String()
  203. }
  204. // Msgs is a parsable slice of Msg.
  205. type Msgs []*Msg