demo_gen_class.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // ==========================================================================
  2. // GFast自动生成dao internal操作代码,无需手动修改,重新生成会自动覆盖.
  3. // 生成日期:2021-07-26 11:07:30
  4. // 生成路径: gfast/app/system/dao/internal/demo_gen_class.go
  5. // 生成人:gfast
  6. // ==========================================================================
  7. package internal
  8. import (
  9. "context"
  10. "github.com/gogf/gf/database/gdb"
  11. "github.com/gogf/gf/frame/g"
  12. )
  13. // DemoGenClassDao is the manager for logic model data accessing and custom defined data operations functions management.
  14. type DemoGenClassDao struct {
  15. Table string // Table is the underlying table name of the DAO.
  16. Group string // Group is the database configuration group name of current DAO.
  17. Columns DemoGenClassColumns // Columns is the short type for Columns, which contains all the column names of Table for convenient usage.
  18. }
  19. // DemoGenClassColumns defines and stores column names for table demo_gen_class.
  20. type DemoGenClassColumns struct {
  21. Id string // 分类id
  22. ClassName string // 分类名
  23. }
  24. var demoGenClassColumns = DemoGenClassColumns{
  25. Id: "id",
  26. ClassName: "class_name",
  27. }
  28. // NewDemoGenClassDao creates and returns a new DAO object for table data access.
  29. func NewDemoGenClassDao() *DemoGenClassDao {
  30. return &DemoGenClassDao{
  31. Group: "default",
  32. Table: "demo_gen_class",
  33. Columns: demoGenClassColumns,
  34. }
  35. }
  36. // DB retrieves and returns the underlying raw database management object of current DAO.
  37. func (dao *DemoGenClassDao) DB() gdb.DB {
  38. return g.DB(dao.Group)
  39. }
  40. // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
  41. func (dao *DemoGenClassDao) Ctx(ctx context.Context) *gdb.Model {
  42. return dao.DB().Model(dao.Table).Safe().Ctx(ctx)
  43. }
  44. // Transaction wraps the transaction logic using function f.
  45. // It rollbacks the transaction and returns the error from function f if it returns non-nil error.
  46. // It commits the transaction and returns nil if function f returns nil.
  47. //
  48. // Note that, you should not Commit or Rollback the transaction in function f
  49. // as it is automatically handled by this function.
  50. func (dao *DemoGenClassDao) Transaction(ctx context.Context, f func(ctx context.Context, tx *gdb.TX) error) (err error) {
  51. return dao.Ctx(ctx).Transaction(ctx, f)
  52. }