sys_post_model.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. // ==========================================================================
  2. // This is auto-generated by gf cli tool. You may not really want to edit it.
  3. // ==========================================================================
  4. package sys_post
  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 sys_post operations.
  13. type arModel struct {
  14. gmvc.M
  15. }
  16. var (
  17. // Table is the table name of sys_post.
  18. Table = "sys_post"
  19. // Model is the model object of sys_post.
  20. Model = &arModel{g.DB("default").Table(Table).Safe()}
  21. // Columns defines and stores column names for table sys_post.
  22. Columns = struct {
  23. PostId string // 岗位ID
  24. PostCode string // 岗位编码
  25. PostName string // 岗位名称
  26. PostSort string // 显示顺序
  27. Status string // 状态(0正常 1停用)
  28. CreateBy string // 创建者
  29. CreateTime string // 创建时间
  30. UpdateBy string // 更新者
  31. UpdateTime string // 更新时间
  32. Remark string // 备注
  33. }{
  34. PostId: "post_id",
  35. PostCode: "post_code",
  36. PostName: "post_name",
  37. PostSort: "post_sort",
  38. Status: "status",
  39. CreateBy: "create_by",
  40. CreateTime: "create_time",
  41. UpdateBy: "update_by",
  42. UpdateTime: "update_time",
  43. Remark: "remark",
  44. }
  45. )
  46. // FindOne is a convenience method for Model.FindOne.
  47. // See Model.FindOne.
  48. func FindOne(where ...interface{}) (*Entity, error) {
  49. return Model.FindOne(where...)
  50. }
  51. // FindAll is a convenience method for Model.FindAll.
  52. // See Model.FindAll.
  53. func FindAll(where ...interface{}) ([]*Entity, error) {
  54. return Model.FindAll(where...)
  55. }
  56. // FindValue is a convenience method for Model.FindValue.
  57. // See Model.FindValue.
  58. func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
  59. return Model.FindValue(fieldsAndWhere...)
  60. }
  61. // FindArray is a convenience method for Model.FindArray.
  62. // See Model.FindArray.
  63. func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) {
  64. return Model.FindArray(fieldsAndWhere...)
  65. }
  66. // FindCount is a convenience method for Model.FindCount.
  67. // See Model.FindCount.
  68. func FindCount(where ...interface{}) (int, error) {
  69. return Model.FindCount(where...)
  70. }
  71. // Insert is a convenience method for Model.Insert.
  72. func Insert(data ...interface{}) (result sql.Result, err error) {
  73. return Model.Insert(data...)
  74. }
  75. // InsertIgnore is a convenience method for Model.InsertIgnore.
  76. func InsertIgnore(data ...interface{}) (result sql.Result, err error) {
  77. return Model.InsertIgnore(data...)
  78. }
  79. // Replace is a convenience method for Model.Replace.
  80. func Replace(data ...interface{}) (result sql.Result, err error) {
  81. return Model.Replace(data...)
  82. }
  83. // Save is a convenience method for Model.Save.
  84. func Save(data ...interface{}) (result sql.Result, err error) {
  85. return Model.Save(data...)
  86. }
  87. // Update is a convenience method for Model.Update.
  88. func Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
  89. return Model.Update(dataAndWhere...)
  90. }
  91. // Delete is a convenience method for Model.Delete.
  92. func Delete(where ...interface{}) (result sql.Result, err error) {
  93. return Model.Delete(where...)
  94. }
  95. // As sets an alias name for current table.
  96. func (m *arModel) As(as string) *arModel {
  97. return &arModel{m.M.As(as)}
  98. }
  99. // TX sets the transaction for current operation.
  100. func (m *arModel) TX(tx *gdb.TX) *arModel {
  101. return &arModel{m.M.TX(tx)}
  102. }
  103. // Master marks the following operation on master node.
  104. func (m *arModel) Master() *arModel {
  105. return &arModel{m.M.Master()}
  106. }
  107. // Slave marks the following operation on slave node.
  108. // Note that it makes sense only if there's any slave node configured.
  109. func (m *arModel) Slave() *arModel {
  110. return &arModel{m.M.Slave()}
  111. }
  112. // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
  113. func (m *arModel) LeftJoin(joinTable string, on string) *arModel {
  114. return &arModel{m.M.LeftJoin(joinTable, on)}
  115. }
  116. // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
  117. func (m *arModel) RightJoin(joinTable string, on string) *arModel {
  118. return &arModel{m.M.RightJoin(joinTable, on)}
  119. }
  120. // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
  121. func (m *arModel) InnerJoin(joinTable string, on string) *arModel {
  122. return &arModel{m.M.InnerJoin(joinTable, on)}
  123. }
  124. // Fields sets the operation fields of the model, multiple fields joined using char ','.
  125. func (m *arModel) Fields(fields string) *arModel {
  126. return &arModel{m.M.Fields(fields)}
  127. }
  128. // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
  129. func (m *arModel) FieldsEx(fields string) *arModel {
  130. return &arModel{m.M.FieldsEx(fields)}
  131. }
  132. // Option sets the extra operation option for the model.
  133. func (m *arModel) Option(option int) *arModel {
  134. return &arModel{m.M.Option(option)}
  135. }
  136. // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
  137. // the data and where attributes for empty values.
  138. func (m *arModel) OmitEmpty() *arModel {
  139. return &arModel{m.M.OmitEmpty()}
  140. }
  141. // Filter marks filtering the fields which does not exist in the fields of the operated table.
  142. func (m *arModel) Filter() *arModel {
  143. return &arModel{m.M.Filter()}
  144. }
  145. // Where sets the condition statement for the model. The parameter <where> can be type of
  146. // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
  147. // multiple conditions will be joined into where statement using "AND".
  148. // Eg:
  149. // Where("uid=10000")
  150. // Where("uid", 10000)
  151. // Where("money>? AND name like ?", 99999, "vip_%")
  152. // Where("uid", 1).Where("name", "john")
  153. // Where("status IN (?)", g.Slice{1,2,3})
  154. // Where("age IN(?,?)", 18, 50)
  155. // Where(User{ Id : 1, UserName : "john"})
  156. func (m *arModel) Where(where interface{}, args ...interface{}) *arModel {
  157. return &arModel{m.M.Where(where, args...)}
  158. }
  159. // And adds "AND" condition to the where statement.
  160. func (m *arModel) And(where interface{}, args ...interface{}) *arModel {
  161. return &arModel{m.M.And(where, args...)}
  162. }
  163. // Or adds "OR" condition to the where statement.
  164. func (m *arModel) Or(where interface{}, args ...interface{}) *arModel {
  165. return &arModel{m.M.Or(where, args...)}
  166. }
  167. // Group sets the "GROUP BY" statement for the model.
  168. func (m *arModel) Group(groupBy string) *arModel {
  169. return &arModel{m.M.Group(groupBy)}
  170. }
  171. // Order sets the "ORDER BY" statement for the model.
  172. func (m *arModel) Order(orderBy string) *arModel {
  173. return &arModel{m.M.Order(orderBy)}
  174. }
  175. // Limit sets the "LIMIT" statement for the model.
  176. // The parameter <limit> can be either one or two number, if passed two number is passed,
  177. // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
  178. // statement.
  179. func (m *arModel) Limit(limit ...int) *arModel {
  180. return &arModel{m.M.Limit(limit...)}
  181. }
  182. // Offset sets the "OFFSET" statement for the model.
  183. // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
  184. func (m *arModel) Offset(offset int) *arModel {
  185. return &arModel{m.M.Offset(offset)}
  186. }
  187. // Page sets the paging number for the model.
  188. // The parameter <page> is started from 1 for paging.
  189. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
  190. func (m *arModel) Page(page, limit int) *arModel {
  191. return &arModel{m.M.Page(page, limit)}
  192. }
  193. // Batch sets the batch operation number for the model.
  194. func (m *arModel) Batch(batch int) *arModel {
  195. return &arModel{m.M.Batch(batch)}
  196. }
  197. // Cache sets the cache feature for the model. It caches the result of the sql, which means
  198. // if there's another same sql request, it just reads and returns the result from cache, it
  199. // but not committed and executed into the database.
  200. //
  201. // If the parameter <duration> < 0, which means it clear the cache with given <name>.
  202. // If the parameter <duration> = 0, which means it never expires.
  203. // If the parameter <duration> > 0, which means it expires after <duration>.
  204. //
  205. // The optional parameter <name> is used to bind a name to the cache, which means you can later
  206. // control the cache like changing the <duration> or clearing the cache with specified <name>.
  207. //
  208. // Note that, the cache feature is disabled if the model is operating on a transaction.
  209. func (m *arModel) Cache(duration time.Duration, name ...string) *arModel {
  210. return &arModel{m.M.Cache(duration, name...)}
  211. }
  212. // Data sets the operation data for the model.
  213. // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
  214. // Eg:
  215. // Data("uid=10000")
  216. // Data("uid", 10000)
  217. // Data(g.Map{"uid": 10000, "name":"john"})
  218. // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
  219. func (m *arModel) Data(data ...interface{}) *arModel {
  220. return &arModel{m.M.Data(data...)}
  221. }
  222. // All does "SELECT FROM ..." statement for the model.
  223. // It retrieves the records from table and returns the result as []*Entity.
  224. // It returns nil if there's no record retrieved with the given conditions from table.
  225. //
  226. // The optional parameter <where> is the same as the parameter of Model.Where function,
  227. // see Model.Where.
  228. func (m *arModel) All(where ...interface{}) ([]*Entity, error) {
  229. all, err := m.M.All(where...)
  230. if err != nil {
  231. return nil, err
  232. }
  233. var entities []*Entity
  234. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  235. return nil, err
  236. }
  237. return entities, nil
  238. }
  239. // One retrieves one record from table and returns the result as *Entity.
  240. // It returns nil if there's no record retrieved with the given conditions from table.
  241. //
  242. // The optional parameter <where> is the same as the parameter of Model.Where function,
  243. // see Model.Where.
  244. func (m *arModel) One(where ...interface{}) (*Entity, error) {
  245. one, err := m.M.One(where...)
  246. if err != nil {
  247. return nil, err
  248. }
  249. var entity *Entity
  250. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  251. return nil, err
  252. }
  253. return entity, nil
  254. }
  255. // FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
  256. // Also see Model.WherePri and Model.One.
  257. func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
  258. one, err := m.M.FindOne(where...)
  259. if err != nil {
  260. return nil, err
  261. }
  262. var entity *Entity
  263. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  264. return nil, err
  265. }
  266. return entity, nil
  267. }
  268. // FindAll retrieves and returns Result by by Model.WherePri and Model.All.
  269. // Also see Model.WherePri and Model.All.
  270. func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
  271. all, err := m.M.FindAll(where...)
  272. if err != nil {
  273. return nil, err
  274. }
  275. var entities []*Entity
  276. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  277. return nil, err
  278. }
  279. return entities, nil
  280. }
  281. // Chunk iterates the table with given size and callback function.
  282. func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) {
  283. m.M.Chunk(limit, func(result gdb.Result, err error) bool {
  284. var entities []*Entity
  285. err = result.Structs(&entities)
  286. if err == sql.ErrNoRows {
  287. return false
  288. }
  289. return callback(entities, err)
  290. })
  291. }
  292. // LockUpdate sets the lock for update for current operation.
  293. func (m *arModel) LockUpdate() *arModel {
  294. return &arModel{m.M.LockUpdate()}
  295. }
  296. // LockShared sets the lock in share mode for current operation.
  297. func (m *arModel) LockShared() *arModel {
  298. return &arModel{m.M.LockShared()}
  299. }