sys_dept_model.go 11 KB

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