sys_menu.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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. "dashoo.cn/micro/app/model"
  13. )
  14. // SysMenuDao is the manager for logic model data accessing
  15. // and custom defined data operations functions management.
  16. type SysMenuDao struct {
  17. gmvc.M
  18. DB gdb.DB
  19. Table string
  20. Columns sysMenuColumns
  21. }
  22. // SysMenuColumns defines and stores column names for table sys_menu.
  23. type sysMenuColumns struct {
  24. Id string // 菜单ID
  25. MenuName string // 菜单名称
  26. ParentId string // 父菜单ID
  27. Name string // 路由名称
  28. Path string // 路由地址
  29. Component string // 组件路径
  30. Query string // 路由参数
  31. IsFrame string // 是否为外链(10是20否)
  32. IsCache string // 是否缓存(10缓存20不缓存)
  33. MenuType string // 菜单类型(M目录C菜单 F按钮)
  34. Visible string // 显示状态(10显示20隐藏)
  35. Status string // 菜单状态(10正常20停用)
  36. Perms string // 权限标识
  37. Icon string // 菜单图标
  38. PlatformId string // 所属平台
  39. Sort string // 显示顺序
  40. ActiveMenu string // 高亮路由
  41. NoColumn string // 是否展示栏目20 不展示
  42. Remark string // 备注
  43. CreatedBy string // 创建者
  44. CreatedName string // 创建人
  45. CreatedTime string // 创建时间
  46. UpdatedBy string // 更新者
  47. UpdatedName string // 更新人
  48. UpdatedTime string // 更新时间
  49. DeletedTime string // 删除时间
  50. }
  51. var (
  52. // SysMenu is globally public accessible object for table sys_menu operations.
  53. SysMenu = SysMenuDao{
  54. M: g.DB("default").Model("sys_menu").Safe(),
  55. DB: g.DB("default"),
  56. Table: "sys_menu",
  57. Columns: sysMenuColumns{
  58. Id: "id",
  59. MenuName: "menu_name",
  60. ParentId: "parent_id",
  61. Name: "name",
  62. Path: "path",
  63. Component: "component",
  64. Query: "query",
  65. IsFrame: "is_frame",
  66. IsCache: "is_cache",
  67. MenuType: "menu_type",
  68. Visible: "visible",
  69. Status: "status",
  70. Perms: "perms",
  71. Icon: "icon",
  72. PlatformId: "platform_id",
  73. Sort: "sort",
  74. ActiveMenu: "active_menu",
  75. NoColumn: "no_column",
  76. Remark: "remark",
  77. CreatedBy: "created_by",
  78. CreatedName: "created_name",
  79. CreatedTime: "created_time",
  80. UpdatedBy: "updated_by",
  81. UpdatedName: "updated_name",
  82. UpdatedTime: "updated_time",
  83. DeletedTime: "deleted_time",
  84. },
  85. }
  86. )
  87. func NewSysMenuDao(tenant string) SysMenuDao {
  88. var dao SysMenuDao
  89. dao = SysMenuDao{
  90. M: g.DB(tenant).Model("sys_menu").Safe(),
  91. DB: g.DB(tenant),
  92. Table: "sys_menu",
  93. Columns: sysMenuColumns{
  94. Id: "id",
  95. MenuName: "menu_name",
  96. ParentId: "parent_id",
  97. Name: "name",
  98. Path: "path",
  99. Component: "component",
  100. Query: "query",
  101. IsFrame: "is_frame",
  102. IsCache: "is_cache",
  103. MenuType: "menu_type",
  104. Visible: "visible",
  105. Status: "status",
  106. Perms: "perms",
  107. Icon: "icon",
  108. PlatformId: "platform_id",
  109. Sort: "sort",
  110. ActiveMenu: "active_menu",
  111. NoColumn: "no_column",
  112. Remark: "remark",
  113. CreatedBy: "created_by",
  114. CreatedName: "created_name",
  115. CreatedTime: "created_time",
  116. UpdatedBy: "updated_by",
  117. UpdatedName: "updated_name",
  118. UpdatedTime: "updated_time",
  119. DeletedTime: "deleted_time",
  120. },
  121. }
  122. return dao
  123. }
  124. // Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
  125. // of current DB object and with given context in it.
  126. // Note that this returned DB object can be used only once, so do not assign it to
  127. // a global or package variable for long using.
  128. func (d *SysMenuDao) Ctx(ctx context.Context) *SysMenuDao {
  129. return &SysMenuDao{M: d.M.Ctx(ctx)}
  130. }
  131. // As sets an alias name for current table.
  132. func (d *SysMenuDao) As(as string) *SysMenuDao {
  133. return &SysMenuDao{M: d.M.As(as)}
  134. }
  135. // TX sets the transaction for current operation.
  136. func (d *SysMenuDao) TX(tx *gdb.TX) *SysMenuDao {
  137. return &SysMenuDao{M: d.M.TX(tx)}
  138. }
  139. // Master marks the following operation on master node.
  140. func (d *SysMenuDao) Master() *SysMenuDao {
  141. return &SysMenuDao{M: d.M.Master()}
  142. }
  143. // Slave marks the following operation on slave node.
  144. // Note that it makes sense only if there's any slave node configured.
  145. func (d *SysMenuDao) Slave() *SysMenuDao {
  146. return &SysMenuDao{M: d.M.Slave()}
  147. }
  148. // Args sets custom arguments for model operation.
  149. func (d *SysMenuDao) Args(args ...interface{}) *SysMenuDao {
  150. return &SysMenuDao{M: d.M.Args(args...)}
  151. }
  152. // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
  153. // The parameter <table> can be joined table and its joined condition,
  154. // and also with its alias name, like:
  155. // Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
  156. // Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
  157. func (d *SysMenuDao) LeftJoin(table ...string) *SysMenuDao {
  158. return &SysMenuDao{M: d.M.LeftJoin(table...)}
  159. }
  160. // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
  161. // The parameter <table> can be joined table and its joined condition,
  162. // and also with its alias name, like:
  163. // Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
  164. // Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
  165. func (d *SysMenuDao) RightJoin(table ...string) *SysMenuDao {
  166. return &SysMenuDao{M: d.M.RightJoin(table...)}
  167. }
  168. // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
  169. // The parameter <table> can be joined table and its joined condition,
  170. // and also with its alias name, like:
  171. // Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
  172. // Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
  173. func (d *SysMenuDao) InnerJoin(table ...string) *SysMenuDao {
  174. return &SysMenuDao{M: d.M.InnerJoin(table...)}
  175. }
  176. // Fields sets the operation fields of the model, multiple fields joined using char ','.
  177. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  178. func (d *SysMenuDao) Fields(fieldNamesOrMapStruct ...interface{}) *SysMenuDao {
  179. return &SysMenuDao{M: d.M.Fields(fieldNamesOrMapStruct...)}
  180. }
  181. // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
  182. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  183. func (d *SysMenuDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *SysMenuDao {
  184. return &SysMenuDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...)}
  185. }
  186. // Option sets the extra operation option for the model.
  187. func (d *SysMenuDao) Option(option int) *SysMenuDao {
  188. return &SysMenuDao{M: d.M.Option(option)}
  189. }
  190. // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
  191. // the data and where attributes for empty values.
  192. func (d *SysMenuDao) OmitEmpty() *SysMenuDao {
  193. return &SysMenuDao{M: d.M.OmitEmpty()}
  194. }
  195. // Filter marks filtering the fields which does not exist in the fields of the operated table.
  196. func (d *SysMenuDao) Filter() *SysMenuDao {
  197. return &SysMenuDao{M: d.M.Filter()}
  198. }
  199. // Where sets the condition statement for the model. The parameter <where> can be type of
  200. // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
  201. // multiple conditions will be joined into where statement using "AND".
  202. // Eg:
  203. // Where("uid=10000")
  204. // Where("uid", 10000)
  205. // Where("money>? AND name like ?", 99999, "vip_%")
  206. // Where("uid", 1).Where("name", "john")
  207. // Where("status IN (?)", g.Slice{1,2,3})
  208. // Where("age IN(?,?)", 18, 50)
  209. // Where(User{ Id : 1, UserName : "john"})
  210. func (d *SysMenuDao) Where(where interface{}, args ...interface{}) *SysMenuDao {
  211. return &SysMenuDao{M: d.M.Where(where, args...)}
  212. }
  213. // WherePri does the same logic as M.Where except that if the parameter <where>
  214. // is a single condition like int/string/float/slice, it treats the condition as the primary
  215. // key value. That is, if primary key is "id" and given <where> parameter as "123", the
  216. // WherePri function treats the condition as "id=123", but M.Where treats the condition
  217. // as string "123".
  218. func (d *SysMenuDao) WherePri(where interface{}, args ...interface{}) *SysMenuDao {
  219. return &SysMenuDao{M: d.M.WherePri(where, args...)}
  220. }
  221. // And adds "AND" condition to the where statement.
  222. func (d *SysMenuDao) And(where interface{}, args ...interface{}) *SysMenuDao {
  223. return &SysMenuDao{M: d.M.And(where, args...)}
  224. }
  225. // Or adds "OR" condition to the where statement.
  226. func (d *SysMenuDao) Or(where interface{}, args ...interface{}) *SysMenuDao {
  227. return &SysMenuDao{M: d.M.Or(where, args...)}
  228. }
  229. // Group sets the "GROUP BY" statement for the model.
  230. func (d *SysMenuDao) Group(groupBy string) *SysMenuDao {
  231. return &SysMenuDao{M: d.M.Group(groupBy)}
  232. }
  233. // Order sets the "ORDER BY" statement for the model.
  234. func (d *SysMenuDao) Order(orderBy ...string) *SysMenuDao {
  235. return &SysMenuDao{M: d.M.Order(orderBy...)}
  236. }
  237. // Limit sets the "LIMIT" statement for the model.
  238. // The parameter <limit> can be either one or two number, if passed two number is passed,
  239. // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
  240. // statement.
  241. func (d *SysMenuDao) Limit(limit ...int) *SysMenuDao {
  242. return &SysMenuDao{M: d.M.Limit(limit...)}
  243. }
  244. // Offset sets the "OFFSET" statement for the model.
  245. // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
  246. func (d *SysMenuDao) Offset(offset int) *SysMenuDao {
  247. return &SysMenuDao{M: d.M.Offset(offset)}
  248. }
  249. // Page sets the paging number for the model.
  250. // The parameter <page> is started from 1 for paging.
  251. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
  252. func (d *SysMenuDao) Page(page, limit int) *SysMenuDao {
  253. return &SysMenuDao{M: d.M.Page(page, limit)}
  254. }
  255. // Batch sets the batch operation number for the model.
  256. func (d *SysMenuDao) Batch(batch int) *SysMenuDao {
  257. return &SysMenuDao{M: d.M.Batch(batch)}
  258. }
  259. // Cache sets the cache feature for the model. It caches the result of the sql, which means
  260. // if there's another same sql request, it just reads and returns the result from cache, it
  261. // but not committed and executed into the database.
  262. //
  263. // If the parameter <duration> < 0, which means it clear the cache with given <name>.
  264. // If the parameter <duration> = 0, which means it never expires.
  265. // If the parameter <duration> > 0, which means it expires after <duration>.
  266. //
  267. // The optional parameter <name> is used to bind a name to the cache, which means you can later
  268. // control the cache like changing the <duration> or clearing the cache with specified <name>.
  269. //
  270. // Note that, the cache feature is disabled if the model is operating on a transaction.
  271. func (d *SysMenuDao) Cache(duration time.Duration, name ...string) *SysMenuDao {
  272. return &SysMenuDao{M: d.M.Cache(duration, name...)}
  273. }
  274. // Data sets the operation data for the model.
  275. // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
  276. // Eg:
  277. // Data("uid=10000")
  278. // Data("uid", 10000)
  279. // Data(g.Map{"uid": 10000, "name":"john"})
  280. // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
  281. func (d *SysMenuDao) Data(data ...interface{}) *SysMenuDao {
  282. return &SysMenuDao{M: d.M.Data(data...)}
  283. }
  284. // All does "SELECT FROM ..." statement for the model.
  285. // It retrieves the records from table and returns the result as []*model.SysMenu.
  286. // It returns nil if there's no record retrieved with the given conditions from table.
  287. //
  288. // The optional parameter <where> is the same as the parameter of M.Where function,
  289. // see M.Where.
  290. func (d *SysMenuDao) All(where ...interface{}) ([]*model.SysMenu, error) {
  291. all, err := d.M.All(where...)
  292. if err != nil {
  293. return nil, err
  294. }
  295. var entities []*model.SysMenu
  296. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  297. return nil, err
  298. }
  299. return entities, nil
  300. }
  301. // One retrieves one record from table and returns the result as *model.SysMenu.
  302. // It returns nil if there's no record retrieved with the given conditions from table.
  303. //
  304. // The optional parameter <where> is the same as the parameter of M.Where function,
  305. // see M.Where.
  306. func (d *SysMenuDao) One(where ...interface{}) (*model.SysMenu, error) {
  307. one, err := d.M.One(where...)
  308. if err != nil {
  309. return nil, err
  310. }
  311. var entity *model.SysMenu
  312. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  313. return nil, err
  314. }
  315. return entity, nil
  316. }
  317. // FindOne retrieves and returns a single Record by M.WherePri and M.One.
  318. // Also see M.WherePri and M.One.
  319. func (d *SysMenuDao) FindOne(where ...interface{}) (*model.SysMenu, error) {
  320. one, err := d.M.FindOne(where...)
  321. if err != nil {
  322. return nil, err
  323. }
  324. var entity *model.SysMenu
  325. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  326. return nil, err
  327. }
  328. return entity, nil
  329. }
  330. // FindAll retrieves and returns Result by by M.WherePri and M.All.
  331. // Also see M.WherePri and M.All.
  332. func (d *SysMenuDao) FindAll(where ...interface{}) ([]*model.SysMenu, error) {
  333. all, err := d.M.FindAll(where...)
  334. if err != nil {
  335. return nil, err
  336. }
  337. var entities []*model.SysMenu
  338. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  339. return nil, err
  340. }
  341. return entities, nil
  342. }
  343. // Struct retrieves one record from table and converts it into given struct.
  344. // The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
  345. // it can create the struct internally during converting.
  346. //
  347. // The optional parameter <where> is the same as the parameter of Model.Where function,
  348. // see Model.Where.
  349. //
  350. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  351. // from table and <pointer> is not nil.
  352. //
  353. // Eg:
  354. // user := new(User)
  355. // err := dao.User.Where("id", 1).Struct(user)
  356. //
  357. // user := (*User)(nil)
  358. // err := dao.User.Where("id", 1).Struct(&user)
  359. func (d *SysMenuDao) Struct(pointer interface{}, where ...interface{}) error {
  360. return d.M.Struct(pointer, where...)
  361. }
  362. // Structs retrieves records from table and converts them into given struct slice.
  363. // The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
  364. // slice internally during converting.
  365. //
  366. // The optional parameter <where> is the same as the parameter of Model.Where function,
  367. // see Model.Where.
  368. //
  369. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  370. // from table and <pointer> is not empty.
  371. //
  372. // Eg:
  373. // users := ([]User)(nil)
  374. // err := dao.User.Structs(&users)
  375. //
  376. // users := ([]*User)(nil)
  377. // err := dao.User.Structs(&users)
  378. func (d *SysMenuDao) Structs(pointer interface{}, where ...interface{}) error {
  379. return d.M.Structs(pointer, where...)
  380. }
  381. // Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
  382. // It calls function Struct if <pointer> is type of *struct/**struct.
  383. // It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
  384. //
  385. // The optional parameter <where> is the same as the parameter of Model.Where function,
  386. // see Model.Where.
  387. //
  388. // Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
  389. //
  390. // Eg:
  391. // user := new(User)
  392. // err := dao.User.Where("id", 1).Scan(user)
  393. //
  394. // user := (*User)(nil)
  395. // err := dao.User.Where("id", 1).Scan(&user)
  396. //
  397. // users := ([]User)(nil)
  398. // err := dao.User.Scan(&users)
  399. //
  400. // users := ([]*User)(nil)
  401. // err := dao.User.Scan(&users)
  402. func (d *SysMenuDao) Scan(pointer interface{}, where ...interface{}) error {
  403. return d.M.Scan(pointer, where...)
  404. }
  405. // Chunk iterates the table with given size and callback function.
  406. func (d *SysMenuDao) Chunk(limit int, callback func(entities []*model.SysMenu, err error) bool) {
  407. d.M.Chunk(limit, func(result gdb.Result, err error) bool {
  408. var entities []*model.SysMenu
  409. err = result.Structs(&entities)
  410. if err == sql.ErrNoRows {
  411. return false
  412. }
  413. return callback(entities, err)
  414. })
  415. }
  416. // LockUpdate sets the lock for update for current operation.
  417. func (d *SysMenuDao) LockUpdate() *SysMenuDao {
  418. return &SysMenuDao{M: d.M.LockUpdate()}
  419. }
  420. // LockShared sets the lock in share mode for current operation.
  421. func (d *SysMenuDao) LockShared() *SysMenuDao {
  422. return &SysMenuDao{M: d.M.LockShared()}
  423. }
  424. // Unscoped enables/disables the soft deleting feature.
  425. func (d *SysMenuDao) Unscoped() *SysMenuDao {
  426. return &SysMenuDao{M: d.M.Unscoped()}
  427. }