You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
3.0 KiB

2 weeks ago
2 weeks ago
  1. // ==========================================================================
  2. // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
  3. // ==========================================================================
  4. package internal
  5. import (
  6. "context"
  7. "github.com/gogf/gf/v2/database/gdb"
  8. "github.com/gogf/gf/v2/frame/g"
  9. )
  10. // ArticleDao is the data access object for the table article.
  11. type ArticleDao struct {
  12. table string // table is the underlying table name of the DAO.
  13. group string // group is the database configuration group name of the current DAO.
  14. columns ArticleColumns // columns contains all the column names of Table for convenient usage.
  15. handlers []gdb.ModelHandler // handlers for customized model modification.
  16. }
  17. // ArticleColumns defines and stores column names for the table article.
  18. type ArticleColumns struct {
  19. Id string //
  20. UserId string // 用户ID
  21. ArticleTitle string // 文章/视频标题
  22. ArticleContent string // 文章/视频内容
  23. VoteStatus string // 是否发起投票:1发起,0不发起
  24. CreateTime string //
  25. UpdateTime string //
  26. }
  27. // articleColumns holds the columns for the table article.
  28. var articleColumns = ArticleColumns{
  29. Id: "id",
  30. UserId: "user_id",
  31. ArticleTitle: "article_title",
  32. ArticleContent: "article_content",
  33. VoteStatus: "vote_status",
  34. CreateTime: "create_time",
  35. UpdateTime: "update_time",
  36. }
  37. // NewArticleDao creates and returns a new DAO object for table data access.
  38. func NewArticleDao(handlers ...gdb.ModelHandler) *ArticleDao {
  39. return &ArticleDao{
  40. group: "default",
  41. table: "article",
  42. columns: articleColumns,
  43. handlers: handlers,
  44. }
  45. }
  46. // DB retrieves and returns the underlying raw database management object of the current DAO.
  47. func (dao *ArticleDao) DB() gdb.DB {
  48. return g.DB(dao.group)
  49. }
  50. // Table returns the table name of the current DAO.
  51. func (dao *ArticleDao) Table() string {
  52. return dao.table
  53. }
  54. // Columns returns all column names of the current DAO.
  55. func (dao *ArticleDao) Columns() ArticleColumns {
  56. return dao.columns
  57. }
  58. // Group returns the database configuration group name of the current DAO.
  59. func (dao *ArticleDao) Group() string {
  60. return dao.group
  61. }
  62. // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
  63. func (dao *ArticleDao) Ctx(ctx context.Context) *gdb.Model {
  64. model := dao.DB().Model(dao.table)
  65. for _, handler := range dao.handlers {
  66. model = handler(model)
  67. }
  68. return model.Safe().Ctx(ctx)
  69. }
  70. // Transaction wraps the transaction logic using function f.
  71. // It rolls back the transaction and returns the error if function f returns a non-nil error.
  72. // It commits the transaction and returns nil if function f returns nil.
  73. //
  74. // Note: Do not commit or roll back the transaction in function f,
  75. // as it is automatically handled by this function.
  76. func (dao *ArticleDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
  77. return dao.Ctx(ctx).Transaction(ctx, f)
  78. }