chat_records.gen.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. // Code generated by gorm.io/gen. DO NOT EDIT.
  2. // Code generated by gorm.io/gen. DO NOT EDIT.
  3. // Code generated by gorm.io/gen. DO NOT EDIT.
  4. package query
  5. import (
  6. "context"
  7. "gorm.io/gorm"
  8. "gorm.io/gorm/clause"
  9. "gorm.io/gorm/schema"
  10. "gorm.io/gen"
  11. "gorm.io/gen/field"
  12. "gorm.io/plugin/dbresolver"
  13. "wechat-api/database/dao/wechat/model"
  14. )
  15. func newChatRecord(db *gorm.DB, opts ...gen.DOOption) chatRecord {
  16. _chatRecord := chatRecord{}
  17. _chatRecord.chatRecordDo.UseDB(db, opts...)
  18. _chatRecord.chatRecordDo.UseModel(&model.ChatRecord{})
  19. tableName := _chatRecord.chatRecordDo.TableName()
  20. _chatRecord.ALL = field.NewAsterisk(tableName)
  21. _chatRecord.ID = field.NewInt64(tableName, "id")
  22. _chatRecord.CreatedAt = field.NewTime(tableName, "created_at")
  23. _chatRecord.UpdatedAt = field.NewTime(tableName, "updated_at")
  24. _chatRecord.DeletedAt = field.NewField(tableName, "deleted_at")
  25. _chatRecord.Content = field.NewString(tableName, "content")
  26. _chatRecord.ContentType = field.NewInt64(tableName, "content_type")
  27. _chatRecord.SessionID = field.NewInt64(tableName, "session_id")
  28. _chatRecord.UserID = field.NewInt64(tableName, "user_id")
  29. _chatRecord.BotID = field.NewInt64(tableName, "bot_id")
  30. _chatRecord.BotType = field.NewInt64(tableName, "bot_type")
  31. _chatRecord.fillFieldMap()
  32. return _chatRecord
  33. }
  34. // chatRecord 聊天历史记录
  35. type chatRecord struct {
  36. chatRecordDo
  37. ALL field.Asterisk
  38. ID field.Int64
  39. CreatedAt field.Time // Create Time | 创建日期
  40. UpdatedAt field.Time // Update Time | 修改日期
  41. DeletedAt field.Field // Delete Time | 删除日期
  42. Content field.String // 内容
  43. ContentType field.Int64 // 类型:1-提问 2-回答
  44. SessionID field.Int64 // 会话ID
  45. UserID field.Int64 // 用户ID
  46. BotID field.Int64 // 聊天ID
  47. BotType field.Int64 // 用户类型:1-微信 2-小程序 3-智能体
  48. fieldMap map[string]field.Expr
  49. }
  50. func (c chatRecord) Table(newTableName string) *chatRecord {
  51. c.chatRecordDo.UseTable(newTableName)
  52. return c.updateTableName(newTableName)
  53. }
  54. func (c chatRecord) As(alias string) *chatRecord {
  55. c.chatRecordDo.DO = *(c.chatRecordDo.As(alias).(*gen.DO))
  56. return c.updateTableName(alias)
  57. }
  58. func (c *chatRecord) updateTableName(table string) *chatRecord {
  59. c.ALL = field.NewAsterisk(table)
  60. c.ID = field.NewInt64(table, "id")
  61. c.CreatedAt = field.NewTime(table, "created_at")
  62. c.UpdatedAt = field.NewTime(table, "updated_at")
  63. c.DeletedAt = field.NewField(table, "deleted_at")
  64. c.Content = field.NewString(table, "content")
  65. c.ContentType = field.NewInt64(table, "content_type")
  66. c.SessionID = field.NewInt64(table, "session_id")
  67. c.UserID = field.NewInt64(table, "user_id")
  68. c.BotID = field.NewInt64(table, "bot_id")
  69. c.BotType = field.NewInt64(table, "bot_type")
  70. c.fillFieldMap()
  71. return c
  72. }
  73. func (c *chatRecord) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
  74. _f, ok := c.fieldMap[fieldName]
  75. if !ok || _f == nil {
  76. return nil, false
  77. }
  78. _oe, ok := _f.(field.OrderExpr)
  79. return _oe, ok
  80. }
  81. func (c *chatRecord) fillFieldMap() {
  82. c.fieldMap = make(map[string]field.Expr, 10)
  83. c.fieldMap["id"] = c.ID
  84. c.fieldMap["created_at"] = c.CreatedAt
  85. c.fieldMap["updated_at"] = c.UpdatedAt
  86. c.fieldMap["deleted_at"] = c.DeletedAt
  87. c.fieldMap["content"] = c.Content
  88. c.fieldMap["content_type"] = c.ContentType
  89. c.fieldMap["session_id"] = c.SessionID
  90. c.fieldMap["user_id"] = c.UserID
  91. c.fieldMap["bot_id"] = c.BotID
  92. c.fieldMap["bot_type"] = c.BotType
  93. }
  94. func (c chatRecord) clone(db *gorm.DB) chatRecord {
  95. c.chatRecordDo.ReplaceConnPool(db.Statement.ConnPool)
  96. return c
  97. }
  98. func (c chatRecord) replaceDB(db *gorm.DB) chatRecord {
  99. c.chatRecordDo.ReplaceDB(db)
  100. return c
  101. }
  102. type chatRecordDo struct{ gen.DO }
  103. type IChatRecordDo interface {
  104. gen.SubQuery
  105. Debug() IChatRecordDo
  106. WithContext(ctx context.Context) IChatRecordDo
  107. WithResult(fc func(tx gen.Dao)) gen.ResultInfo
  108. ReplaceDB(db *gorm.DB)
  109. ReadDB() IChatRecordDo
  110. WriteDB() IChatRecordDo
  111. As(alias string) gen.Dao
  112. Session(config *gorm.Session) IChatRecordDo
  113. Columns(cols ...field.Expr) gen.Columns
  114. Clauses(conds ...clause.Expression) IChatRecordDo
  115. Not(conds ...gen.Condition) IChatRecordDo
  116. Or(conds ...gen.Condition) IChatRecordDo
  117. Select(conds ...field.Expr) IChatRecordDo
  118. Where(conds ...gen.Condition) IChatRecordDo
  119. Order(conds ...field.Expr) IChatRecordDo
  120. Distinct(cols ...field.Expr) IChatRecordDo
  121. Omit(cols ...field.Expr) IChatRecordDo
  122. Join(table schema.Tabler, on ...field.Expr) IChatRecordDo
  123. LeftJoin(table schema.Tabler, on ...field.Expr) IChatRecordDo
  124. RightJoin(table schema.Tabler, on ...field.Expr) IChatRecordDo
  125. Group(cols ...field.Expr) IChatRecordDo
  126. Having(conds ...gen.Condition) IChatRecordDo
  127. Limit(limit int) IChatRecordDo
  128. Offset(offset int) IChatRecordDo
  129. Count() (count int64, err error)
  130. Scopes(funcs ...func(gen.Dao) gen.Dao) IChatRecordDo
  131. Unscoped() IChatRecordDo
  132. Create(values ...*model.ChatRecord) error
  133. CreateInBatches(values []*model.ChatRecord, batchSize int) error
  134. Save(values ...*model.ChatRecord) error
  135. First() (*model.ChatRecord, error)
  136. Take() (*model.ChatRecord, error)
  137. Last() (*model.ChatRecord, error)
  138. Find() ([]*model.ChatRecord, error)
  139. FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ChatRecord, err error)
  140. FindInBatches(result *[]*model.ChatRecord, batchSize int, fc func(tx gen.Dao, batch int) error) error
  141. Pluck(column field.Expr, dest interface{}) error
  142. Delete(...*model.ChatRecord) (info gen.ResultInfo, err error)
  143. Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
  144. UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
  145. Updates(value interface{}) (info gen.ResultInfo, err error)
  146. UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
  147. UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
  148. UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
  149. UpdateFrom(q gen.SubQuery) gen.Dao
  150. Attrs(attrs ...field.AssignExpr) IChatRecordDo
  151. Assign(attrs ...field.AssignExpr) IChatRecordDo
  152. Joins(fields ...field.RelationField) IChatRecordDo
  153. Preload(fields ...field.RelationField) IChatRecordDo
  154. FirstOrInit() (*model.ChatRecord, error)
  155. FirstOrCreate() (*model.ChatRecord, error)
  156. FindByPage(offset int, limit int) (result []*model.ChatRecord, count int64, err error)
  157. ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
  158. Scan(result interface{}) (err error)
  159. Returning(value interface{}, columns ...string) IChatRecordDo
  160. UnderlyingDB() *gorm.DB
  161. schema.Tabler
  162. }
  163. func (c chatRecordDo) Debug() IChatRecordDo {
  164. return c.withDO(c.DO.Debug())
  165. }
  166. func (c chatRecordDo) WithContext(ctx context.Context) IChatRecordDo {
  167. return c.withDO(c.DO.WithContext(ctx))
  168. }
  169. func (c chatRecordDo) ReadDB() IChatRecordDo {
  170. return c.Clauses(dbresolver.Read)
  171. }
  172. func (c chatRecordDo) WriteDB() IChatRecordDo {
  173. return c.Clauses(dbresolver.Write)
  174. }
  175. func (c chatRecordDo) Session(config *gorm.Session) IChatRecordDo {
  176. return c.withDO(c.DO.Session(config))
  177. }
  178. func (c chatRecordDo) Clauses(conds ...clause.Expression) IChatRecordDo {
  179. return c.withDO(c.DO.Clauses(conds...))
  180. }
  181. func (c chatRecordDo) Returning(value interface{}, columns ...string) IChatRecordDo {
  182. return c.withDO(c.DO.Returning(value, columns...))
  183. }
  184. func (c chatRecordDo) Not(conds ...gen.Condition) IChatRecordDo {
  185. return c.withDO(c.DO.Not(conds...))
  186. }
  187. func (c chatRecordDo) Or(conds ...gen.Condition) IChatRecordDo {
  188. return c.withDO(c.DO.Or(conds...))
  189. }
  190. func (c chatRecordDo) Select(conds ...field.Expr) IChatRecordDo {
  191. return c.withDO(c.DO.Select(conds...))
  192. }
  193. func (c chatRecordDo) Where(conds ...gen.Condition) IChatRecordDo {
  194. return c.withDO(c.DO.Where(conds...))
  195. }
  196. func (c chatRecordDo) Order(conds ...field.Expr) IChatRecordDo {
  197. return c.withDO(c.DO.Order(conds...))
  198. }
  199. func (c chatRecordDo) Distinct(cols ...field.Expr) IChatRecordDo {
  200. return c.withDO(c.DO.Distinct(cols...))
  201. }
  202. func (c chatRecordDo) Omit(cols ...field.Expr) IChatRecordDo {
  203. return c.withDO(c.DO.Omit(cols...))
  204. }
  205. func (c chatRecordDo) Join(table schema.Tabler, on ...field.Expr) IChatRecordDo {
  206. return c.withDO(c.DO.Join(table, on...))
  207. }
  208. func (c chatRecordDo) LeftJoin(table schema.Tabler, on ...field.Expr) IChatRecordDo {
  209. return c.withDO(c.DO.LeftJoin(table, on...))
  210. }
  211. func (c chatRecordDo) RightJoin(table schema.Tabler, on ...field.Expr) IChatRecordDo {
  212. return c.withDO(c.DO.RightJoin(table, on...))
  213. }
  214. func (c chatRecordDo) Group(cols ...field.Expr) IChatRecordDo {
  215. return c.withDO(c.DO.Group(cols...))
  216. }
  217. func (c chatRecordDo) Having(conds ...gen.Condition) IChatRecordDo {
  218. return c.withDO(c.DO.Having(conds...))
  219. }
  220. func (c chatRecordDo) Limit(limit int) IChatRecordDo {
  221. return c.withDO(c.DO.Limit(limit))
  222. }
  223. func (c chatRecordDo) Offset(offset int) IChatRecordDo {
  224. return c.withDO(c.DO.Offset(offset))
  225. }
  226. func (c chatRecordDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IChatRecordDo {
  227. return c.withDO(c.DO.Scopes(funcs...))
  228. }
  229. func (c chatRecordDo) Unscoped() IChatRecordDo {
  230. return c.withDO(c.DO.Unscoped())
  231. }
  232. func (c chatRecordDo) Create(values ...*model.ChatRecord) error {
  233. if len(values) == 0 {
  234. return nil
  235. }
  236. return c.DO.Create(values)
  237. }
  238. func (c chatRecordDo) CreateInBatches(values []*model.ChatRecord, batchSize int) error {
  239. return c.DO.CreateInBatches(values, batchSize)
  240. }
  241. // Save : !!! underlying implementation is different with GORM
  242. // The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
  243. func (c chatRecordDo) Save(values ...*model.ChatRecord) error {
  244. if len(values) == 0 {
  245. return nil
  246. }
  247. return c.DO.Save(values)
  248. }
  249. func (c chatRecordDo) First() (*model.ChatRecord, error) {
  250. if result, err := c.DO.First(); err != nil {
  251. return nil, err
  252. } else {
  253. return result.(*model.ChatRecord), nil
  254. }
  255. }
  256. func (c chatRecordDo) Take() (*model.ChatRecord, error) {
  257. if result, err := c.DO.Take(); err != nil {
  258. return nil, err
  259. } else {
  260. return result.(*model.ChatRecord), nil
  261. }
  262. }
  263. func (c chatRecordDo) Last() (*model.ChatRecord, error) {
  264. if result, err := c.DO.Last(); err != nil {
  265. return nil, err
  266. } else {
  267. return result.(*model.ChatRecord), nil
  268. }
  269. }
  270. func (c chatRecordDo) Find() ([]*model.ChatRecord, error) {
  271. result, err := c.DO.Find()
  272. return result.([]*model.ChatRecord), err
  273. }
  274. func (c chatRecordDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ChatRecord, err error) {
  275. buf := make([]*model.ChatRecord, 0, batchSize)
  276. err = c.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
  277. defer func() { results = append(results, buf...) }()
  278. return fc(tx, batch)
  279. })
  280. return results, err
  281. }
  282. func (c chatRecordDo) FindInBatches(result *[]*model.ChatRecord, batchSize int, fc func(tx gen.Dao, batch int) error) error {
  283. return c.DO.FindInBatches(result, batchSize, fc)
  284. }
  285. func (c chatRecordDo) Attrs(attrs ...field.AssignExpr) IChatRecordDo {
  286. return c.withDO(c.DO.Attrs(attrs...))
  287. }
  288. func (c chatRecordDo) Assign(attrs ...field.AssignExpr) IChatRecordDo {
  289. return c.withDO(c.DO.Assign(attrs...))
  290. }
  291. func (c chatRecordDo) Joins(fields ...field.RelationField) IChatRecordDo {
  292. for _, _f := range fields {
  293. c = *c.withDO(c.DO.Joins(_f))
  294. }
  295. return &c
  296. }
  297. func (c chatRecordDo) Preload(fields ...field.RelationField) IChatRecordDo {
  298. for _, _f := range fields {
  299. c = *c.withDO(c.DO.Preload(_f))
  300. }
  301. return &c
  302. }
  303. func (c chatRecordDo) FirstOrInit() (*model.ChatRecord, error) {
  304. if result, err := c.DO.FirstOrInit(); err != nil {
  305. return nil, err
  306. } else {
  307. return result.(*model.ChatRecord), nil
  308. }
  309. }
  310. func (c chatRecordDo) FirstOrCreate() (*model.ChatRecord, error) {
  311. if result, err := c.DO.FirstOrCreate(); err != nil {
  312. return nil, err
  313. } else {
  314. return result.(*model.ChatRecord), nil
  315. }
  316. }
  317. func (c chatRecordDo) FindByPage(offset int, limit int) (result []*model.ChatRecord, count int64, err error) {
  318. result, err = c.Offset(offset).Limit(limit).Find()
  319. if err != nil {
  320. return
  321. }
  322. if size := len(result); 0 < limit && 0 < size && size < limit {
  323. count = int64(size + offset)
  324. return
  325. }
  326. count, err = c.Offset(-1).Limit(-1).Count()
  327. return
  328. }
  329. func (c chatRecordDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
  330. count, err = c.Count()
  331. if err != nil {
  332. return
  333. }
  334. err = c.Offset(offset).Limit(limit).Scan(result)
  335. return
  336. }
  337. func (c chatRecordDo) Scan(result interface{}) (err error) {
  338. return c.DO.Scan(result)
  339. }
  340. func (c chatRecordDo) Delete(models ...*model.ChatRecord) (result gen.ResultInfo, err error) {
  341. return c.DO.Delete(models)
  342. }
  343. func (c *chatRecordDo) withDO(do gen.Dao) *chatRecordDo {
  344. c.DO = *do.(*gen.DO)
  345. return c
  346. }