1
0

sys_post_role.go 14 KB

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