learning_learning_record.go 16 KB

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