sys_menu.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  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. "github.com/gogf/gf/util/gconv"
  12. "strings"
  13. "time"
  14. "dashoo.cn/micro/app/model"
  15. )
  16. // SysMenuDao is the manager for logic model data accessing and custom defined data operations functions management.
  17. type SysMenuDao struct {
  18. gmvc.M // M is the core and embedded struct that inherits all chaining operations from gdb.Model.
  19. C sysMenuColumns // C is the short type for Columns, which contains all the column names of Table for convenient usage.
  20. DB gdb.DB // DB is the raw underlying database management object.
  21. Table string // Table is the underlying table name of the DAO.
  22. TableAs string // TableAs is the underlying table alias name of the DAO.
  23. }
  24. // SysMenuColumns defines and stores column names for table sys_menu.
  25. type sysMenuColumns struct {
  26. Id string // 菜单ID
  27. MenuName string // 菜单名称
  28. ParentId string // 父菜单ID
  29. Name string // 路由名称
  30. Path string // 路由地址
  31. Component string // 组件路径
  32. Query string // 路由参数
  33. IsFrame string // 是否为外链(10是20否)
  34. IsCache string // 是否缓存(10缓存20不缓存)
  35. MenuType string // 菜单类型(M目录C菜单 F按钮)
  36. Visible string // 显示状态(10显示20隐藏)
  37. Status string // 菜单状态(10正常20停用)
  38. Perms string // 权限标识
  39. Icon string // 菜单图标
  40. PlatformId string // 所属平台
  41. Sort string // 显示顺序
  42. ActiveMenu string // 高亮路由
  43. NoColumn string // 是否展示栏目20 不展示
  44. Remark string // 备注
  45. CreatedBy string // 创建者
  46. CreatedName string // 创建人
  47. CreatedTime string // 创建时间
  48. UpdatedBy string // 更新者
  49. UpdatedName string // 更新人
  50. UpdatedTime string // 更新时间
  51. DeletedTime string // 删除时间
  52. }
  53. var (
  54. // SysMenu is globally public accessible object for table sys_menu operations.
  55. SysMenu = SysMenuDao{
  56. M: g.DB("default").Model("sys_menu").Safe(),
  57. DB: g.DB("default"),
  58. Table: "sys_menu",
  59. C: sysMenuColumns{
  60. Id: "id",
  61. MenuName: "menu_name",
  62. ParentId: "parent_id",
  63. Name: "name",
  64. Path: "path",
  65. Component: "component",
  66. Query: "query",
  67. IsFrame: "is_frame",
  68. IsCache: "is_cache",
  69. MenuType: "menu_type",
  70. Visible: "visible",
  71. Status: "status",
  72. Perms: "perms",
  73. Icon: "icon",
  74. PlatformId: "platform_id",
  75. Sort: "sort",
  76. ActiveMenu: "active_menu",
  77. NoColumn: "no_column",
  78. Remark: "remark",
  79. CreatedBy: "created_by",
  80. CreatedName: "created_name",
  81. CreatedTime: "created_time",
  82. UpdatedBy: "updated_by",
  83. UpdatedName: "updated_name",
  84. UpdatedTime: "updated_time",
  85. DeletedTime: "deleted_time",
  86. },
  87. }
  88. )
  89. func NewSysMenuDao(tenant string) SysMenuDao {
  90. var dao SysMenuDao
  91. dao = SysMenuDao{
  92. M: g.DB(tenant).Model("sys_menu").Safe(),
  93. DB: g.DB(tenant),
  94. Table: "sys_menu",
  95. C: sysMenuColumns{
  96. Id: "id",
  97. MenuName: "menu_name",
  98. ParentId: "parent_id",
  99. Name: "name",
  100. Path: "path",
  101. Component: "component",
  102. Query: "query",
  103. IsFrame: "is_frame",
  104. IsCache: "is_cache",
  105. MenuType: "menu_type",
  106. Visible: "visible",
  107. Status: "status",
  108. Perms: "perms",
  109. Icon: "icon",
  110. PlatformId: "platform_id",
  111. Sort: "sort",
  112. ActiveMenu: "active_menu",
  113. NoColumn: "no_column",
  114. Remark: "remark",
  115. CreatedBy: "created_by",
  116. CreatedName: "created_name",
  117. CreatedTime: "created_time",
  118. UpdatedBy: "updated_by",
  119. UpdatedName: "updated_name",
  120. UpdatedTime: "updated_time",
  121. DeletedTime: "deleted_time",
  122. },
  123. }
  124. return dao
  125. }
  126. // Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
  127. // of current DB object and with given context in it.
  128. // Note that this returned DB object can be used only once, so do not assign it to
  129. // a global or package variable for long using.
  130. func (d *SysMenuDao) Ctx(ctx context.Context) *SysMenuDao {
  131. return &SysMenuDao{M: d.M.Ctx(ctx), Table: d.Table, TableAs: d.TableAs}
  132. }
  133. // GetCtx returns the context for current Model.
  134. // It returns "context.Background() i"s there's no context previously set.
  135. func (d *SysMenuDao) GetCtx() context.Context {
  136. return d.M.GetCtx()
  137. }
  138. // As sets an alias name for current table.
  139. func (d *SysMenuDao) As(as string) *SysMenuDao {
  140. return &SysMenuDao{M: d.M.As(as), Table: d.Table, TableAs: as}
  141. }
  142. // TX sets the transaction for current operation.
  143. func (d *SysMenuDao) TX(tx *gdb.TX) *SysMenuDao {
  144. return &SysMenuDao{M: d.M.TX(tx), Table: d.Table, TableAs: d.TableAs}
  145. }
  146. // Master marks the following operation on master node.
  147. func (d *SysMenuDao) Master() *SysMenuDao {
  148. return &SysMenuDao{M: d.M.Master(), Table: d.Table, TableAs: d.TableAs}
  149. }
  150. // Slave marks the following operation on slave node.
  151. // Note that it makes sense only if there's any slave node configured.
  152. func (d *SysMenuDao) Slave() *SysMenuDao {
  153. return &SysMenuDao{M: d.M.Slave(), Table: d.Table, TableAs: d.TableAs}
  154. }
  155. // Args sets custom arguments for model operation.
  156. func (d *SysMenuDao) Args(args ...interface{}) *SysMenuDao {
  157. return &SysMenuDao{M: d.M.Args(args...), Table: d.Table, TableAs: d.TableAs}
  158. }
  159. // Handler calls each of "handlers" on current Model and returns a new Model.
  160. // ModelHandler is a function that handles given Model and returns a new Model that is custom modified.
  161. func (d *SysMenuDao) Handler(handlers ...gdb.ModelHandler) *SysMenuDao {
  162. return &SysMenuDao{M: d.M.Handler(handlers...), Table: d.Table, TableAs: d.TableAs}
  163. }
  164. // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
  165. // The parameter <table> can be joined table and its joined condition,
  166. // and also with its alias name, like:
  167. // Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
  168. // Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
  169. func (d *SysMenuDao) LeftJoin(table ...string) *SysMenuDao {
  170. return &SysMenuDao{M: d.M.LeftJoin(table...), Table: d.Table, TableAs: d.TableAs}
  171. }
  172. // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
  173. // The parameter <table> can be joined table and its joined condition,
  174. // and also with its alias name, like:
  175. // Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
  176. // Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
  177. func (d *SysMenuDao) RightJoin(table ...string) *SysMenuDao {
  178. return &SysMenuDao{M: d.M.RightJoin(table...), Table: d.Table, TableAs: d.TableAs}
  179. }
  180. // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
  181. // The parameter <table> can be joined table and its joined condition,
  182. // and also with its alias name, like:
  183. // Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
  184. // Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
  185. func (d *SysMenuDao) InnerJoin(table ...string) *SysMenuDao {
  186. return &SysMenuDao{M: d.M.InnerJoin(table...), Table: d.Table, TableAs: d.TableAs}
  187. }
  188. // Fields sets the operation fields of the model, multiple fields joined using char ','.
  189. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  190. func (d *SysMenuDao) Fields(fieldNamesOrMapStruct ...interface{}) *SysMenuDao {
  191. return &SysMenuDao{M: d.M.Fields(fieldNamesOrMapStruct...), Table: d.Table, TableAs: d.TableAs}
  192. }
  193. // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
  194. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  195. func (d *SysMenuDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *SysMenuDao {
  196. return &SysMenuDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...), Table: d.Table, TableAs: d.TableAs}
  197. }
  198. // FieldCount formats and appends commonly used field "COUNT(column)" to the select fields of model.
  199. func (d *SysMenuDao) FieldCount(column string, as ...string) *SysMenuDao {
  200. return &SysMenuDao{M: d.M.FieldCount(column, as...), Table: d.Table, TableAs: d.TableAs}
  201. }
  202. // FieldSum formats and appends commonly used field "SUM(column)" to the select fields of model.
  203. func (d *SysMenuDao) FieldSum(column string, as ...string) *SysMenuDao {
  204. return &SysMenuDao{M: d.M.FieldSum(column, as...), Table: d.Table, TableAs: d.TableAs}
  205. }
  206. // FieldMin formats and appends commonly used field "MIN(column)" to the select fields of model.
  207. func (d *SysMenuDao) FieldMin(column string, as ...string) *SysMenuDao {
  208. return &SysMenuDao{M: d.M.FieldMin(column, as...), Table: d.Table, TableAs: d.TableAs}
  209. }
  210. // FieldMax formats and appends commonly used field "MAX(column)" to the select fields of model.
  211. func (d *SysMenuDao) FieldMax(column string, as ...string) *SysMenuDao {
  212. return &SysMenuDao{M: d.M.FieldMax(column, as...), Table: d.Table, TableAs: d.TableAs}
  213. }
  214. // FieldAvg formats and appends commonly used field "AVG(column)" to the select fields of model.
  215. func (d *SysMenuDao) FieldAvg(column string, as ...string) *SysMenuDao {
  216. return &SysMenuDao{M: d.M.FieldAvg(column, as...), Table: d.Table, TableAs: d.TableAs}
  217. }
  218. // Option adds extra operation option for the model.
  219. // Deprecated, use separate operations instead.
  220. func (d *SysMenuDao) Option(option int) *SysMenuDao {
  221. return &SysMenuDao{M: d.M.Option(option), Table: d.Table, TableAs: d.TableAs}
  222. }
  223. // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
  224. // the data and where attributes for empty values.
  225. func (d *SysMenuDao) OmitEmpty() *SysMenuDao {
  226. return &SysMenuDao{M: d.M.OmitEmpty(), Table: d.Table, TableAs: d.TableAs}
  227. }
  228. // OmitEmptyWhere sets optionOmitEmptyWhere option for the model, which automatically filers
  229. // the Where/Having parameters for "empty" values.
  230. func (d *SysMenuDao) OmitEmptyWhere() *SysMenuDao {
  231. return &SysMenuDao{M: d.M.OmitEmptyWhere(), Table: d.Table, TableAs: d.TableAs}
  232. }
  233. // OmitEmptyData sets optionOmitEmptyData option for the model, which automatically filers
  234. // the Data parameters for "empty" values.
  235. func (d *SysMenuDao) OmitEmptyData() *SysMenuDao {
  236. return &SysMenuDao{M: d.M.OmitEmptyData(), Table: d.Table, TableAs: d.TableAs}
  237. }
  238. // OmitNil sets optionOmitNil option for the model, which automatically filers
  239. // the data and where parameters for "nil" values.
  240. func (d *SysMenuDao) OmitNil() *SysMenuDao {
  241. return &SysMenuDao{M: d.M.OmitNil(), Table: d.Table, TableAs: d.TableAs}
  242. }
  243. // OmitNilWhere sets optionOmitNilWhere option for the model, which automatically filers
  244. // the Where/Having parameters for "nil" values.
  245. func (d *SysMenuDao) OmitNilWhere() *SysMenuDao {
  246. return &SysMenuDao{M: d.M.OmitNilWhere(), Table: d.Table, TableAs: d.TableAs}
  247. }
  248. // OmitNilData sets optionOmitNilData option for the model, which automatically filers
  249. // the Data parameters for "nil" values.
  250. func (d *SysMenuDao) OmitNilData() *SysMenuDao {
  251. return &SysMenuDao{M: d.M.OmitNilData(), Table: d.Table, TableAs: d.TableAs}
  252. }
  253. // Filter marks filtering the fields which does not exist in the fields of the operated table.
  254. // Note that this function supports only single table operations.
  255. // Deprecated, filter feature is automatically enabled from GoFrame v1.16.0, it is so no longer used.
  256. func (d *SysMenuDao) Filter() *SysMenuDao {
  257. return &SysMenuDao{M: d.M.Filter(), Table: d.Table, TableAs: d.TableAs}
  258. }
  259. // Where sets the condition statement for the model. The parameter <where> can be type of
  260. // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
  261. // multiple conditions will be joined into where statement using "AND".
  262. // Eg:
  263. // Where("uid=10000")
  264. // Where("uid", 10000)
  265. // Where("money>? AND name like ?", 99999, "vip_%")
  266. // Where("uid", 1).Where("name", "john")
  267. // Where("status IN (?)", g.Slice{1,2,3})
  268. // Where("age IN(?,?)", 18, 50)
  269. // Where(User{ Id : 1, UserName : "john"})
  270. func (d *SysMenuDao) Where(where interface{}, args ...interface{}) *SysMenuDao {
  271. return &SysMenuDao{M: d.M.Where(where, args...), Table: d.Table, TableAs: d.TableAs}
  272. }
  273. // WherePri does the same logic as M.Where except that if the parameter <where>
  274. // is a single condition like int/string/float/slice, it treats the condition as the primary
  275. // key value. That is, if primary key is "id" and given <where> parameter as "123", the
  276. // WherePri function treats the condition as "id=123", but M.Where treats the condition
  277. // as string "123".
  278. func (d *SysMenuDao) WherePri(where interface{}, args ...interface{}) *SysMenuDao {
  279. return &SysMenuDao{M: d.M.WherePri(where, args...), Table: d.Table, TableAs: d.TableAs}
  280. }
  281. // Having sets the having statement for the model.
  282. // The parameters of this function usage are as the same as function Where.
  283. // See Where.
  284. func (d *SysMenuDao) Having(having interface{}, args ...interface{}) *SysMenuDao {
  285. return &SysMenuDao{M: d.M.Having(having, args...), Table: d.Table, TableAs: d.TableAs}
  286. }
  287. // Wheref builds condition string using fmt.Sprintf and arguments.
  288. // Note that if the number of "args" is more than the place holder in "format",
  289. // the extra "args" will be used as the where condition arguments of the Model.
  290. func (d *SysMenuDao) Wheref(format string, args ...interface{}) *SysMenuDao {
  291. return &SysMenuDao{M: d.M.Wheref(format, args...), Table: d.Table, TableAs: d.TableAs}
  292. }
  293. // WhereLT builds "column < value" statement.
  294. func (d *SysMenuDao) WhereLT(column string, value interface{}) *SysMenuDao {
  295. return &SysMenuDao{M: d.M.WhereLT(column, value), Table: d.Table, TableAs: d.TableAs}
  296. }
  297. // WhereLTE builds "column <= value" statement.
  298. func (d *SysMenuDao) WhereLTE(column string, value interface{}) *SysMenuDao {
  299. return &SysMenuDao{M: d.M.WhereLTE(column, value), Table: d.Table, TableAs: d.TableAs}
  300. }
  301. // WhereGT builds "column > value" statement.
  302. func (d *SysMenuDao) WhereGT(column string, value interface{}) *SysMenuDao {
  303. return &SysMenuDao{M: d.M.WhereGT(column, value), Table: d.Table, TableAs: d.TableAs}
  304. }
  305. // WhereGTE builds "column >= value" statement.
  306. func (d *SysMenuDao) WhereGTE(column string, value interface{}) *SysMenuDao {
  307. return &SysMenuDao{M: d.M.WhereGTE(column, value), Table: d.Table, TableAs: d.TableAs}
  308. }
  309. // WhereBetween builds "column BETWEEN min AND max" statement.
  310. func (d *SysMenuDao) WhereBetween(column string, min, max interface{}) *SysMenuDao {
  311. return &SysMenuDao{M: d.M.WhereBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
  312. }
  313. // WhereLike builds "column LIKE like" statement.
  314. func (d *SysMenuDao) WhereLike(column string, like interface{}) *SysMenuDao {
  315. return &SysMenuDao{M: d.M.WhereLike(column, like), Table: d.Table, TableAs: d.TableAs}
  316. }
  317. // WhereIn builds "column IN (in)" statement.
  318. func (d *SysMenuDao) WhereIn(column string, in interface{}) *SysMenuDao {
  319. return &SysMenuDao{M: d.M.WhereIn(column, in), Table: d.Table, TableAs: d.TableAs}
  320. }
  321. // WhereNull builds "columns[0] IS NULL AND columns[1] IS NULL ..." statement.
  322. func (d *SysMenuDao) WhereNull(columns ...string) *SysMenuDao {
  323. return &SysMenuDao{M: d.M.WhereNull(columns...), Table: d.Table, TableAs: d.TableAs}
  324. }
  325. // WhereNotBetween builds "column NOT BETWEEN min AND max" statement.
  326. func (d *SysMenuDao) WhereNotBetween(column string, min, max interface{}) *SysMenuDao {
  327. return &SysMenuDao{M: d.M.WhereNotBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
  328. }
  329. // WhereNotLike builds "column NOT LIKE like" statement.
  330. func (d *SysMenuDao) WhereNotLike(column string, like interface{}) *SysMenuDao {
  331. return &SysMenuDao{M: d.M.WhereNotLike(column, like), Table: d.Table, TableAs: d.TableAs}
  332. }
  333. // WhereNot builds "column != value" statement.
  334. func (d *SysMenuDao) WhereNot(column string, value interface{}) *SysMenuDao {
  335. return &SysMenuDao{M: d.M.WhereNot(column, value), Table: d.Table, TableAs: d.TableAs}
  336. }
  337. // WhereNotIn builds "column NOT IN (in)" statement.
  338. func (d *SysMenuDao) WhereNotIn(column string, in interface{}) *SysMenuDao {
  339. return &SysMenuDao{M: d.M.WhereNotIn(column, in), Table: d.Table, TableAs: d.TableAs}
  340. }
  341. // WhereNotNull builds "columns[0] IS NOT NULL AND columns[1] IS NOT NULL ..." statement.
  342. func (d *SysMenuDao) WhereNotNull(columns ...string) *SysMenuDao {
  343. return &SysMenuDao{M: d.M.WhereNotNull(columns...), Table: d.Table, TableAs: d.TableAs}
  344. }
  345. // WhereOr adds "OR" condition to the where statement.
  346. func (d *SysMenuDao) WhereOr(where interface{}, args ...interface{}) *SysMenuDao {
  347. return &SysMenuDao{M: d.M.WhereOr(where, args...), Table: d.Table, TableAs: d.TableAs}
  348. }
  349. // WhereOrf builds "OR" condition string using fmt.Sprintf and arguments.
  350. func (d *SysMenuDao) WhereOrf(format string, args ...interface{}) *SysMenuDao {
  351. return &SysMenuDao{M: d.M.WhereOrf(format, args...), Table: d.Table, TableAs: d.TableAs}
  352. }
  353. // WhereOrLT builds "column < value" statement in "OR" conditions..
  354. func (d *SysMenuDao) WhereOrLT(column string, value interface{}) *SysMenuDao {
  355. return &SysMenuDao{M: d.M.WhereOrLT(column, value), Table: d.Table, TableAs: d.TableAs}
  356. }
  357. // WhereOrLTE builds "column <= value" statement in "OR" conditions..
  358. func (d *SysMenuDao) WhereOrLTE(column string, value interface{}) *SysMenuDao {
  359. return &SysMenuDao{M: d.M.WhereOrLTE(column, value), Table: d.Table, TableAs: d.TableAs}
  360. }
  361. // WhereOrGT builds "column > value" statement in "OR" conditions..
  362. func (d *SysMenuDao) WhereOrGT(column string, value interface{}) *SysMenuDao {
  363. return &SysMenuDao{M: d.M.WhereOrGT(column, value), Table: d.Table, TableAs: d.TableAs}
  364. }
  365. // WhereOrGTE builds "column >= value" statement in "OR" conditions..
  366. func (d *SysMenuDao) WhereOrGTE(column string, value interface{}) *SysMenuDao {
  367. return &SysMenuDao{M: d.M.WhereOrGTE(column, value), Table: d.Table, TableAs: d.TableAs}
  368. }
  369. // WhereOrBetween builds "column BETWEEN min AND max" statement in "OR" conditions.
  370. func (d *SysMenuDao) WhereOrBetween(column string, min, max interface{}) *SysMenuDao {
  371. return &SysMenuDao{M: d.M.WhereOrBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
  372. }
  373. // WhereOrLike builds "column LIKE like" statement in "OR" conditions.
  374. func (d *SysMenuDao) WhereOrLike(column string, like interface{}) *SysMenuDao {
  375. return &SysMenuDao{M: d.M.WhereOrLike(column, like), Table: d.Table, TableAs: d.TableAs}
  376. }
  377. // WhereOrIn builds "column IN (in)" statement in "OR" conditions.
  378. func (d *SysMenuDao) WhereOrIn(column string, in interface{}) *SysMenuDao {
  379. return &SysMenuDao{M: d.M.WhereOrIn(column, in), Table: d.Table, TableAs: d.TableAs}
  380. }
  381. // WhereOrNull builds "columns[0] IS NULL OR columns[1] IS NULL ..." statement in "OR" conditions.
  382. func (d *SysMenuDao) WhereOrNull(columns ...string) *SysMenuDao {
  383. return &SysMenuDao{M: d.M.WhereOrNull(columns...), Table: d.Table, TableAs: d.TableAs}
  384. }
  385. // WhereOrNotBetween builds "column NOT BETWEEN min AND max" statement in "OR" conditions.
  386. func (d *SysMenuDao) WhereOrNotBetween(column string, min, max interface{}) *SysMenuDao {
  387. return &SysMenuDao{M: d.M.WhereOrNotBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
  388. }
  389. // WhereOrNotLike builds "column NOT LIKE like" statement in "OR" conditions.
  390. func (d *SysMenuDao) WhereOrNotLike(column string, like interface{}) *SysMenuDao {
  391. return &SysMenuDao{M: d.M.WhereOrNotLike(column, like), Table: d.Table, TableAs: d.TableAs}
  392. }
  393. // WhereOrNotIn builds "column NOT IN (in)" statement.
  394. func (d *SysMenuDao) WhereOrNotIn(column string, in interface{}) *SysMenuDao {
  395. return &SysMenuDao{M: d.M.WhereOrNotIn(column, in), Table: d.Table, TableAs: d.TableAs}
  396. }
  397. // WhereOrNotNull builds "columns[0] IS NOT NULL OR columns[1] IS NOT NULL ..." statement in "OR" conditions.
  398. func (d *SysMenuDao) WhereOrNotNull(columns ...string) *SysMenuDao {
  399. return &SysMenuDao{M: d.M.WhereOrNotNull(columns...), Table: d.Table, TableAs: d.TableAs}
  400. }
  401. // Group sets the "GROUP BY" statement for the model.
  402. func (d *SysMenuDao) Group(groupBy ...string) *SysMenuDao {
  403. return &SysMenuDao{M: d.M.Group(groupBy...), Table: d.Table, TableAs: d.TableAs}
  404. }
  405. // And adds "AND" condition to the where statement.
  406. // Deprecated, use Where instead.
  407. func (d *SysMenuDao) And(where interface{}, args ...interface{}) *SysMenuDao {
  408. return &SysMenuDao{M: d.M.And(where, args...), Table: d.Table, TableAs: d.TableAs}
  409. }
  410. // Or adds "OR" condition to the where statement.
  411. // Deprecated, use WhereOr instead.
  412. func (d *SysMenuDao) Or(where interface{}, args ...interface{}) *SysMenuDao {
  413. return &SysMenuDao{M: d.M.Or(where, args...), Table: d.Table, TableAs: d.TableAs}
  414. }
  415. // GroupBy sets the "GROUP BY" statement for the model.
  416. func (d *SysMenuDao) GroupBy(groupBy string) *SysMenuDao {
  417. return &SysMenuDao{M: d.M.Group(groupBy), Table: d.Table, TableAs: d.TableAs}
  418. }
  419. // Order sets the "ORDER BY" statement for the model.
  420. func (d *SysMenuDao) Order(orderBy ...string) *SysMenuDao {
  421. return &SysMenuDao{M: d.M.Order(orderBy...), Table: d.Table, TableAs: d.TableAs}
  422. }
  423. // OrderAsc sets the "ORDER BY xxx ASC" statement for the model.
  424. func (d *SysMenuDao) OrderAsc(column string) *SysMenuDao {
  425. return &SysMenuDao{M: d.M.OrderAsc(column), Table: d.Table, TableAs: d.TableAs}
  426. }
  427. // OrderDesc sets the "ORDER BY xxx DESC" statement for the model.
  428. func (d *SysMenuDao) OrderDesc(column string) *SysMenuDao {
  429. return &SysMenuDao{M: d.M.OrderDesc(column), Table: d.Table, TableAs: d.TableAs}
  430. }
  431. // OrderRandom sets the "ORDER BY RANDOM()" statement for the model.
  432. func (d *SysMenuDao) OrderRandom() *SysMenuDao {
  433. return &SysMenuDao{M: d.M.OrderRandom(), Table: d.Table, TableAs: d.TableAs}
  434. }
  435. // OrderBy is alias of Model.Order.
  436. // See Model.Order.
  437. // Deprecated, use Order instead.
  438. func (d *SysMenuDao) OrderBy(orderBy string) *SysMenuDao {
  439. return &SysMenuDao{M: d.M.Order(orderBy), Table: d.Table, TableAs: d.TableAs}
  440. }
  441. // Limit sets the "LIMIT" statement for the model.
  442. // The parameter <limit> can be either one or two number, if passed two number is passed,
  443. // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
  444. // statement.
  445. func (d *SysMenuDao) Limit(limit ...int) *SysMenuDao {
  446. return &SysMenuDao{M: d.M.Limit(limit...), Table: d.Table, TableAs: d.TableAs}
  447. }
  448. // Offset sets the "OFFSET" statement for the model.
  449. // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
  450. func (d *SysMenuDao) Offset(offset int) *SysMenuDao {
  451. return &SysMenuDao{M: d.M.Offset(offset), Table: d.Table, TableAs: d.TableAs}
  452. }
  453. // Distinct forces the query to only return distinct results.
  454. func (d *SysMenuDao) Distinct() *SysMenuDao {
  455. return &SysMenuDao{M: d.M.Distinct(), Table: d.Table, TableAs: d.TableAs}
  456. }
  457. // Page sets the paging number for the model.
  458. // The parameter <page> is started from 1 for paging.
  459. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
  460. func (d *SysMenuDao) Page(page, limit int) *SysMenuDao {
  461. return &SysMenuDao{M: d.M.Page(page, limit), Table: d.Table, TableAs: d.TableAs}
  462. }
  463. // Batch sets the batch operation number for the model.
  464. func (d *SysMenuDao) Batch(batch int) *SysMenuDao {
  465. return &SysMenuDao{M: d.M.Batch(batch), Table: d.Table, TableAs: d.TableAs}
  466. }
  467. // Cache sets the cache feature for the model. It caches the result of the sql, which means
  468. // if there's another same sql request, it just reads and returns the result from cache, it
  469. // but not committed and executed into the database.
  470. //
  471. // If the parameter <duration> < 0, which means it clear the cache with given <name>.
  472. // If the parameter <duration> = 0, which means it never expires.
  473. // If the parameter <duration> > 0, which means it expires after <duration>.
  474. //
  475. // The optional parameter <name> is used to bind a name to the cache, which means you can later
  476. // control the cache like changing the <duration> or clearing the cache with specified <name>.
  477. //
  478. // Note that, the cache feature is disabled if the model is operating on a transaction.
  479. func (d *SysMenuDao) Cache(duration time.Duration, name ...string) *SysMenuDao {
  480. return &SysMenuDao{M: d.M.Cache(duration, name...), Table: d.Table, TableAs: d.TableAs}
  481. }
  482. // Data sets the operation data for the model.
  483. // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
  484. // Eg:
  485. // Data("uid=10000")
  486. // Data("uid", 10000)
  487. // Data(g.Map{"uid": 10000, "name":"john"})
  488. // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
  489. func (d *SysMenuDao) Data(data ...interface{}) *SysMenuDao {
  490. return &SysMenuDao{M: d.M.Data(data...), Table: d.Table, TableAs: d.TableAs}
  491. }
  492. // All does "SELECT FROM ..." statement for the model.
  493. // It retrieves the records from table and returns the result as []*model.SysMenu.
  494. // It returns nil if there's no record retrieved with the given conditions from table.
  495. //
  496. // The optional parameter <where> is the same as the parameter of M.Where function,
  497. // see M.Where.
  498. func (d *SysMenuDao) All(where ...interface{}) ([]*model.SysMenu, error) {
  499. all, err := d.M.All(where...)
  500. if err != nil {
  501. return nil, err
  502. }
  503. var entities []*model.SysMenu
  504. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  505. return nil, err
  506. }
  507. return entities, nil
  508. }
  509. // One retrieves one record from table and returns the result as *model.SysMenu.
  510. // It returns nil if there's no record retrieved with the given conditions from table.
  511. //
  512. // The optional parameter <where> is the same as the parameter of M.Where function,
  513. // see M.Where.
  514. func (d *SysMenuDao) One(where ...interface{}) (*model.SysMenu, error) {
  515. one, err := d.M.One(where...)
  516. if err != nil {
  517. return nil, err
  518. }
  519. var entity *model.SysMenu
  520. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  521. return nil, err
  522. }
  523. return entity, nil
  524. }
  525. // FindOne retrieves and returns a single Record by M.WherePri and M.One.
  526. // Also see M.WherePri and M.One.
  527. func (d *SysMenuDao) FindOne(where ...interface{}) (*model.SysMenu, error) {
  528. one, err := d.M.FindOne(where...)
  529. if err != nil {
  530. return nil, err
  531. }
  532. var entity *model.SysMenu
  533. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  534. return nil, err
  535. }
  536. return entity, nil
  537. }
  538. // FindAll retrieves and returns Result by by M.WherePri and M.All.
  539. // Also see M.WherePri and M.All.
  540. func (d *SysMenuDao) FindAll(where ...interface{}) ([]*model.SysMenu, error) {
  541. all, err := d.M.FindAll(where...)
  542. if err != nil {
  543. return nil, err
  544. }
  545. var entities []*model.SysMenu
  546. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  547. return nil, err
  548. }
  549. return entities, nil
  550. }
  551. // Struct retrieves one record from table and converts it into given struct.
  552. // The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
  553. // it can create the struct internally during converting.
  554. //
  555. // The optional parameter <where> is the same as the parameter of Model.Where function,
  556. // see Model.Where.
  557. //
  558. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  559. // from table and <pointer> is not nil.
  560. //
  561. // Eg:
  562. // user := new(User)
  563. // err := dao.User.Where("id", 1).Struct(user)
  564. //
  565. // user := (*User)(nil)
  566. // err := dao.User.Where("id", 1).Struct(&user)
  567. func (d *SysMenuDao) Struct(pointer interface{}, where ...interface{}) error {
  568. return d.M.Struct(pointer, where...)
  569. }
  570. // Structs retrieves records from table and converts them into given struct slice.
  571. // The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
  572. // slice internally during converting.
  573. //
  574. // The optional parameter <where> is the same as the parameter of Model.Where function,
  575. // see Model.Where.
  576. //
  577. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  578. // from table and <pointer> is not empty.
  579. //
  580. // Eg:
  581. // users := ([]User)(nil)
  582. // err := dao.User.Structs(&users)
  583. //
  584. // users := ([]*User)(nil)
  585. // err := dao.User.Structs(&users)
  586. func (d *SysMenuDao) Structs(pointer interface{}, where ...interface{}) error {
  587. return d.M.Structs(pointer, where...)
  588. }
  589. // Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
  590. // It calls function Struct if <pointer> is type of *struct/**struct.
  591. // It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
  592. //
  593. // The optional parameter <where> is the same as the parameter of Model.Where function,
  594. // see Model.Where.
  595. //
  596. // Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
  597. //
  598. // Eg:
  599. // user := new(User)
  600. // err := dao.User.Where("id", 1).Scan(user)
  601. //
  602. // user := (*User)(nil)
  603. // err := dao.User.Where("id", 1).Scan(&user)
  604. //
  605. // users := ([]User)(nil)
  606. // err := dao.User.Scan(&users)
  607. //
  608. // users := ([]*User)(nil)
  609. // err := dao.User.Scan(&users)
  610. func (d *SysMenuDao) Scan(pointer interface{}, where ...interface{}) error {
  611. return d.M.Scan(pointer, where...)
  612. }
  613. // Chunk iterates the table with given size and callback function.
  614. func (d *SysMenuDao) Chunk(limit int, callback func(entities []*model.SysMenu, err error) bool) {
  615. d.M.Chunk(limit, func(result gdb.Result, err error) bool {
  616. var entities []*model.SysMenu
  617. err = result.Structs(&entities)
  618. if err == sql.ErrNoRows {
  619. return false
  620. }
  621. return callback(entities, err)
  622. })
  623. }
  624. // LockUpdate sets the lock for update for current operation.
  625. func (d *SysMenuDao) LockUpdate() *SysMenuDao {
  626. return &SysMenuDao{M: d.M.LockUpdate(), Table: d.Table, TableAs: d.TableAs}
  627. }
  628. // LockShared sets the lock in share mode for current operation.
  629. func (d *SysMenuDao) LockShared() *SysMenuDao {
  630. return &SysMenuDao{M: d.M.LockShared(), Table: d.Table, TableAs: d.TableAs}
  631. }
  632. // Unscoped enables/disables the soft deleting feature.
  633. func (d *SysMenuDao) Unscoped() *SysMenuDao {
  634. return &SysMenuDao{M: d.M.Unscoped(), Table: d.Table, TableAs: d.TableAs}
  635. }
  636. // DataScope enables the DataScope feature.
  637. func (d *SysMenuDao) DataScope(ctx context.Context, userCol ...string) *SysMenuDao {
  638. cs := ctx.Value("contextService")
  639. dataScope := gconv.Map(cs)["dataScope"].(g.Map)
  640. if dataScope != nil {
  641. userIds, ok := dataScope["userIds"]
  642. delete(dataScope, "userIds")
  643. var columns []string
  644. var values []interface{}
  645. if ok && userIds != "-1" {
  646. column := "created_by"
  647. if len(userCol) == 1 {
  648. column = userCol[0]
  649. }
  650. dataScope[column] = userIds
  651. if d.Table == "sys_user" {
  652. dataScope["id"] = userIds
  653. }
  654. }
  655. tableAs := d.TableAs
  656. if d.TableAs != "" {
  657. tableAs += "."
  658. }
  659. for k, v := range dataScope {
  660. if ok, _ := d.M.HasField(k); ok {
  661. columns = append(columns, tableAs+k+" IN (?) ")
  662. values = append(values, v)
  663. }
  664. }
  665. whereSql := strings.Join(columns, " OR ")
  666. return &SysMenuDao{M: d.M.Where(whereSql, values).Ctx(ctx), Table: d.Table, TableAs: d.TableAs}
  667. }
  668. return d
  669. }