chat_session.gen.go 12 KB

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