dao_internal.template 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // ==========================================================================
  2. // GFast自动生成dao internal操作代码,无需手动修改,重新生成会自动覆盖.
  3. // 生成日期:{{.table.CreateTime}}
  4. // 生成路径: {{.table.PackageName}}/dao/internal/{{.table.TableName}}.go
  5. // 生成人:{{.table.FunctionAuthor}}
  6. // ==========================================================================
  7. package internal
  8. import (
  9. "github.com/gogf/gf/database/gdb"
  10. "github.com/gogf/gf/frame/g"
  11. "github.com/gogf/gf/frame/gmvc"
  12. )
  13. // {{.table.ClassName}}Dao is the manager for logic model data accessing and custom defined data operations functions management.
  14. type {{.table.ClassName}}Dao struct {
  15. gmvc.M // M is the core and embedded struct that inherits all chaining operations from gdb.Model.
  16. C {{.table.BusinessName | CaseCamelLower}}Columns // C is the short type for Columns, which contains all the column names of Table for convenient usage.
  17. DB gdb.DB // DB is the raw underlying database management object.
  18. Table string // Table is the underlying table name of the DAO.
  19. }
  20. // {{.table.BusinessName | CaseCamelLower}}Columns defines and stores column names for table {{.table.TableName}}.
  21. type {{.table.BusinessName | CaseCamelLower}}Columns struct {
  22. {{range $index, $column := .table.Columns}}
  23. {{$column.GoField}} string // {{$column.ColumnComment}}
  24. {{end}}
  25. }
  26. // New{{.table.ClassName}}Dao creates and returns a new DAO object for table data access.
  27. func New{{.table.ClassName}}Dao() *{{.table.ClassName}}Dao {
  28. columns := {{.table.BusinessName | CaseCamelLower}}Columns{
  29. {{range $index, $column := .table.Columns}}
  30. {{$column.GoField}}: "{{$column.ColumnName}}",
  31. {{end}}
  32. }
  33. return &{{.table.ClassName}}Dao{
  34. C: columns,
  35. M: g.DB("default").Model("{{.table.TableName}}").Safe(),
  36. DB: g.DB("default"),
  37. Table: "{{.table.TableName}}",
  38. }
  39. }