cms_news_model.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. // ==========================================================================
  2. // This is auto-generated by gf cli tool. You may not really want to edit it.
  3. // ==========================================================================
  4. package cms_news
  5. import (
  6. "database/sql"
  7. "github.com/gogf/gf/database/gdb"
  8. "github.com/gogf/gf/frame/g"
  9. "github.com/gogf/gf/frame/gmvc"
  10. "time"
  11. )
  12. // arModel is a active record design model for table cms_news operations.
  13. type arModel struct {
  14. gmvc.M
  15. }
  16. var (
  17. // Table is the table name of cms_news.
  18. Table = "cms_news"
  19. // Model is the model object of cms_news.
  20. Model = &arModel{g.DB("default").Table(Table).Safe()}
  21. // Columns defines and stores column names for table cms_news.
  22. Columns = struct {
  23. Id string //
  24. NewsFormat string // 内容格式;1:html;2:md
  25. UserId string // 发表者用户id
  26. NewsStatus string // 状态;1:已发布;0:未发布;
  27. IsTop string // 是否置顶;1:置顶;0:不置顶
  28. Recommended string // 是否推荐;1:推荐;0:不推荐
  29. NewsHits string // 查看数
  30. NewsLike string // 点赞数
  31. CreateTime string // 创建时间
  32. UpdateTime string // 更新时间
  33. PublishedTime string // 发布时间
  34. DeleteTime string // 删除时间
  35. NewsTitle string // post标题
  36. NewsKeywords string // seo keywords
  37. NewsExcerpt string // post摘要
  38. NewsSource string // 转载文章的来源
  39. NewsContent string // 文章内容
  40. Thumbnail string // 缩略图
  41. IsJump string // 是否跳转地址
  42. JumpUrl string // 跳转地址
  43. IsPushed string // 是否已推送
  44. }{
  45. Id: "id",
  46. NewsFormat: "news_format",
  47. UserId: "user_id",
  48. NewsStatus: "news_status",
  49. IsTop: "is_top",
  50. Recommended: "recommended",
  51. NewsHits: "news_hits",
  52. NewsLike: "news_like",
  53. CreateTime: "create_time",
  54. UpdateTime: "update_time",
  55. PublishedTime: "published_time",
  56. DeleteTime: "delete_time",
  57. NewsTitle: "news_title",
  58. NewsKeywords: "news_keywords",
  59. NewsExcerpt: "news_excerpt",
  60. NewsSource: "news_source",
  61. NewsContent: "news_content",
  62. Thumbnail: "thumbnail",
  63. IsJump: "is_jump",
  64. JumpUrl: "jump_url",
  65. IsPushed: "is_pushed",
  66. }
  67. )
  68. // FindOne is a convenience method for Model.FindOne.
  69. // See Model.FindOne.
  70. func FindOne(where ...interface{}) (*Entity, error) {
  71. return Model.FindOne(where...)
  72. }
  73. // FindAll is a convenience method for Model.FindAll.
  74. // See Model.FindAll.
  75. func FindAll(where ...interface{}) ([]*Entity, error) {
  76. return Model.FindAll(where...)
  77. }
  78. // FindValue is a convenience method for Model.FindValue.
  79. // See Model.FindValue.
  80. func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
  81. return Model.FindValue(fieldsAndWhere...)
  82. }
  83. // FindArray is a convenience method for Model.FindArray.
  84. // See Model.FindArray.
  85. func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) {
  86. return Model.FindArray(fieldsAndWhere...)
  87. }
  88. // FindCount is a convenience method for Model.FindCount.
  89. // See Model.FindCount.
  90. func FindCount(where ...interface{}) (int, error) {
  91. return Model.FindCount(where...)
  92. }
  93. // Insert is a convenience method for Model.Insert.
  94. func Insert(data ...interface{}) (result sql.Result, err error) {
  95. return Model.Insert(data...)
  96. }
  97. // InsertIgnore is a convenience method for Model.InsertIgnore.
  98. func InsertIgnore(data ...interface{}) (result sql.Result, err error) {
  99. return Model.InsertIgnore(data...)
  100. }
  101. // Replace is a convenience method for Model.Replace.
  102. func Replace(data ...interface{}) (result sql.Result, err error) {
  103. return Model.Replace(data...)
  104. }
  105. // Save is a convenience method for Model.Save.
  106. func Save(data ...interface{}) (result sql.Result, err error) {
  107. return Model.Save(data...)
  108. }
  109. // Update is a convenience method for Model.Update.
  110. func Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
  111. return Model.Update(dataAndWhere...)
  112. }
  113. // Delete is a convenience method for Model.Delete.
  114. func Delete(where ...interface{}) (result sql.Result, err error) {
  115. return Model.Delete(where...)
  116. }
  117. // As sets an alias name for current table.
  118. func (m *arModel) As(as string) *arModel {
  119. return &arModel{m.M.As(as)}
  120. }
  121. // TX sets the transaction for current operation.
  122. func (m *arModel) TX(tx *gdb.TX) *arModel {
  123. return &arModel{m.M.TX(tx)}
  124. }
  125. // Master marks the following operation on master node.
  126. func (m *arModel) Master() *arModel {
  127. return &arModel{m.M.Master()}
  128. }
  129. // Slave marks the following operation on slave node.
  130. // Note that it makes sense only if there's any slave node configured.
  131. func (m *arModel) Slave() *arModel {
  132. return &arModel{m.M.Slave()}
  133. }
  134. // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
  135. func (m *arModel) LeftJoin(joinTable string, on string) *arModel {
  136. return &arModel{m.M.LeftJoin(joinTable, on)}
  137. }
  138. // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
  139. func (m *arModel) RightJoin(joinTable string, on string) *arModel {
  140. return &arModel{m.M.RightJoin(joinTable, on)}
  141. }
  142. // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
  143. func (m *arModel) InnerJoin(joinTable string, on string) *arModel {
  144. return &arModel{m.M.InnerJoin(joinTable, on)}
  145. }
  146. // Fields sets the operation fields of the model, multiple fields joined using char ','.
  147. func (m *arModel) Fields(fields string) *arModel {
  148. return &arModel{m.M.Fields(fields)}
  149. }
  150. // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
  151. func (m *arModel) FieldsEx(fields string) *arModel {
  152. return &arModel{m.M.FieldsEx(fields)}
  153. }
  154. // Option sets the extra operation option for the model.
  155. func (m *arModel) Option(option int) *arModel {
  156. return &arModel{m.M.Option(option)}
  157. }
  158. // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
  159. // the data and where attributes for empty values.
  160. func (m *arModel) OmitEmpty() *arModel {
  161. return &arModel{m.M.OmitEmpty()}
  162. }
  163. // Filter marks filtering the fields which does not exist in the fields of the operated table.
  164. func (m *arModel) Filter() *arModel {
  165. return &arModel{m.M.Filter()}
  166. }
  167. // Where sets the condition statement for the model. The parameter <where> can be type of
  168. // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
  169. // multiple conditions will be joined into where statement using "AND".
  170. // Eg:
  171. // Where("uid=10000")
  172. // Where("uid", 10000)
  173. // Where("money>? AND name like ?", 99999, "vip_%")
  174. // Where("uid", 1).Where("name", "john")
  175. // Where("status IN (?)", g.Slice{1,2,3})
  176. // Where("age IN(?,?)", 18, 50)
  177. // Where(User{ Id : 1, UserName : "john"})
  178. func (m *arModel) Where(where interface{}, args ...interface{}) *arModel {
  179. return &arModel{m.M.Where(where, args...)}
  180. }
  181. // And adds "AND" condition to the where statement.
  182. func (m *arModel) And(where interface{}, args ...interface{}) *arModel {
  183. return &arModel{m.M.And(where, args...)}
  184. }
  185. // Or adds "OR" condition to the where statement.
  186. func (m *arModel) Or(where interface{}, args ...interface{}) *arModel {
  187. return &arModel{m.M.Or(where, args...)}
  188. }
  189. // Group sets the "GROUP BY" statement for the model.
  190. func (m *arModel) Group(groupBy string) *arModel {
  191. return &arModel{m.M.Group(groupBy)}
  192. }
  193. // Order sets the "ORDER BY" statement for the model.
  194. func (m *arModel) Order(orderBy string) *arModel {
  195. return &arModel{m.M.Order(orderBy)}
  196. }
  197. // Limit sets the "LIMIT" statement for the model.
  198. // The parameter <limit> can be either one or two number, if passed two number is passed,
  199. // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
  200. // statement.
  201. func (m *arModel) Limit(limit ...int) *arModel {
  202. return &arModel{m.M.Limit(limit...)}
  203. }
  204. // Offset sets the "OFFSET" statement for the model.
  205. // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
  206. func (m *arModel) Offset(offset int) *arModel {
  207. return &arModel{m.M.Offset(offset)}
  208. }
  209. // Page sets the paging number for the model.
  210. // The parameter <page> is started from 1 for paging.
  211. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
  212. func (m *arModel) Page(page, limit int) *arModel {
  213. return &arModel{m.M.Page(page, limit)}
  214. }
  215. // Batch sets the batch operation number for the model.
  216. func (m *arModel) Batch(batch int) *arModel {
  217. return &arModel{m.M.Batch(batch)}
  218. }
  219. // Cache sets the cache feature for the model. It caches the result of the sql, which means
  220. // if there's another same sql request, it just reads and returns the result from cache, it
  221. // but not committed and executed into the database.
  222. //
  223. // If the parameter <duration> < 0, which means it clear the cache with given <name>.
  224. // If the parameter <duration> = 0, which means it never expires.
  225. // If the parameter <duration> > 0, which means it expires after <duration>.
  226. //
  227. // The optional parameter <name> is used to bind a name to the cache, which means you can later
  228. // control the cache like changing the <duration> or clearing the cache with specified <name>.
  229. //
  230. // Note that, the cache feature is disabled if the model is operating on a transaction.
  231. func (m *arModel) Cache(duration time.Duration, name ...string) *arModel {
  232. return &arModel{m.M.Cache(duration, name...)}
  233. }
  234. // Data sets the operation data for the model.
  235. // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
  236. // Eg:
  237. // Data("uid=10000")
  238. // Data("uid", 10000)
  239. // Data(g.Map{"uid": 10000, "name":"john"})
  240. // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
  241. func (m *arModel) Data(data ...interface{}) *arModel {
  242. return &arModel{m.M.Data(data...)}
  243. }
  244. // All does "SELECT FROM ..." statement for the model.
  245. // It retrieves the records from table and returns the result as []*Entity.
  246. // It returns nil if there's no record retrieved with the given conditions from table.
  247. //
  248. // The optional parameter <where> is the same as the parameter of Model.Where function,
  249. // see Model.Where.
  250. func (m *arModel) All(where ...interface{}) ([]*Entity, error) {
  251. all, err := m.M.All(where...)
  252. if err != nil {
  253. return nil, err
  254. }
  255. var entities []*Entity
  256. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  257. return nil, err
  258. }
  259. return entities, nil
  260. }
  261. // One retrieves one record from table and returns the result as *Entity.
  262. // It returns nil if there's no record retrieved with the given conditions from table.
  263. //
  264. // The optional parameter <where> is the same as the parameter of Model.Where function,
  265. // see Model.Where.
  266. func (m *arModel) One(where ...interface{}) (*Entity, error) {
  267. one, err := m.M.One(where...)
  268. if err != nil {
  269. return nil, err
  270. }
  271. var entity *Entity
  272. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  273. return nil, err
  274. }
  275. return entity, nil
  276. }
  277. // FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
  278. // Also see Model.WherePri and Model.One.
  279. func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
  280. one, err := m.M.FindOne(where...)
  281. if err != nil {
  282. return nil, err
  283. }
  284. var entity *Entity
  285. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  286. return nil, err
  287. }
  288. return entity, nil
  289. }
  290. // FindAll retrieves and returns Result by by Model.WherePri and Model.All.
  291. // Also see Model.WherePri and Model.All.
  292. func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
  293. all, err := m.M.FindAll(where...)
  294. if err != nil {
  295. return nil, err
  296. }
  297. var entities []*Entity
  298. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  299. return nil, err
  300. }
  301. return entities, nil
  302. }
  303. // Chunk iterates the table with given size and callback function.
  304. func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) {
  305. m.M.Chunk(limit, func(result gdb.Result, err error) bool {
  306. var entities []*Entity
  307. err = result.Structs(&entities)
  308. if err == sql.ErrNoRows {
  309. return false
  310. }
  311. return callback(entities, err)
  312. })
  313. }
  314. // LockUpdate sets the lock for update for current operation.
  315. func (m *arModel) LockUpdate() *arModel {
  316. return &arModel{m.M.LockUpdate()}
  317. }
  318. // LockShared sets the lock in share mode for current operation.
  319. func (m *arModel) LockShared() *arModel {
  320. return &arModel{m.M.LockShared()}
  321. }