cms_news_model.go 12 KB

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