auth_rule_model.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. // ==========================================================================
  2. // This is auto-generated by gf cli tool. You may not really want to edit it.
  3. // ==========================================================================
  4. package auth_rule
  5. import (
  6. "database/sql"
  7. "github.com/gogf/gf/database/gdb"
  8. "github.com/gogf/gf/frame/g"
  9. "github.com/gogf/gf/frame/gmvc"
  10. "time"
  11. )
  12. // arModel is a active record design model for table auth_rule operations.
  13. type arModel struct {
  14. gmvc.M
  15. }
  16. var (
  17. // Table is the table name of auth_rule.
  18. Table = "auth_rule"
  19. // Model is the model object of auth_rule.
  20. Model = &arModel{g.DB("default").Table(Table).Safe()}
  21. // Columns defines and stores column names for table auth_rule.
  22. Columns = struct {
  23. Id string //
  24. Pid string // 父ID
  25. Name string // 规则名称
  26. Title string // 规则名称
  27. Icon string // 图标
  28. Condition string // 条件
  29. Remark string // 备注
  30. MenuType string // 类型 0目录 1菜单 2按钮
  31. Createtime string // 创建时间
  32. Updatetime string // 更新时间
  33. Weigh string // 权重
  34. Status string // 状态
  35. AlwaysShow string // 显示状态
  36. Path string // 路由地址
  37. Component string // 组件路径
  38. IsFrame string // 是否外链 1是 0否
  39. ModuleType string // 所属模块
  40. ModelId string // 模型ID
  41. }{
  42. Id: "id",
  43. Pid: "pid",
  44. Name: "name",
  45. Title: "title",
  46. Icon: "icon",
  47. Condition: "condition",
  48. Remark: "remark",
  49. MenuType: "menu_type",
  50. Createtime: "createtime",
  51. Updatetime: "updatetime",
  52. Weigh: "weigh",
  53. Status: "status",
  54. AlwaysShow: "always_show",
  55. Path: "path",
  56. Component: "component",
  57. IsFrame: "is_frame",
  58. ModuleType: "module_type",
  59. ModelId: "model_id",
  60. }
  61. )
  62. // FindOne is a convenience method for Model.FindOne.
  63. // See Model.FindOne.
  64. func FindOne(where ...interface{}) (*Entity, error) {
  65. return Model.FindOne(where...)
  66. }
  67. // FindAll is a convenience method for Model.FindAll.
  68. // See Model.FindAll.
  69. func FindAll(where ...interface{}) ([]*Entity, error) {
  70. return Model.FindAll(where...)
  71. }
  72. // FindValue is a convenience method for Model.FindValue.
  73. // See Model.FindValue.
  74. func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
  75. return Model.FindValue(fieldsAndWhere...)
  76. }
  77. // FindArray is a convenience method for Model.FindArray.
  78. // See Model.FindArray.
  79. func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) {
  80. return Model.FindArray(fieldsAndWhere...)
  81. }
  82. // FindCount is a convenience method for Model.FindCount.
  83. // See Model.FindCount.
  84. func FindCount(where ...interface{}) (int, error) {
  85. return Model.FindCount(where...)
  86. }
  87. // Insert is a convenience method for Model.Insert.
  88. func Insert(data ...interface{}) (result sql.Result, err error) {
  89. return Model.Insert(data...)
  90. }
  91. // InsertIgnore is a convenience method for Model.InsertIgnore.
  92. func InsertIgnore(data ...interface{}) (result sql.Result, err error) {
  93. return Model.InsertIgnore(data...)
  94. }
  95. // Replace is a convenience method for Model.Replace.
  96. func Replace(data ...interface{}) (result sql.Result, err error) {
  97. return Model.Replace(data...)
  98. }
  99. // Save is a convenience method for Model.Save.
  100. func Save(data ...interface{}) (result sql.Result, err error) {
  101. return Model.Save(data...)
  102. }
  103. // Update is a convenience method for Model.Update.
  104. func Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
  105. return Model.Update(dataAndWhere...)
  106. }
  107. // Delete is a convenience method for Model.Delete.
  108. func Delete(where ...interface{}) (result sql.Result, err error) {
  109. return Model.Delete(where...)
  110. }
  111. // As sets an alias name for current table.
  112. func (m *arModel) As(as string) *arModel {
  113. return &arModel{m.M.As(as)}
  114. }
  115. // TX sets the transaction for current operation.
  116. func (m *arModel) TX(tx *gdb.TX) *arModel {
  117. return &arModel{m.M.TX(tx)}
  118. }
  119. // Master marks the following operation on master node.
  120. func (m *arModel) Master() *arModel {
  121. return &arModel{m.M.Master()}
  122. }
  123. // Slave marks the following operation on slave node.
  124. // Note that it makes sense only if there's any slave node configured.
  125. func (m *arModel) Slave() *arModel {
  126. return &arModel{m.M.Slave()}
  127. }
  128. // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
  129. // The parameter <table> can be joined table and its joined condition,
  130. // and also with its alias name, like:
  131. // Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
  132. // Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
  133. func (m *arModel) LeftJoin(table ...string) *arModel {
  134. return &arModel{m.M.LeftJoin(table...)}
  135. }
  136. // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
  137. // The parameter <table> can be joined table and its joined condition,
  138. // and also with its alias name, like:
  139. // Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
  140. // Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
  141. func (m *arModel) RightJoin(table ...string) *arModel {
  142. return &arModel{m.M.RightJoin(table...)}
  143. }
  144. // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
  145. // The parameter <table> can be joined table and its joined condition,
  146. // and also with its alias name, like:
  147. // Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
  148. // Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
  149. func (m *arModel) InnerJoin(table ...string) *arModel {
  150. return &arModel{m.M.InnerJoin(table...)}
  151. }
  152. // Fields sets the operation fields of the model, multiple fields joined using char ','.
  153. func (m *arModel) Fields(fields string) *arModel {
  154. return &arModel{m.M.Fields(fields)}
  155. }
  156. // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
  157. func (m *arModel) FieldsEx(fields string) *arModel {
  158. return &arModel{m.M.FieldsEx(fields)}
  159. }
  160. // Option sets the extra operation option for the model.
  161. func (m *arModel) Option(option int) *arModel {
  162. return &arModel{m.M.Option(option)}
  163. }
  164. // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
  165. // the data and where attributes for empty values.
  166. func (m *arModel) OmitEmpty() *arModel {
  167. return &arModel{m.M.OmitEmpty()}
  168. }
  169. // Filter marks filtering the fields which does not exist in the fields of the operated table.
  170. func (m *arModel) Filter() *arModel {
  171. return &arModel{m.M.Filter()}
  172. }
  173. // Where sets the condition statement for the model. The parameter <where> can be type of
  174. // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
  175. // multiple conditions will be joined into where statement using "AND".
  176. // Eg:
  177. // Where("uid=10000")
  178. // Where("uid", 10000)
  179. // Where("money>? AND name like ?", 99999, "vip_%")
  180. // Where("uid", 1).Where("name", "john")
  181. // Where("status IN (?)", g.Slice{1,2,3})
  182. // Where("age IN(?,?)", 18, 50)
  183. // Where(User{ Id : 1, UserName : "john"})
  184. func (m *arModel) Where(where interface{}, args ...interface{}) *arModel {
  185. return &arModel{m.M.Where(where, args...)}
  186. }
  187. // And adds "AND" condition to the where statement.
  188. func (m *arModel) And(where interface{}, args ...interface{}) *arModel {
  189. return &arModel{m.M.And(where, args...)}
  190. }
  191. // Or adds "OR" condition to the where statement.
  192. func (m *arModel) Or(where interface{}, args ...interface{}) *arModel {
  193. return &arModel{m.M.Or(where, args...)}
  194. }
  195. // Group sets the "GROUP BY" statement for the model.
  196. func (m *arModel) Group(groupBy string) *arModel {
  197. return &arModel{m.M.Group(groupBy)}
  198. }
  199. // Order sets the "ORDER BY" statement for the model.
  200. func (m *arModel) Order(orderBy ...string) *arModel {
  201. return &arModel{m.M.Order(orderBy...)}
  202. }
  203. // Limit sets the "LIMIT" statement for the model.
  204. // The parameter <limit> can be either one or two number, if passed two number is passed,
  205. // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
  206. // statement.
  207. func (m *arModel) Limit(limit ...int) *arModel {
  208. return &arModel{m.M.Limit(limit...)}
  209. }
  210. // Offset sets the "OFFSET" statement for the model.
  211. // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
  212. func (m *arModel) Offset(offset int) *arModel {
  213. return &arModel{m.M.Offset(offset)}
  214. }
  215. // Page sets the paging number for the model.
  216. // The parameter <page> is started from 1 for paging.
  217. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
  218. func (m *arModel) Page(page, limit int) *arModel {
  219. return &arModel{m.M.Page(page, limit)}
  220. }
  221. // Batch sets the batch operation number for the model.
  222. func (m *arModel) Batch(batch int) *arModel {
  223. return &arModel{m.M.Batch(batch)}
  224. }
  225. // Cache sets the cache feature for the model. It caches the result of the sql, which means
  226. // if there's another same sql request, it just reads and returns the result from cache, it
  227. // but not committed and executed into the database.
  228. //
  229. // If the parameter <duration> < 0, which means it clear the cache with given <name>.
  230. // If the parameter <duration> = 0, which means it never expires.
  231. // If the parameter <duration> > 0, which means it expires after <duration>.
  232. //
  233. // The optional parameter <name> is used to bind a name to the cache, which means you can later
  234. // control the cache like changing the <duration> or clearing the cache with specified <name>.
  235. //
  236. // Note that, the cache feature is disabled if the model is operating on a transaction.
  237. func (m *arModel) Cache(duration time.Duration, name ...string) *arModel {
  238. return &arModel{m.M.Cache(duration, name...)}
  239. }
  240. // Data sets the operation data for the model.
  241. // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
  242. // Eg:
  243. // Data("uid=10000")
  244. // Data("uid", 10000)
  245. // Data(g.Map{"uid": 10000, "name":"john"})
  246. // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
  247. func (m *arModel) Data(data ...interface{}) *arModel {
  248. return &arModel{m.M.Data(data...)}
  249. }
  250. // All does "SELECT FROM ..." statement for the model.
  251. // It retrieves the records from table and returns the result as []*Entity.
  252. // It returns nil if there's no record retrieved with the given conditions from table.
  253. //
  254. // The optional parameter <where> is the same as the parameter of Model.Where function,
  255. // see Model.Where.
  256. func (m *arModel) All(where ...interface{}) ([]*Entity, error) {
  257. all, err := m.M.All(where...)
  258. if err != nil {
  259. return nil, err
  260. }
  261. var entities []*Entity
  262. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  263. return nil, err
  264. }
  265. return entities, nil
  266. }
  267. // One retrieves one record from table and returns the result as *Entity.
  268. // It returns nil if there's no record retrieved with the given conditions from table.
  269. //
  270. // The optional parameter <where> is the same as the parameter of Model.Where function,
  271. // see Model.Where.
  272. func (m *arModel) One(where ...interface{}) (*Entity, error) {
  273. one, err := m.M.One(where...)
  274. if err != nil {
  275. return nil, err
  276. }
  277. var entity *Entity
  278. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  279. return nil, err
  280. }
  281. return entity, nil
  282. }
  283. // FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
  284. // Also see Model.WherePri and Model.One.
  285. func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
  286. one, err := m.M.FindOne(where...)
  287. if err != nil {
  288. return nil, err
  289. }
  290. var entity *Entity
  291. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  292. return nil, err
  293. }
  294. return entity, nil
  295. }
  296. // FindAll retrieves and returns Result by by Model.WherePri and Model.All.
  297. // Also see Model.WherePri and Model.All.
  298. func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
  299. all, err := m.M.FindAll(where...)
  300. if err != nil {
  301. return nil, err
  302. }
  303. var entities []*Entity
  304. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  305. return nil, err
  306. }
  307. return entities, nil
  308. }
  309. // Chunk iterates the table with given size and callback function.
  310. func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) {
  311. m.M.Chunk(limit, func(result gdb.Result, err error) bool {
  312. var entities []*Entity
  313. err = result.Structs(&entities)
  314. if err == sql.ErrNoRows {
  315. return false
  316. }
  317. return callback(entities, err)
  318. })
  319. }
  320. // LockUpdate sets the lock for update for current operation.
  321. func (m *arModel) LockUpdate() *arModel {
  322. return &arModel{m.M.LockUpdate()}
  323. }
  324. // LockShared sets the lock in share mode for current operation.
  325. func (m *arModel) LockShared() *arModel {
  326. return &arModel{m.M.LockShared()}
  327. }
  328. // Unscoped enables/disables the soft deleting feature.
  329. func (m *arModel) Unscoped() *arModel {
  330. return &arModel{m.M.Unscoped()}
  331. }