sys_group.go 15 KB

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