chatsession.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "wechat-api/ent/chatsession"
  8. "entgo.io/ent"
  9. "entgo.io/ent/dialect/sql"
  10. )
  11. // ChatSession is the model entity for the ChatSession schema.
  12. type ChatSession 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. // 名称
  23. Name string `json:"name,omitempty"`
  24. // 用户ID
  25. UserID uint64 `json:"user_id,omitempty"`
  26. // 聊天ID
  27. BotID uint64 `json:"bot_id,omitempty"`
  28. // 类型:1-微信 2-小程序card 3-智能体
  29. BotType uint8 `json:"bot_type,omitempty"`
  30. selectValues sql.SelectValues
  31. }
  32. // scanValues returns the types for scanning values from sql.Rows.
  33. func (*ChatSession) scanValues(columns []string) ([]any, error) {
  34. values := make([]any, len(columns))
  35. for i := range columns {
  36. switch columns[i] {
  37. case chatsession.FieldID, chatsession.FieldUserID, chatsession.FieldBotID, chatsession.FieldBotType:
  38. values[i] = new(sql.NullInt64)
  39. case chatsession.FieldName:
  40. values[i] = new(sql.NullString)
  41. case chatsession.FieldCreatedAt, chatsession.FieldUpdatedAt, chatsession.FieldDeletedAt:
  42. values[i] = new(sql.NullTime)
  43. default:
  44. values[i] = new(sql.UnknownType)
  45. }
  46. }
  47. return values, nil
  48. }
  49. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  50. // to the ChatSession fields.
  51. func (cs *ChatSession) assignValues(columns []string, values []any) error {
  52. if m, n := len(values), len(columns); m < n {
  53. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  54. }
  55. for i := range columns {
  56. switch columns[i] {
  57. case chatsession.FieldID:
  58. value, ok := values[i].(*sql.NullInt64)
  59. if !ok {
  60. return fmt.Errorf("unexpected type %T for field id", value)
  61. }
  62. cs.ID = uint64(value.Int64)
  63. case chatsession.FieldCreatedAt:
  64. if value, ok := values[i].(*sql.NullTime); !ok {
  65. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  66. } else if value.Valid {
  67. cs.CreatedAt = value.Time
  68. }
  69. case chatsession.FieldUpdatedAt:
  70. if value, ok := values[i].(*sql.NullTime); !ok {
  71. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  72. } else if value.Valid {
  73. cs.UpdatedAt = value.Time
  74. }
  75. case chatsession.FieldDeletedAt:
  76. if value, ok := values[i].(*sql.NullTime); !ok {
  77. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  78. } else if value.Valid {
  79. cs.DeletedAt = value.Time
  80. }
  81. case chatsession.FieldName:
  82. if value, ok := values[i].(*sql.NullString); !ok {
  83. return fmt.Errorf("unexpected type %T for field name", values[i])
  84. } else if value.Valid {
  85. cs.Name = value.String
  86. }
  87. case chatsession.FieldUserID:
  88. if value, ok := values[i].(*sql.NullInt64); !ok {
  89. return fmt.Errorf("unexpected type %T for field user_id", values[i])
  90. } else if value.Valid {
  91. cs.UserID = uint64(value.Int64)
  92. }
  93. case chatsession.FieldBotID:
  94. if value, ok := values[i].(*sql.NullInt64); !ok {
  95. return fmt.Errorf("unexpected type %T for field bot_id", values[i])
  96. } else if value.Valid {
  97. cs.BotID = uint64(value.Int64)
  98. }
  99. case chatsession.FieldBotType:
  100. if value, ok := values[i].(*sql.NullInt64); !ok {
  101. return fmt.Errorf("unexpected type %T for field bot_type", values[i])
  102. } else if value.Valid {
  103. cs.BotType = uint8(value.Int64)
  104. }
  105. default:
  106. cs.selectValues.Set(columns[i], values[i])
  107. }
  108. }
  109. return nil
  110. }
  111. // Value returns the ent.Value that was dynamically selected and assigned to the ChatSession.
  112. // This includes values selected through modifiers, order, etc.
  113. func (cs *ChatSession) Value(name string) (ent.Value, error) {
  114. return cs.selectValues.Get(name)
  115. }
  116. // Update returns a builder for updating this ChatSession.
  117. // Note that you need to call ChatSession.Unwrap() before calling this method if this ChatSession
  118. // was returned from a transaction, and the transaction was committed or rolled back.
  119. func (cs *ChatSession) Update() *ChatSessionUpdateOne {
  120. return NewChatSessionClient(cs.config).UpdateOne(cs)
  121. }
  122. // Unwrap unwraps the ChatSession entity that was returned from a transaction after it was closed,
  123. // so that all future queries will be executed through the driver which created the transaction.
  124. func (cs *ChatSession) Unwrap() *ChatSession {
  125. _tx, ok := cs.config.driver.(*txDriver)
  126. if !ok {
  127. panic("ent: ChatSession is not a transactional entity")
  128. }
  129. cs.config.driver = _tx.drv
  130. return cs
  131. }
  132. // String implements the fmt.Stringer.
  133. func (cs *ChatSession) String() string {
  134. var builder strings.Builder
  135. builder.WriteString("ChatSession(")
  136. builder.WriteString(fmt.Sprintf("id=%v, ", cs.ID))
  137. builder.WriteString("created_at=")
  138. builder.WriteString(cs.CreatedAt.Format(time.ANSIC))
  139. builder.WriteString(", ")
  140. builder.WriteString("updated_at=")
  141. builder.WriteString(cs.UpdatedAt.Format(time.ANSIC))
  142. builder.WriteString(", ")
  143. builder.WriteString("deleted_at=")
  144. builder.WriteString(cs.DeletedAt.Format(time.ANSIC))
  145. builder.WriteString(", ")
  146. builder.WriteString("name=")
  147. builder.WriteString(cs.Name)
  148. builder.WriteString(", ")
  149. builder.WriteString("user_id=")
  150. builder.WriteString(fmt.Sprintf("%v", cs.UserID))
  151. builder.WriteString(", ")
  152. builder.WriteString("bot_id=")
  153. builder.WriteString(fmt.Sprintf("%v", cs.BotID))
  154. builder.WriteString(", ")
  155. builder.WriteString("bot_type=")
  156. builder.WriteString(fmt.Sprintf("%v", cs.BotType))
  157. builder.WriteByte(')')
  158. return builder.String()
  159. }
  160. // ChatSessions is a parsable slice of ChatSession.
  161. type ChatSessions []*ChatSession