sys_role.go 30 KB

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