message.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "wechat-api/ent/message"
  7. "entgo.io/ent"
  8. "entgo.io/ent/dialect/sql"
  9. )
  10. // Message is the model entity for the Message schema.
  11. type Message struct {
  12. config `json:"-"`
  13. // ID of the ent.
  14. ID int `json:"id,omitempty"`
  15. // 属主微信id
  16. WxWxid string `json:"wx_wxid,omitempty"`
  17. // 微信id 公众号微信ID
  18. Wxid string `json:"wxid,omitempty"`
  19. // 微信消息内容
  20. Content string `json:"content,omitempty"`
  21. selectValues sql.SelectValues
  22. }
  23. // scanValues returns the types for scanning values from sql.Rows.
  24. func (*Message) scanValues(columns []string) ([]any, error) {
  25. values := make([]any, len(columns))
  26. for i := range columns {
  27. switch columns[i] {
  28. case message.FieldID:
  29. values[i] = new(sql.NullInt64)
  30. case message.FieldWxWxid, message.FieldWxid, message.FieldContent:
  31. values[i] = new(sql.NullString)
  32. default:
  33. values[i] = new(sql.UnknownType)
  34. }
  35. }
  36. return values, nil
  37. }
  38. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  39. // to the Message fields.
  40. func (m *Message) assignValues(columns []string, values []any) error {
  41. if m, n := len(values), len(columns); m < n {
  42. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  43. }
  44. for i := range columns {
  45. switch columns[i] {
  46. case message.FieldID:
  47. value, ok := values[i].(*sql.NullInt64)
  48. if !ok {
  49. return fmt.Errorf("unexpected type %T for field id", value)
  50. }
  51. m.ID = int(value.Int64)
  52. case message.FieldWxWxid:
  53. if value, ok := values[i].(*sql.NullString); !ok {
  54. return fmt.Errorf("unexpected type %T for field wx_wxid", values[i])
  55. } else if value.Valid {
  56. m.WxWxid = value.String
  57. }
  58. case message.FieldWxid:
  59. if value, ok := values[i].(*sql.NullString); !ok {
  60. return fmt.Errorf("unexpected type %T for field wxid", values[i])
  61. } else if value.Valid {
  62. m.Wxid = value.String
  63. }
  64. case message.FieldContent:
  65. if value, ok := values[i].(*sql.NullString); !ok {
  66. return fmt.Errorf("unexpected type %T for field content", values[i])
  67. } else if value.Valid {
  68. m.Content = value.String
  69. }
  70. default:
  71. m.selectValues.Set(columns[i], values[i])
  72. }
  73. }
  74. return nil
  75. }
  76. // Value returns the ent.Value that was dynamically selected and assigned to the Message.
  77. // This includes values selected through modifiers, order, etc.
  78. func (m *Message) Value(name string) (ent.Value, error) {
  79. return m.selectValues.Get(name)
  80. }
  81. // Update returns a builder for updating this Message.
  82. // Note that you need to call Message.Unwrap() before calling this method if this Message
  83. // was returned from a transaction, and the transaction was committed or rolled back.
  84. func (m *Message) Update() *MessageUpdateOne {
  85. return NewMessageClient(m.config).UpdateOne(m)
  86. }
  87. // Unwrap unwraps the Message entity that was returned from a transaction after it was closed,
  88. // so that all future queries will be executed through the driver which created the transaction.
  89. func (m *Message) Unwrap() *Message {
  90. _tx, ok := m.config.driver.(*txDriver)
  91. if !ok {
  92. panic("ent: Message is not a transactional entity")
  93. }
  94. m.config.driver = _tx.drv
  95. return m
  96. }
  97. // String implements the fmt.Stringer.
  98. func (m *Message) String() string {
  99. var builder strings.Builder
  100. builder.WriteString("Message(")
  101. builder.WriteString(fmt.Sprintf("id=%v, ", m.ID))
  102. builder.WriteString("wx_wxid=")
  103. builder.WriteString(m.WxWxid)
  104. builder.WriteString(", ")
  105. builder.WriteString("wxid=")
  106. builder.WriteString(m.Wxid)
  107. builder.WriteString(", ")
  108. builder.WriteString("content=")
  109. builder.WriteString(m.Content)
  110. builder.WriteByte(')')
  111. return builder.String()
  112. }
  113. // Messages is a parsable slice of Message.
  114. type Messages []*Message