role.gen.go 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. // Code generated by gorm.io/gen. DO NOT EDIT.
  2. // Code generated by gorm.io/gen. DO NOT EDIT.
  3. // Code generated by gorm.io/gen. DO NOT EDIT.
  4. package query
  5. import (
  6. "context"
  7. "gorm.io/gorm"
  8. "gorm.io/gorm/clause"
  9. "gorm.io/gorm/schema"
  10. "gorm.io/gen"
  11. "gorm.io/gen/field"
  12. "gorm.io/plugin/dbresolver"
  13. "gadmin/internal/gorm/model"
  14. )
  15. func newRole(db *gorm.DB, opts ...gen.DOOption) role {
  16. _role := role{}
  17. _role.roleDo.UseDB(db, opts...)
  18. _role.roleDo.UseModel(&model.Role{})
  19. tableName := _role.roleDo.TableName()
  20. _role.ALL = field.NewAsterisk(tableName)
  21. _role.ID = field.NewInt64(tableName, "id")
  22. _role.Name = field.NewString(tableName, "name")
  23. _role.Key = field.NewString(tableName, "key")
  24. _role.DataScope = field.NewBool(tableName, "data_scope")
  25. _role.MenuCheckStrictly = field.NewBool(tableName, "menu_check_strictly")
  26. _role.DeptCheckStrictly = field.NewBool(tableName, "dept_check_strictly")
  27. _role.Remark = field.NewString(tableName, "remark")
  28. _role.Sort = field.NewInt32(tableName, "sort")
  29. _role.Status = field.NewString(tableName, "status")
  30. _role.CreatedAt = field.NewTime(tableName, "created_at")
  31. _role.UpdatedAt = field.NewTime(tableName, "updated_at")
  32. _role.fillFieldMap()
  33. return _role
  34. }
  35. type role struct {
  36. roleDo
  37. ALL field.Asterisk
  38. ID field.Int64 // 角色ID
  39. Name field.String // 角色名称
  40. Key field.String // 角色权限字符串
  41. DataScope field.Bool // 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)
  42. MenuCheckStrictly field.Bool // 菜单树选择项是否关联显示
  43. DeptCheckStrictly field.Bool // 部门树选择项是否关联显示
  44. Remark field.String // 备注
  45. Sort field.Int32 // 排序
  46. Status field.String // 角色状态
  47. CreatedAt field.Time // 创建时间
  48. UpdatedAt field.Time // 更新时间
  49. fieldMap map[string]field.Expr
  50. }
  51. func (r role) Table(newTableName string) *role {
  52. r.roleDo.UseTable(newTableName)
  53. return r.updateTableName(newTableName)
  54. }
  55. func (r role) As(alias string) *role {
  56. r.roleDo.DO = *(r.roleDo.As(alias).(*gen.DO))
  57. return r.updateTableName(alias)
  58. }
  59. func (r *role) updateTableName(table string) *role {
  60. r.ALL = field.NewAsterisk(table)
  61. r.ID = field.NewInt64(table, "id")
  62. r.Name = field.NewString(table, "name")
  63. r.Key = field.NewString(table, "key")
  64. r.DataScope = field.NewBool(table, "data_scope")
  65. r.MenuCheckStrictly = field.NewBool(table, "menu_check_strictly")
  66. r.DeptCheckStrictly = field.NewBool(table, "dept_check_strictly")
  67. r.Remark = field.NewString(table, "remark")
  68. r.Sort = field.NewInt32(table, "sort")
  69. r.Status = field.NewString(table, "status")
  70. r.CreatedAt = field.NewTime(table, "created_at")
  71. r.UpdatedAt = field.NewTime(table, "updated_at")
  72. r.fillFieldMap()
  73. return r
  74. }
  75. func (r *role) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
  76. _f, ok := r.fieldMap[fieldName]
  77. if !ok || _f == nil {
  78. return nil, false
  79. }
  80. _oe, ok := _f.(field.OrderExpr)
  81. return _oe, ok
  82. }
  83. func (r *role) fillFieldMap() {
  84. r.fieldMap = make(map[string]field.Expr, 11)
  85. r.fieldMap["id"] = r.ID
  86. r.fieldMap["name"] = r.Name
  87. r.fieldMap["key"] = r.Key
  88. r.fieldMap["data_scope"] = r.DataScope
  89. r.fieldMap["menu_check_strictly"] = r.MenuCheckStrictly
  90. r.fieldMap["dept_check_strictly"] = r.DeptCheckStrictly
  91. r.fieldMap["remark"] = r.Remark
  92. r.fieldMap["sort"] = r.Sort
  93. r.fieldMap["status"] = r.Status
  94. r.fieldMap["created_at"] = r.CreatedAt
  95. r.fieldMap["updated_at"] = r.UpdatedAt
  96. }
  97. func (r role) clone(db *gorm.DB) role {
  98. r.roleDo.ReplaceConnPool(db.Statement.ConnPool)
  99. return r
  100. }
  101. func (r role) replaceDB(db *gorm.DB) role {
  102. r.roleDo.ReplaceDB(db)
  103. return r
  104. }
  105. type roleDo struct{ gen.DO }
  106. func (r roleDo) Debug() *roleDo {
  107. return r.withDO(r.DO.Debug())
  108. }
  109. func (r roleDo) WithContext(ctx context.Context) *roleDo {
  110. return r.withDO(r.DO.WithContext(ctx))
  111. }
  112. func (r roleDo) ReadDB() *roleDo {
  113. return r.Clauses(dbresolver.Read)
  114. }
  115. func (r roleDo) WriteDB() *roleDo {
  116. return r.Clauses(dbresolver.Write)
  117. }
  118. func (r roleDo) Session(config *gorm.Session) *roleDo {
  119. return r.withDO(r.DO.Session(config))
  120. }
  121. func (r roleDo) Clauses(conds ...clause.Expression) *roleDo {
  122. return r.withDO(r.DO.Clauses(conds...))
  123. }
  124. func (r roleDo) Returning(value interface{}, columns ...string) *roleDo {
  125. return r.withDO(r.DO.Returning(value, columns...))
  126. }
  127. func (r roleDo) Not(conds ...gen.Condition) *roleDo {
  128. return r.withDO(r.DO.Not(conds...))
  129. }
  130. func (r roleDo) Or(conds ...gen.Condition) *roleDo {
  131. return r.withDO(r.DO.Or(conds...))
  132. }
  133. func (r roleDo) Select(conds ...field.Expr) *roleDo {
  134. return r.withDO(r.DO.Select(conds...))
  135. }
  136. func (r roleDo) Where(conds ...gen.Condition) *roleDo {
  137. return r.withDO(r.DO.Where(conds...))
  138. }
  139. func (r roleDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) *roleDo {
  140. return r.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
  141. }
  142. func (r roleDo) Order(conds ...field.Expr) *roleDo {
  143. return r.withDO(r.DO.Order(conds...))
  144. }
  145. func (r roleDo) Distinct(cols ...field.Expr) *roleDo {
  146. return r.withDO(r.DO.Distinct(cols...))
  147. }
  148. func (r roleDo) Omit(cols ...field.Expr) *roleDo {
  149. return r.withDO(r.DO.Omit(cols...))
  150. }
  151. func (r roleDo) Join(table schema.Tabler, on ...field.Expr) *roleDo {
  152. return r.withDO(r.DO.Join(table, on...))
  153. }
  154. func (r roleDo) LeftJoin(table schema.Tabler, on ...field.Expr) *roleDo {
  155. return r.withDO(r.DO.LeftJoin(table, on...))
  156. }
  157. func (r roleDo) RightJoin(table schema.Tabler, on ...field.Expr) *roleDo {
  158. return r.withDO(r.DO.RightJoin(table, on...))
  159. }
  160. func (r roleDo) Group(cols ...field.Expr) *roleDo {
  161. return r.withDO(r.DO.Group(cols...))
  162. }
  163. func (r roleDo) Having(conds ...gen.Condition) *roleDo {
  164. return r.withDO(r.DO.Having(conds...))
  165. }
  166. func (r roleDo) Limit(limit int) *roleDo {
  167. return r.withDO(r.DO.Limit(limit))
  168. }
  169. func (r roleDo) Offset(offset int) *roleDo {
  170. return r.withDO(r.DO.Offset(offset))
  171. }
  172. func (r roleDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *roleDo {
  173. return r.withDO(r.DO.Scopes(funcs...))
  174. }
  175. func (r roleDo) Unscoped() *roleDo {
  176. return r.withDO(r.DO.Unscoped())
  177. }
  178. func (r roleDo) Create(values ...*model.Role) error {
  179. if len(values) == 0 {
  180. return nil
  181. }
  182. return r.DO.Create(values)
  183. }
  184. func (r roleDo) CreateInBatches(values []*model.Role, batchSize int) error {
  185. return r.DO.CreateInBatches(values, batchSize)
  186. }
  187. // Save : !!! underlying implementation is different with GORM
  188. // The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
  189. func (r roleDo) Save(values ...*model.Role) error {
  190. if len(values) == 0 {
  191. return nil
  192. }
  193. return r.DO.Save(values)
  194. }
  195. func (r roleDo) First() (*model.Role, error) {
  196. if result, err := r.DO.First(); err != nil {
  197. return nil, err
  198. } else {
  199. return result.(*model.Role), nil
  200. }
  201. }
  202. func (r roleDo) Take() (*model.Role, error) {
  203. if result, err := r.DO.Take(); err != nil {
  204. return nil, err
  205. } else {
  206. return result.(*model.Role), nil
  207. }
  208. }
  209. func (r roleDo) Last() (*model.Role, error) {
  210. if result, err := r.DO.Last(); err != nil {
  211. return nil, err
  212. } else {
  213. return result.(*model.Role), nil
  214. }
  215. }
  216. func (r roleDo) Find() ([]*model.Role, error) {
  217. result, err := r.DO.Find()
  218. return result.([]*model.Role), err
  219. }
  220. func (r roleDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Role, err error) {
  221. buf := make([]*model.Role, 0, batchSize)
  222. err = r.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
  223. defer func() { results = append(results, buf...) }()
  224. return fc(tx, batch)
  225. })
  226. return results, err
  227. }
  228. func (r roleDo) FindInBatches(result *[]*model.Role, batchSize int, fc func(tx gen.Dao, batch int) error) error {
  229. return r.DO.FindInBatches(result, batchSize, fc)
  230. }
  231. func (r roleDo) Attrs(attrs ...field.AssignExpr) *roleDo {
  232. return r.withDO(r.DO.Attrs(attrs...))
  233. }
  234. func (r roleDo) Assign(attrs ...field.AssignExpr) *roleDo {
  235. return r.withDO(r.DO.Assign(attrs...))
  236. }
  237. func (r roleDo) Joins(fields ...field.RelationField) *roleDo {
  238. for _, _f := range fields {
  239. r = *r.withDO(r.DO.Joins(_f))
  240. }
  241. return &r
  242. }
  243. func (r roleDo) Preload(fields ...field.RelationField) *roleDo {
  244. for _, _f := range fields {
  245. r = *r.withDO(r.DO.Preload(_f))
  246. }
  247. return &r
  248. }
  249. func (r roleDo) FirstOrInit() (*model.Role, error) {
  250. if result, err := r.DO.FirstOrInit(); err != nil {
  251. return nil, err
  252. } else {
  253. return result.(*model.Role), nil
  254. }
  255. }
  256. func (r roleDo) FirstOrCreate() (*model.Role, error) {
  257. if result, err := r.DO.FirstOrCreate(); err != nil {
  258. return nil, err
  259. } else {
  260. return result.(*model.Role), nil
  261. }
  262. }
  263. func (r roleDo) FindByPage(offset int, limit int) (result []*model.Role, count int64, err error) {
  264. result, err = r.Offset(offset).Limit(limit).Find()
  265. if err != nil {
  266. return
  267. }
  268. if size := len(result); 0 < limit && 0 < size && size < limit {
  269. count = int64(size + offset)
  270. return
  271. }
  272. count, err = r.Offset(-1).Limit(-1).Count()
  273. return
  274. }
  275. func (r roleDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
  276. count, err = r.Count()
  277. if err != nil {
  278. return
  279. }
  280. err = r.Offset(offset).Limit(limit).Scan(result)
  281. return
  282. }
  283. func (r roleDo) Scan(result interface{}) (err error) {
  284. return r.DO.Scan(result)
  285. }
  286. func (r roleDo) Delete(models ...*model.Role) (result gen.ResultInfo, err error) {
  287. return r.DO.Delete(models)
  288. }
  289. func (r *roleDo) withDO(do gen.Dao) *roleDo {
  290. r.DO = *do.(*gen.DO)
  291. return r
  292. }