gen

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCircleQuery = errors.New("circle query with other fields")
)

Functions

func GenModel

func GenModel(table *InnerTable) (string, error)

Types

type Case

type Case struct {
	SnakeCase      string
	LowerCamelCase string
	UpperCamelCase string
}

type InnerField

type InnerField struct {
	IsPrimaryKey bool
	InnerWithField
	DataBaseType string // 数据库中字段类型
	Tag          string // 标签,格式:`db:"xxx"`
	Comment      string // 注释,以"// 开头"
	Cache        bool   // 是否缓存模式
	QueryType    QueryType
	WithFields   []InnerWithField
	Sort         []InnerSort
}

type InnerSort

type InnerSort struct {
	Field Case
	Asc   bool
}

type InnerTable

type InnerTable struct {
	Case
	ContainsCache  bool
	CreateNotFound bool
	PrimaryField   *InnerField
	Fields         []*InnerField
	CacheKey       map[string]Key // key-数据库字段
}

func TableConvert

func TableConvert(outerTable OuterTable) (*InnerTable, error)

type InnerWithField

type InnerWithField struct {
	Case
	DataType string
}

type Key

type Key struct {
	Define      string // cacheKey define,如:cacheUserUserIdPrefix
	Value       string // cacheKey value expression,如:cache#user#userId#
	Expression  string // cacheKey expression,如:cacheUserUserIdPrefix="cache#user#userId#"
	KeyVariable string // cacheKey 声明变量,如:userIdKey
	Key         string // 缓存key的代码,如 userIdKey:=fmt.Sprintf("%s%v", cacheUserUserIdPrefix, userId)
	DataKey     string // 缓存key的代码,如 userIdKey:=fmt.Sprintf("%s%v", cacheUserUserIdPrefix, data.userId)
	RespKey     string // 缓存key的代码,如 userIdKey:=fmt.Sprintf("%s%v", cacheUserUserIdPrefix, resp.userId)
}

type OuterFiled

type OuterFiled struct {
	IsPrimaryKey bool   `json:"isPrimaryKey,optional"`
	Name         string `json:"name"`
	DataBaseType string `json:"dataBaseType"`
	Comment      string `json:"comment"`
	Cache        bool   `json:"cache,optional"`
	// if IsPrimaryKey==false下面字段有效
	QueryType  QueryType        `json:"queryType"`           // 查找类型
	WithFields []OuterWithField `json:"withFields,optional"` // 其他字段联合组成条件的字段列表
	OuterSort  []OuterSort      `json:"sort,optional"`
}

type OuterSort

type OuterSort struct {
	Field string `json:"fields"`
	Asc   bool   `json:"asc,optional"`
}

type OuterTable

type OuterTable struct {
	Table          string        `json:"table"`
	CreateNotFound bool          `json:"createNotFound,optional"`
	Fields         []*OuterFiled `json:"fields"`
}

type OuterWithField

type OuterWithField struct {
	Name         string `json:"name"`
	DataBaseType string `json:"dataBaseType"`
}

type QueryType

type QueryType int
const (
	QueryNone  QueryType = 0
	QueryOne   QueryType = 1 // 仅支持单个字段为查询条件
	QueryAll   QueryType = 2 // 可支持多个字段为查询条件,且关系均为and
	QueryLimit QueryType = 3 // 可支持多个字段为查询条件,且关系均为and
)

Jump to

Keyboard shortcuts

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