Documentation ¶
Index ¶
- Variables
- func GuessTypeName(ci *schema.ColumnInfo) string
- func IgnoreNotFoundError(err error) error
- func MoveEdge(query *gorm.DB, base uint, offset string) (err error)
- func Paginate(query *gorm.DB, out interface{}, pageno, pagesize int) (total int, err error)
- func ReplaceModelFields(cp *rewrite.CodeParser, node *rewrite.DeclNode, summary ClassSummary)
- func ScanModelDir(dir string)
- type ClassSummary
- type FilterFunc
- type ITableComment
- type ITableName
- type Model
- type NestedModel
- type SqlTag
- type TimeModel
Constants ¶
This section is empty.
Variables ¶
View Source
var ModelClasses = map[string]ClassSummary{ "base.TimeModel": { Name: "base.TimeModel", Import: "github.com/azhai/gozzo-db/construct", Alias: "base", Features: []string{ "CreatedAt time.Time", "UpdatedAt time.Time", "DeletedAt *time.Time", }, FieldLines: []string{ "CreatedAt time.Time `json:\"-\" gorm:\"comment:'创建时间'\"` // 创建时间", "UpdatedAt time.Time `json:\"-\" gorm:\"comment:'更新时间'\"` // 更新时间", "DeletedAt *time.Time `json:\"-\" gorm:\"index;comment:'删除时间'\"` // 删除时间", }, }, "*base.NestedModel": { Name: "*base.NestedModel", Import: "github.com/azhai/gozzo-db/construct", Alias: "base", Features: []string{ "Lft uint", "Rgt uint", "Depth uint8", }, FieldLines: []string{ "Lft uint `json:\"-\" gorm:\"not null;default:0;comment:'左边界'\"` // 左边界", "Rgt uint `json:\"-\" gorm:\"not null;index;default:0;comment:'右边界'\"` // 右边界", "Depth uint8 `json:\"depth\" gorm:\"not null;index;default:1;comment:'高度'\"` // 高度", }, }, }
Functions ¶
func GuessTypeName ¶
func GuessTypeName(ci *schema.ColumnInfo) string
根据数据库字段类型猜测Go类型,适用于mysql或pgsql
func ReplaceModelFields ¶ added in v0.6.3
func ReplaceModelFields(cp *rewrite.CodeParser, node *rewrite.DeclNode, summary ClassSummary)
func ScanModelDir ¶ added in v0.6.3
func ScanModelDir(dir string)
Types ¶
type ClassSummary ¶ added in v0.6.3
type ClassSummary struct { Name string Import, Alias string Features []string FieldLines []string IsChanged bool // contains filtered or unexported fields }
func NewClassSummary ¶ added in v0.6.3
func NewClassSummary(name string) ClassSummary
func ReplaceSummary ¶ added in v0.6.3
func ReplaceSummary(summary, sub ClassSummary) ClassSummary
func (ClassSummary) GetInnerCode ¶ added in v0.6.3
func (s ClassSummary) GetInnerCode() string
func (ClassSummary) GetSortedFeatures ¶ added in v0.6.3
func (s ClassSummary) GetSortedFeatures() []string
func (*ClassSummary) ParseFields ¶ added in v0.6.3
func (s *ClassSummary) ParseFields(cp *rewrite.CodeParser, node *rewrite.DeclNode) int
type Model ¶
type Model struct {
ID uint `json:"id" toml:"-" gorm:"primary_key;not null;auto_increment"`
}
*
- 带自增主键的基础Model
func (Model) TableComment ¶ added in v0.5.5
type NestedModel ¶ added in v0.6.3
type NestedModel struct { Lft uint `json:"-" gorm:"not null;default:0;comment:'左边界'"` // 左边界 Rgt uint `json:"-" gorm:"not null;index;default:0;comment:'右边界'"` // 右边界 Depth uint8 `json:"depth" gorm:"not null;index;default:1;comment:'高度'"` // 高度 }
嵌套集合树
func (*NestedModel) AddToParent ¶ added in v0.6.3
func (n *NestedModel) AddToParent(parent *NestedModel, tbQuery *gorm.DB) error
添加到父节点最末,tbQuery一定要使用db.Table(...)
func (NestedModel) AncestorsFilter ¶ added in v0.6.3
func (n NestedModel) AncestorsFilter(Backward bool) FilterFunc
找出所有直系祖先节点
func (NestedModel) ChildrenFilter ¶ added in v0.6.3
func (n NestedModel) ChildrenFilter(rank uint8) FilterFunc
找出所有子孙节点
func (NestedModel) CountChildren ¶ added in v0.6.3
func (n NestedModel) CountChildren() int
有多少个子孙节点
Click to show internal directories.
Click to hide internal directories.