sys_menu.go 16 KB

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