make

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package make 命令行的 make 命令.

Index

Constants

This section is empty.

Variables

View Source
var ErrDDLDiffFound = errors.New("ddl drift detected")

ErrDDLDiffFound 表示当前模型生成的 DDL 与已落盘文件存在漂移。

Functions

func GenerateCreateTableDDL

func GenerateCreateTableDDL(db *gorm.DB, model any) (string, error)

GenerateCreateTableDDL 基于 GORM dry-run 输出严格的建表 SQL。

func NewCommand

func NewCommand(base Config) *cobra.Command

NewCommand 构建 make 命令树,base 为生成配置(零值字段回退到内置默认值). 返回的命令树持有自身配置副本,多次调用互不影响.

Types

type Config

type Config struct {
	ProjectName   string
	ModelDir      string
	RepositoryDir string
	MigrationDir  string
	DDLDir        string
	DB            *gorm.DB
	DDLModels     []any
}

Config 控制 make 系列命令的生成目录和 DDL 上下文。

type Model

type Model struct {
	TableName          string
	StructName         string
	StructNamePlural   string
	StructFieldName    string
	VariableName       string
	VariableNamePlural string
	PackageName        string
	ActionName         string
	ProjectName        string
	ColumnName         string
	ModelPackageName   string
	ModelsImportPath   string
}

Model 参数解释

单个词,以 User 模型为例:

{
    "TableName": "users",
    "StructName": "User",
    "StructNamePlural": "Users",
    "VariableName": "user",
    "VariableNamePlural": "users",
    "PackageName": "user"
}

两个词以上,以 TopicComment 模型为例:

{
    "TableName": "topic_comments",
    "StructName": "TopicComment",
    "StructNamePlural": "TopicComments",
    "VariableName": "topicComment",
    "VariableNamePlural": "topicComments",
    "PackageName": "topic_comment"
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL