casbin_rule_model.go 12 KB

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