gendb

package
v0.0.0-...-58d91f3 Latest Latest
Warning

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

Go to latest
Published: May 10, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BIGINT = DataType(1)
	INT    = DataType(2)
	BOOL   = DataType(3)
	STRING = DataType(4)
	FLOAT  = DataType(5)
	STRUCT = DataType(100)
)

Variables

View Source
var IGNORE_UPDATE_COLNAMES = []string{"CreateTime", "ModifiedTime"}

Functions

func CreateBootGoFile

func CreateBootGoFile(env *Env, boot_tpl string, fillVarsFunc func(map[string]interface{})) error

func FmtGoFile

func FmtGoFile(gofile string) error

func RenderByTplFile

func RenderByTplFile(tplfile string, data interface{}) ([]byte, error)

func RenderDMgo

func RenderDMgo(DMTemplateFilePath string, MmPackage string, m *ModelSQLGen) ([]byte, error)

func RenderTpl

func RenderTpl(tplname string, tplcontent string, data interface{}) ([]byte, error)

根据模版生成内容

Types

type Col

type Col struct {
	ColName     string
	ColDataType DataType
	GoTypeName  string
	NotAutoInc  bool //默认主键是自增长的
	FieldName   string
	Comment     string //字段注释
}

func (*Col) IsNum

func (m *Col) IsNum() bool

type DataType

type DataType int

func GetDBTypeByKind

func GetDBTypeByKind(kind reflect.Kind) DataType

type Env

type Env struct {
	GOPATH       string
	CurDir       string
	OutputDir    string
	TmpDir       string
	TemplatePath string
}

func NewEnv

func NewEnv(outputPath string) (m *Env)

func (*Env) PrintDebug

func (m *Env) PrintDebug()

type ModelSQLGen

type ModelSQLGen struct {
	Struct     reflect.Type
	TableName  string
	PKCol      *Col
	Cols       []*Col
	UpdateCols []*Col //no PK, createtime, modifiedtime
	// contains filtered or unexported fields
}

func CreateSQLGenByObj

func CreateSQLGenByObj(obj interface{}, tableName string, pk_col_name string) *ModelSQLGen

func (*ModelSQLGen) ColsSQL

func (m *ModelSQLGen) ColsSQL() string

func (*ModelSQLGen) CreateTableSQL

func (m *ModelSQLGen) CreateTableSQL() string

func (*ModelSQLGen) DeleteByPK_SQL

func (m *ModelSQLGen) DeleteByPK_SQL() string

func (*ModelSQLGen) HasCreateTime

func (m *ModelSQLGen) HasCreateTime() bool

func (*ModelSQLGen) HasModifiedTime

func (m *ModelSQLGen) HasModifiedTime() bool

func (*ModelSQLGen) InsertCode

func (m *ModelSQLGen) InsertCode() string

func (*ModelSQLGen) JoinCols

func (m *ModelSQLGen) JoinCols(alias string, hasPK, hasTimes bool) string

func (*ModelSQLGen) PlaceholdSQL

func (m *ModelSQLGen) PlaceholdSQL() string

func (*ModelSQLGen) QueryByPK_SQL

func (m *ModelSQLGen) QueryByPK_SQL() string

func (*ModelSQLGen) UpdateColsSQL

func (m *ModelSQLGen) UpdateColsSQL() string

Jump to

Keyboard shortcuts

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