sys_menu.go 16 KB

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