casbin_rule.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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. "dashoo.cn/micro/app/common/model"
  8. "database/sql"
  9. "github.com/gogf/gf/database/gdb"
  10. "github.com/gogf/gf/frame/g"
  11. "github.com/gogf/gf/frame/gmvc"
  12. "time"
  13. )
  14. // CasbinRuleDao is the manager for logic model data accessing
  15. // and custom defined data operations functions management.
  16. type CasbinRuleDao struct {
  17. gmvc.M
  18. DB gdb.DB
  19. Table string
  20. Columns casbinRuleColumns
  21. }
  22. // CasbinRuleColumns defines and stores column names for table casbin_rule.
  23. type casbinRuleColumns struct {
  24. Ptype string //
  25. V0 string //
  26. V1 string //
  27. V2 string //
  28. V3 string //
  29. V4 string //
  30. V5 string //
  31. }
  32. var (
  33. // CasbinRule is globally public accessible object for table casbin_rule operations.
  34. CasbinRule = CasbinRuleDao{
  35. M: g.DB("default").Model("casbin_rule").Safe(),
  36. DB: g.DB("default"),
  37. Table: "casbin_rule",
  38. Columns: casbinRuleColumns{
  39. Ptype: "ptype",
  40. V0: "v0",
  41. V1: "v1",
  42. V2: "v2",
  43. V3: "v3",
  44. V4: "v4",
  45. V5: "v5",
  46. },
  47. }
  48. )
  49. // Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
  50. // of current DB object and with given context in it.
  51. // Note that this returned DB object can be used only once, so do not assign it to
  52. // a global or package variable for long using.
  53. func (d *CasbinRuleDao) Ctx(ctx context.Context) *CasbinRuleDao {
  54. return &CasbinRuleDao{M: d.M.Ctx(ctx)}
  55. }
  56. // As sets an alias name for current table.
  57. func (d *CasbinRuleDao) As(as string) *CasbinRuleDao {
  58. return &CasbinRuleDao{M: d.M.As(as)}
  59. }
  60. // TX sets the transaction for current operation.
  61. func (d *CasbinRuleDao) TX(tx *gdb.TX) *CasbinRuleDao {
  62. return &CasbinRuleDao{M: d.M.TX(tx)}
  63. }
  64. // Master marks the following operation on master node.
  65. func (d *CasbinRuleDao) Master() *CasbinRuleDao {
  66. return &CasbinRuleDao{M: d.M.Master()}
  67. }
  68. // Slave marks the following operation on slave node.
  69. // Note that it makes sense only if there's any slave node configured.
  70. func (d *CasbinRuleDao) Slave() *CasbinRuleDao {
  71. return &CasbinRuleDao{M: d.M.Slave()}
  72. }
  73. // Args sets custom arguments for model operation.
  74. func (d *CasbinRuleDao) Args(args ...interface{}) *CasbinRuleDao {
  75. return &CasbinRuleDao{M: d.M.Args(args...)}
  76. }
  77. // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
  78. // The parameter <table> can be joined table and its joined condition,
  79. // and also with its alias name, like:
  80. // Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
  81. // Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
  82. func (d *CasbinRuleDao) LeftJoin(table ...string) *CasbinRuleDao {
  83. return &CasbinRuleDao{M: d.M.LeftJoin(table...)}
  84. }
  85. // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
  86. // The parameter <table> can be joined table and its joined condition,
  87. // and also with its alias name, like:
  88. // Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
  89. // Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
  90. func (d *CasbinRuleDao) RightJoin(table ...string) *CasbinRuleDao {
  91. return &CasbinRuleDao{M: d.M.RightJoin(table...)}
  92. }
  93. // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
  94. // The parameter <table> can be joined table and its joined condition,
  95. // and also with its alias name, like:
  96. // Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
  97. // Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
  98. func (d *CasbinRuleDao) InnerJoin(table ...string) *CasbinRuleDao {
  99. return &CasbinRuleDao{M: d.M.InnerJoin(table...)}
  100. }
  101. // Fields sets the operation fields of the model, multiple fields joined using char ','.
  102. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  103. func (d *CasbinRuleDao) Fields(fieldNamesOrMapStruct ...interface{}) *CasbinRuleDao {
  104. return &CasbinRuleDao{M: d.M.Fields(fieldNamesOrMapStruct...)}
  105. }
  106. // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
  107. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  108. func (d *CasbinRuleDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *CasbinRuleDao {
  109. return &CasbinRuleDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...)}
  110. }
  111. // Option sets the extra operation option for the model.
  112. func (d *CasbinRuleDao) Option(option int) *CasbinRuleDao {
  113. return &CasbinRuleDao{M: d.M.Option(option)}
  114. }
  115. // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
  116. // the data and where attributes for empty values.
  117. func (d *CasbinRuleDao) OmitEmpty() *CasbinRuleDao {
  118. return &CasbinRuleDao{M: d.M.OmitEmpty()}
  119. }
  120. // Filter marks filtering the fields which does not exist in the fields of the operated table.
  121. func (d *CasbinRuleDao) Filter() *CasbinRuleDao {
  122. return &CasbinRuleDao{M: d.M.Filter()}
  123. }
  124. // Where sets the condition statement for the model. The parameter <where> can be type of
  125. // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
  126. // multiple conditions will be joined into where statement using "AND".
  127. // Eg:
  128. // Where("uid=10000")
  129. // Where("uid", 10000)
  130. // Where("money>? AND name like ?", 99999, "vip_%")
  131. // Where("uid", 1).Where("name", "john")
  132. // Where("status IN (?)", g.Slice{1,2,3})
  133. // Where("age IN(?,?)", 18, 50)
  134. // Where(User{ Id : 1, UserName : "john"})
  135. func (d *CasbinRuleDao) Where(where interface{}, args ...interface{}) *CasbinRuleDao {
  136. return &CasbinRuleDao{M: d.M.Where(where, args...)}
  137. }
  138. // WherePri does the same logic as M.Where except that if the parameter <where>
  139. // is a single condition like int/string/float/slice, it treats the condition as the primary
  140. // key value. That is, if primary key is "id" and given <where> parameter as "123", the
  141. // WherePri function treats the condition as "id=123", but M.Where treats the condition
  142. // as string "123".
  143. func (d *CasbinRuleDao) WherePri(where interface{}, args ...interface{}) *CasbinRuleDao {
  144. return &CasbinRuleDao{M: d.M.WherePri(where, args...)}
  145. }
  146. // And adds "AND" condition to the where statement.
  147. func (d *CasbinRuleDao) And(where interface{}, args ...interface{}) *CasbinRuleDao {
  148. return &CasbinRuleDao{M: d.M.And(where, args...)}
  149. }
  150. // Or adds "OR" condition to the where statement.
  151. func (d *CasbinRuleDao) Or(where interface{}, args ...interface{}) *CasbinRuleDao {
  152. return &CasbinRuleDao{M: d.M.Or(where, args...)}
  153. }
  154. // Group sets the "GROUP BY" statement for the model.
  155. func (d *CasbinRuleDao) Group(groupBy string) *CasbinRuleDao {
  156. return &CasbinRuleDao{M: d.M.Group(groupBy)}
  157. }
  158. // Order sets the "ORDER BY" statement for the model.
  159. func (d *CasbinRuleDao) Order(orderBy ...string) *CasbinRuleDao {
  160. return &CasbinRuleDao{M: d.M.Order(orderBy...)}
  161. }
  162. // Limit sets the "LIMIT" statement for the model.
  163. // The parameter <limit> can be either one or two number, if passed two number is passed,
  164. // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
  165. // statement.
  166. func (d *CasbinRuleDao) Limit(limit ...int) *CasbinRuleDao {
  167. return &CasbinRuleDao{M: d.M.Limit(limit...)}
  168. }
  169. // Offset sets the "OFFSET" statement for the model.
  170. // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
  171. func (d *CasbinRuleDao) Offset(offset int) *CasbinRuleDao {
  172. return &CasbinRuleDao{M: d.M.Offset(offset)}
  173. }
  174. // Page sets the paging number for the model.
  175. // The parameter <page> is started from 1 for paging.
  176. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
  177. func (d *CasbinRuleDao) Page(page, limit int) *CasbinRuleDao {
  178. return &CasbinRuleDao{M: d.M.Page(page, limit)}
  179. }
  180. // Batch sets the batch operation number for the model.
  181. func (d *CasbinRuleDao) Batch(batch int) *CasbinRuleDao {
  182. return &CasbinRuleDao{M: d.M.Batch(batch)}
  183. }
  184. // Cache sets the cache feature for the model. It caches the result of the sql, which means
  185. // if there's another same sql request, it just reads and returns the result from cache, it
  186. // but not committed and executed into the database.
  187. //
  188. // If the parameter <duration> < 0, which means it clear the cache with given <name>.
  189. // If the parameter <duration> = 0, which means it never expires.
  190. // If the parameter <duration> > 0, which means it expires after <duration>.
  191. //
  192. // The optional parameter <name> is used to bind a name to the cache, which means you can later
  193. // control the cache like changing the <duration> or clearing the cache with specified <name>.
  194. //
  195. // Note that, the cache feature is disabled if the model is operating on a transaction.
  196. func (d *CasbinRuleDao) Cache(duration time.Duration, name ...string) *CasbinRuleDao {
  197. return &CasbinRuleDao{M: d.M.Cache(duration, name...)}
  198. }
  199. // Data sets the operation data for the model.
  200. // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
  201. // Eg:
  202. // Data("uid=10000")
  203. // Data("uid", 10000)
  204. // Data(g.Map{"uid": 10000, "name":"john"})
  205. // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
  206. func (d *CasbinRuleDao) Data(data ...interface{}) *CasbinRuleDao {
  207. return &CasbinRuleDao{M: d.M.Data(data...)}
  208. }
  209. // All does "SELECT FROM ..." statement for the model.
  210. // It retrieves the records from table and returns the result as []*model.CasbinRule.
  211. // It returns nil if there's no record retrieved with the given conditions from table.
  212. //
  213. // The optional parameter <where> is the same as the parameter of M.Where function,
  214. // see M.Where.
  215. func (d *CasbinRuleDao) All(where ...interface{}) ([]*model.CasbinRule, error) {
  216. all, err := d.M.All(where...)
  217. if err != nil {
  218. return nil, err
  219. }
  220. var entities []*model.CasbinRule
  221. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  222. return nil, err
  223. }
  224. return entities, nil
  225. }
  226. // One retrieves one record from table and returns the result as *model.CasbinRule.
  227. // It returns nil if there's no record retrieved with the given conditions from table.
  228. //
  229. // The optional parameter <where> is the same as the parameter of M.Where function,
  230. // see M.Where.
  231. func (d *CasbinRuleDao) One(where ...interface{}) (*model.CasbinRule, error) {
  232. one, err := d.M.One(where...)
  233. if err != nil {
  234. return nil, err
  235. }
  236. var entity *model.CasbinRule
  237. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  238. return nil, err
  239. }
  240. return entity, nil
  241. }
  242. // FindOne retrieves and returns a single Record by M.WherePri and M.One.
  243. // Also see M.WherePri and M.One.
  244. func (d *CasbinRuleDao) FindOne(where ...interface{}) (*model.CasbinRule, error) {
  245. one, err := d.M.FindOne(where...)
  246. if err != nil {
  247. return nil, err
  248. }
  249. var entity *model.CasbinRule
  250. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  251. return nil, err
  252. }
  253. return entity, nil
  254. }
  255. // FindAll retrieves and returns Result by by M.WherePri and M.All.
  256. // Also see M.WherePri and M.All.
  257. func (d *CasbinRuleDao) FindAll(where ...interface{}) ([]*model.CasbinRule, error) {
  258. all, err := d.M.FindAll(where...)
  259. if err != nil {
  260. return nil, err
  261. }
  262. var entities []*model.CasbinRule
  263. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  264. return nil, err
  265. }
  266. return entities, nil
  267. }
  268. // Struct retrieves one record from table and converts it into given struct.
  269. // The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
  270. // it can create the struct internally during converting.
  271. //
  272. // The optional parameter <where> is the same as the parameter of Model.Where function,
  273. // see Model.Where.
  274. //
  275. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  276. // from table and <pointer> is not nil.
  277. //
  278. // Eg:
  279. // user := new(User)
  280. // err := dao.User.Where("id", 1).Struct(user)
  281. //
  282. // user := (*User)(nil)
  283. // err := dao.User.Where("id", 1).Struct(&user)
  284. func (d *CasbinRuleDao) Struct(pointer interface{}, where ...interface{}) error {
  285. return d.M.Struct(pointer, where...)
  286. }
  287. // Structs retrieves records from table and converts them into given struct slice.
  288. // The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
  289. // slice internally during converting.
  290. //
  291. // The optional parameter <where> is the same as the parameter of Model.Where function,
  292. // see Model.Where.
  293. //
  294. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  295. // from table and <pointer> is not empty.
  296. //
  297. // Eg:
  298. // users := ([]User)(nil)
  299. // err := dao.User.Structs(&users)
  300. //
  301. // users := ([]*User)(nil)
  302. // err := dao.User.Structs(&users)
  303. func (d *CasbinRuleDao) Structs(pointer interface{}, where ...interface{}) error {
  304. return d.M.Structs(pointer, where...)
  305. }
  306. // Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
  307. // It calls function Struct if <pointer> is type of *struct/**struct.
  308. // It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
  309. //
  310. // The optional parameter <where> is the same as the parameter of Model.Where function,
  311. // see Model.Where.
  312. //
  313. // Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
  314. //
  315. // Eg:
  316. // user := new(User)
  317. // err := dao.User.Where("id", 1).Scan(user)
  318. //
  319. // user := (*User)(nil)
  320. // err := dao.User.Where("id", 1).Scan(&user)
  321. //
  322. // users := ([]User)(nil)
  323. // err := dao.User.Scan(&users)
  324. //
  325. // users := ([]*User)(nil)
  326. // err := dao.User.Scan(&users)
  327. func (d *CasbinRuleDao) Scan(pointer interface{}, where ...interface{}) error {
  328. return d.M.Scan(pointer, where...)
  329. }
  330. // Chunk iterates the table with given size and callback function.
  331. func (d *CasbinRuleDao) Chunk(limit int, callback func(entities []*model.CasbinRule, err error) bool) {
  332. d.M.Chunk(limit, func(result gdb.Result, err error) bool {
  333. var entities []*model.CasbinRule
  334. err = result.Structs(&entities)
  335. if err == sql.ErrNoRows {
  336. return false
  337. }
  338. return callback(entities, err)
  339. })
  340. }
  341. // LockUpdate sets the lock for update for current operation.
  342. func (d *CasbinRuleDao) LockUpdate() *CasbinRuleDao {
  343. return &CasbinRuleDao{M: d.M.LockUpdate()}
  344. }
  345. // LockShared sets the lock in share mode for current operation.
  346. func (d *CasbinRuleDao) LockShared() *CasbinRuleDao {
  347. return &CasbinRuleDao{M: d.M.LockShared()}
  348. }
  349. // Unscoped enables/disables the soft deleting feature.
  350. func (d *CasbinRuleDao) Unscoped() *CasbinRuleDao {
  351. return &CasbinRuleDao{M: d.M.Unscoped()}
  352. }