sys_role.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. // ==========================================================================
  2. // This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
  3. // ==========================================================================
  4. package internal
  5. import (
  6. "context"
  7. "database/sql"
  8. "github.com/gogf/gf/database/gdb"
  9. "github.com/gogf/gf/frame/g"
  10. "github.com/gogf/gf/frame/gmvc"
  11. "time"
  12. "gfast/app/system/model"
  13. )
  14. // SysRoleDao is the manager for logic model data accessing
  15. // and custom defined data operations functions management.
  16. type SysRoleDao struct {
  17. gmvc.M
  18. DB gdb.DB
  19. Table string
  20. Columns sysRoleColumns
  21. }
  22. // SysRoleColumns defines and stores column names for table sys_role.
  23. type sysRoleColumns struct {
  24. Id string //
  25. Status string // 状态;0:禁用;1:正常
  26. ListOrder string // 排序
  27. Name string // 角色名称
  28. Remark string // 备注
  29. DataScope string // 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)
  30. }
  31. var (
  32. // SysRole is globally public accessible object for table sys_role operations.
  33. SysRole = SysRoleDao{
  34. M: g.DB("default").Model("sys_role").Safe(),
  35. DB: g.DB("default"),
  36. Table: "sys_role",
  37. Columns: sysRoleColumns{
  38. Id: "id",
  39. Status: "status",
  40. ListOrder: "list_order",
  41. Name: "name",
  42. Remark: "remark",
  43. DataScope: "data_scope",
  44. },
  45. }
  46. )
  47. // Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
  48. // of current DB object and with given context in it.
  49. // Note that this returned DB object can be used only once, so do not assign it to
  50. // a global or package variable for long using.
  51. func (d *SysRoleDao) Ctx(ctx context.Context) *SysRoleDao {
  52. return &SysRoleDao{M: d.M.Ctx(ctx)}
  53. }
  54. // As sets an alias name for current table.
  55. func (d *SysRoleDao) As(as string) *SysRoleDao {
  56. return &SysRoleDao{M: d.M.As(as)}
  57. }
  58. // TX sets the transaction for current operation.
  59. func (d *SysRoleDao) TX(tx *gdb.TX) *SysRoleDao {
  60. return &SysRoleDao{M: d.M.TX(tx)}
  61. }
  62. // Master marks the following operation on master node.
  63. func (d *SysRoleDao) Master() *SysRoleDao {
  64. return &SysRoleDao{M: d.M.Master()}
  65. }
  66. // Slave marks the following operation on slave node.
  67. // Note that it makes sense only if there's any slave node configured.
  68. func (d *SysRoleDao) Slave() *SysRoleDao {
  69. return &SysRoleDao{M: d.M.Slave()}
  70. }
  71. // Args sets custom arguments for model operation.
  72. func (d *SysRoleDao) Args(args ...interface{}) *SysRoleDao {
  73. return &SysRoleDao{M: d.M.Args(args...)}
  74. }
  75. // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
  76. // The parameter <table> can be joined table and its joined condition,
  77. // and also with its alias name, like:
  78. // Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
  79. // Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
  80. func (d *SysRoleDao) LeftJoin(table ...string) *SysRoleDao {
  81. return &SysRoleDao{M: d.M.LeftJoin(table...)}
  82. }
  83. // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
  84. // The parameter <table> can be joined table and its joined condition,
  85. // and also with its alias name, like:
  86. // Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
  87. // Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
  88. func (d *SysRoleDao) RightJoin(table ...string) *SysRoleDao {
  89. return &SysRoleDao{M: d.M.RightJoin(table...)}
  90. }
  91. // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
  92. // The parameter <table> can be joined table and its joined condition,
  93. // and also with its alias name, like:
  94. // Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
  95. // Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
  96. func (d *SysRoleDao) InnerJoin(table ...string) *SysRoleDao {
  97. return &SysRoleDao{M: d.M.InnerJoin(table...)}
  98. }
  99. // Fields sets the operation fields of the model, multiple fields joined using char ','.
  100. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  101. func (d *SysRoleDao) Fields(fieldNamesOrMapStruct ...interface{}) *SysRoleDao {
  102. return &SysRoleDao{M: d.M.Fields(fieldNamesOrMapStruct...)}
  103. }
  104. // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
  105. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  106. func (d *SysRoleDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *SysRoleDao {
  107. return &SysRoleDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...)}
  108. }
  109. // Option sets the extra operation option for the model.
  110. func (d *SysRoleDao) Option(option int) *SysRoleDao {
  111. return &SysRoleDao{M: d.M.Option(option)}
  112. }
  113. // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
  114. // the data and where attributes for empty values.
  115. func (d *SysRoleDao) OmitEmpty() *SysRoleDao {
  116. return &SysRoleDao{M: d.M.OmitEmpty()}
  117. }
  118. // Filter marks filtering the fields which does not exist in the fields of the operated table.
  119. func (d *SysRoleDao) Filter() *SysRoleDao {
  120. return &SysRoleDao{M: d.M.Filter()}
  121. }
  122. // Where sets the condition statement for the model. The parameter <where> can be type of
  123. // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
  124. // multiple conditions will be joined into where statement using "AND".
  125. // Eg:
  126. // Where("uid=10000")
  127. // Where("uid", 10000)
  128. // Where("money>? AND name like ?", 99999, "vip_%")
  129. // Where("uid", 1).Where("name", "john")
  130. // Where("status IN (?)", g.Slice{1,2,3})
  131. // Where("age IN(?,?)", 18, 50)
  132. // Where(User{ Id : 1, UserName : "john"})
  133. func (d *SysRoleDao) Where(where interface{}, args ...interface{}) *SysRoleDao {
  134. return &SysRoleDao{M: d.M.Where(where, args...)}
  135. }
  136. // WherePri does the same logic as M.Where except that if the parameter <where>
  137. // is a single condition like int/string/float/slice, it treats the condition as the primary
  138. // key value. That is, if primary key is "id" and given <where> parameter as "123", the
  139. // WherePri function treats the condition as "id=123", but M.Where treats the condition
  140. // as string "123".
  141. func (d *SysRoleDao) WherePri(where interface{}, args ...interface{}) *SysRoleDao {
  142. return &SysRoleDao{M: d.M.WherePri(where, args...)}
  143. }
  144. // And adds "AND" condition to the where statement.
  145. func (d *SysRoleDao) And(where interface{}, args ...interface{}) *SysRoleDao {
  146. return &SysRoleDao{M: d.M.And(where, args...)}
  147. }
  148. // Or adds "OR" condition to the where statement.
  149. func (d *SysRoleDao) Or(where interface{}, args ...interface{}) *SysRoleDao {
  150. return &SysRoleDao{M: d.M.Or(where, args...)}
  151. }
  152. // Group sets the "GROUP BY" statement for the model.
  153. func (d *SysRoleDao) Group(groupBy string) *SysRoleDao {
  154. return &SysRoleDao{M: d.M.Group(groupBy)}
  155. }
  156. // Order sets the "ORDER BY" statement for the model.
  157. func (d *SysRoleDao) Order(orderBy ...string) *SysRoleDao {
  158. return &SysRoleDao{M: d.M.Order(orderBy...)}
  159. }
  160. // Limit sets the "LIMIT" statement for the model.
  161. // The parameter <limit> can be either one or two number, if passed two number is passed,
  162. // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
  163. // statement.
  164. func (d *SysRoleDao) Limit(limit ...int) *SysRoleDao {
  165. return &SysRoleDao{M: d.M.Limit(limit...)}
  166. }
  167. // Offset sets the "OFFSET" statement for the model.
  168. // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
  169. func (d *SysRoleDao) Offset(offset int) *SysRoleDao {
  170. return &SysRoleDao{M: d.M.Offset(offset)}
  171. }
  172. // Page sets the paging number for the model.
  173. // The parameter <page> is started from 1 for paging.
  174. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
  175. func (d *SysRoleDao) Page(page, limit int) *SysRoleDao {
  176. return &SysRoleDao{M: d.M.Page(page, limit)}
  177. }
  178. // Batch sets the batch operation number for the model.
  179. func (d *SysRoleDao) Batch(batch int) *SysRoleDao {
  180. return &SysRoleDao{M: d.M.Batch(batch)}
  181. }
  182. // Cache sets the cache feature for the model. It caches the result of the sql, which means
  183. // if there's another same sql request, it just reads and returns the result from cache, it
  184. // but not committed and executed into the database.
  185. //
  186. // If the parameter <duration> < 0, which means it clear the cache with given <name>.
  187. // If the parameter <duration> = 0, which means it never expires.
  188. // If the parameter <duration> > 0, which means it expires after <duration>.
  189. //
  190. // The optional parameter <name> is used to bind a name to the cache, which means you can later
  191. // control the cache like changing the <duration> or clearing the cache with specified <name>.
  192. //
  193. // Note that, the cache feature is disabled if the model is operating on a transaction.
  194. func (d *SysRoleDao) Cache(duration time.Duration, name ...string) *SysRoleDao {
  195. return &SysRoleDao{M: d.M.Cache(duration, name...)}
  196. }
  197. // Data sets the operation data for the model.
  198. // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
  199. // Eg:
  200. // Data("uid=10000")
  201. // Data("uid", 10000)
  202. // Data(g.Map{"uid": 10000, "name":"john"})
  203. // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
  204. func (d *SysRoleDao) Data(data ...interface{}) *SysRoleDao {
  205. return &SysRoleDao{M: d.M.Data(data...)}
  206. }
  207. // All does "SELECT FROM ..." statement for the model.
  208. // It retrieves the records from table and returns the result as []*model.SysRole.
  209. // It returns nil if there's no record retrieved with the given conditions from table.
  210. //
  211. // The optional parameter <where> is the same as the parameter of M.Where function,
  212. // see M.Where.
  213. func (d *SysRoleDao) All(where ...interface{}) ([]*model.SysRole, error) {
  214. all, err := d.M.All(where...)
  215. if err != nil {
  216. return nil, err
  217. }
  218. var entities []*model.SysRole
  219. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  220. return nil, err
  221. }
  222. return entities, nil
  223. }
  224. // One retrieves one record from table and returns the result as *model.SysRole.
  225. // It returns nil if there's no record retrieved with the given conditions from table.
  226. //
  227. // The optional parameter <where> is the same as the parameter of M.Where function,
  228. // see M.Where.
  229. func (d *SysRoleDao) One(where ...interface{}) (*model.SysRole, error) {
  230. one, err := d.M.One(where...)
  231. if err != nil {
  232. return nil, err
  233. }
  234. var entity *model.SysRole
  235. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  236. return nil, err
  237. }
  238. return entity, nil
  239. }
  240. // FindOne retrieves and returns a single Record by M.WherePri and M.One.
  241. // Also see M.WherePri and M.One.
  242. func (d *SysRoleDao) FindOne(where ...interface{}) (*model.SysRole, error) {
  243. one, err := d.M.FindOne(where...)
  244. if err != nil {
  245. return nil, err
  246. }
  247. var entity *model.SysRole
  248. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  249. return nil, err
  250. }
  251. return entity, nil
  252. }
  253. // FindAll retrieves and returns Result by by M.WherePri and M.All.
  254. // Also see M.WherePri and M.All.
  255. func (d *SysRoleDao) FindAll(where ...interface{}) ([]*model.SysRole, error) {
  256. all, err := d.M.FindAll(where...)
  257. if err != nil {
  258. return nil, err
  259. }
  260. var entities []*model.SysRole
  261. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  262. return nil, err
  263. }
  264. return entities, nil
  265. }
  266. // Struct retrieves one record from table and converts it into given struct.
  267. // The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
  268. // it can create the struct internally during converting.
  269. //
  270. // The optional parameter <where> is the same as the parameter of Model.Where function,
  271. // see Model.Where.
  272. //
  273. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  274. // from table and <pointer> is not nil.
  275. //
  276. // Eg:
  277. // user := new(User)
  278. // err := dao.User.Where("id", 1).Struct(user)
  279. //
  280. // user := (*User)(nil)
  281. // err := dao.User.Where("id", 1).Struct(&user)
  282. func (d *SysRoleDao) Struct(pointer interface{}, where ...interface{}) error {
  283. return d.M.Struct(pointer, where...)
  284. }
  285. // Structs retrieves records from table and converts them into given struct slice.
  286. // The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
  287. // slice internally during converting.
  288. //
  289. // The optional parameter <where> is the same as the parameter of Model.Where function,
  290. // see Model.Where.
  291. //
  292. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  293. // from table and <pointer> is not empty.
  294. //
  295. // Eg:
  296. // users := ([]User)(nil)
  297. // err := dao.User.Structs(&users)
  298. //
  299. // users := ([]*User)(nil)
  300. // err := dao.User.Structs(&users)
  301. func (d *SysRoleDao) Structs(pointer interface{}, where ...interface{}) error {
  302. return d.M.Structs(pointer, where...)
  303. }
  304. // Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
  305. // It calls function Struct if <pointer> is type of *struct/**struct.
  306. // It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
  307. //
  308. // The optional parameter <where> is the same as the parameter of Model.Where function,
  309. // see Model.Where.
  310. //
  311. // Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
  312. //
  313. // Eg:
  314. // user := new(User)
  315. // err := dao.User.Where("id", 1).Scan(user)
  316. //
  317. // user := (*User)(nil)
  318. // err := dao.User.Where("id", 1).Scan(&user)
  319. //
  320. // users := ([]User)(nil)
  321. // err := dao.User.Scan(&users)
  322. //
  323. // users := ([]*User)(nil)
  324. // err := dao.User.Scan(&users)
  325. func (d *SysRoleDao) Scan(pointer interface{}, where ...interface{}) error {
  326. return d.M.Scan(pointer, where...)
  327. }
  328. // Chunk iterates the table with given size and callback function.
  329. func (d *SysRoleDao) Chunk(limit int, callback func(entities []*model.SysRole, err error) bool) {
  330. d.M.Chunk(limit, func(result gdb.Result, err error) bool {
  331. var entities []*model.SysRole
  332. err = result.Structs(&entities)
  333. if err == sql.ErrNoRows {
  334. return false
  335. }
  336. return callback(entities, err)
  337. })
  338. }
  339. // LockUpdate sets the lock for update for current operation.
  340. func (d *SysRoleDao) LockUpdate() *SysRoleDao {
  341. return &SysRoleDao{M: d.M.LockUpdate()}
  342. }
  343. // LockShared sets the lock in share mode for current operation.
  344. func (d *SysRoleDao) LockShared() *SysRoleDao {
  345. return &SysRoleDao{M: d.M.LockShared()}
  346. }
  347. // Unscoped enables/disables the soft deleting feature.
  348. func (d *SysRoleDao) Unscoped() *SysRoleDao {
  349. return &SysRoleDao{M: d.M.Unscoped()}
  350. }