schema

package
v0.0.0-...-17711c2 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TableNamePrefix  = "TableName"
	CustomizeCodeTip = "////////////////////// ----- 自定义代码请写在下面 ----- //////////////////////"
)
View Source
const (
	TAG_NAME_SQLCA      = "sqlca"
	TAG_VALUE_IS_NULL   = "isnull"
	TAG_VALUE_READ_ONLY = "readonly"
)
View Source
const (
	POSTGRES_COLUMN_INTEGER           = "integer"
	POSTGRES_COLUMN_BIT               = "bit"
	POSTGRES_COLUMN_BOOLEAN           = "boolean"
	POSTGRES_COLUMN_BOX               = "box"
	POSTGRES_COLUMN_BYTEA             = "bytea"
	POSTGRES_COLUMN_CHARACTER         = "character"
	POSTGRES_COLUMN_CIDR              = "cidr"
	POSTGRES_COLUMN_CIRCLE            = "circle"
	POSTGRES_COLUMN_DATE              = "date"
	POSTGRES_COLUMN_NUMERIC           = "numeric"
	POSTGRES_COLUMN_REAL              = "real"
	POSTGRES_COLUMN_DOUBLE            = "double"
	POSTGRES_COLUMN_INET              = "inet"
	POSTGRES_COLUMN_SMALLINT          = "smallint"
	POSTGRES_COLUMN_BIGINT            = "bigint"
	POSTGRES_COLUMN_INTERVAL          = "interval"
	POSTGRES_COLUMN_JSON              = "json"
	POSTGRES_COLUMN_JSONB             = "jsonb"
	POSTGRES_COLUMN_LINE              = "line"
	POSTGRES_COLUMN_LSEG              = "lseg"
	POSTGRES_COLUMN_MACADDR           = "macaddr"
	POSTGRES_COLUMN_MONEY             = "money"
	POSTGRES_COLUMN_PATH              = "path"
	POSTGRES_COLUMN_POINT             = "point"
	POSTGRES_COLUMN_POLYGON           = "polygon"
	POSTGRES_COLUMN_TEXT              = "text"
	POSTGRES_COLUMN_TIME              = "time"
	POSTGRES_COLUMN_TIMESTAMP         = "timestamp"
	POSTGRES_COLUMN_TSQUERY           = "tsquery"
	POSTGRES_COLUMN_TSVECTOR          = "tsvector"
	POSTGRES_COLUMN_TXID_SNAPSHOT     = "txid_snapshot"
	POSTGRES_COLUMN_UUID              = "uuid"
	POSTGRES_COLUMN_BIT_VARYING       = "bit varying"
	POSTGRES_COLUMN_CHARACTER_VARYING = "character varying"
	POSTGRES_COLUMN_XML               = "xml"
)
View Source
const (
	DB_COLUMN_TYPE_BIGINT     = "bigint"
	DB_COLUMN_TYPE_INT        = "int"
	DB_COLUMN_TYPE_INTEGER    = "integer"
	DB_COLUMN_TYPE_MEDIUMINT  = "mediumint"
	DB_COLUMN_TYPE_SMALLINT   = "smallint"
	DB_COLUMN_TYPE_TINYINT    = "tinyint"
	DB_COLUMN_TYPE_BIT        = "bit"
	DB_COLUMN_TYPE_BOOL       = "bool"
	DB_COLUMN_TYPE_BOOLEAN    = "boolean"
	DB_COLUMN_TYPE_DECIMAL    = "decimal"
	DB_COLUMN_TYPE_REAL       = "real"
	DB_COLUMN_TYPE_DOUBLE     = "double"
	DB_COLUMN_TYPE_FLOAT      = "float"
	DB_COLUMN_TYPE_NUMERIC    = "numeric"
	DB_COLUMN_TYPE_DATETIME   = "datetime"
	DB_COLUMN_TYPE_YEAR       = "year"
	DB_COLUMN_TYPE_DATE       = "date"
	DB_COLUMN_TYPE_TIME       = "time"
	DB_COLUMN_TYPE_TIMESTAMP  = "timestamp"
	DB_COLUMN_TYPE_ENUM       = "enum"
	DB_COLUMN_TYPE_SET        = "set"
	DB_COLUMN_TYPE_VARCHAR    = "varchar"
	DB_COLUMN_TYPE_NVARCHAR   = "nvarchar"
	DB_COLUMN_TYPE_CHAR       = "char"
	DB_COLUMN_TYPE_TEXT       = "text"
	DB_COLUMN_TYPE_TINYTEXT   = "tinytext"
	DB_COLUMN_TYPE_MEDIUMTEXT = "mediumtext"
	DB_COLUMN_TYPE_LONGTEXT   = "longtext"
	DB_COLUMN_TYPE_BLOB       = "blob"
	DB_COLUMN_TYPE_TINYBLOB   = "tinyblob"
	DB_COLUMN_TYPE_MEDIUMBLOB = "mediumblob"
	DB_COLUMN_TYPE_LONGBLOB   = "longblob"
	DB_COLUMN_TYPE_BINARY     = "binary"
	DB_COLUMN_TYPE_VARBINARY  = "varbinary"
	DB_COLUMN_TYPE_JSON       = "json"
	DB_COLUMN_TYPE_JSONB      = "jsonb"
	DB_COLUMN_TYPE_POINT      = "point"
	DB_COLUMN_TYPE_POLYGON    = "polygon"
)
View Source
const (
	SCHEME_MYSQL             = "mysql"
	SCHEME_POSTGRES          = "postgres"
	SCHEME_MSSQL             = "mssql"
	SCHEME_OPEN_GAUSS        = "opengauss"
	JSON_PROPERTY_OMIT_EMTPY = "omitempty"
	DAO_SUFFIX               = "dao"
	TABLE_ALL                = "__all_tables__"
)
View Source
const (
	IMPORT_GOGO_PROTO = `import "github.com/gogo/protobuf/gogoproto/gogo.proto";`
	SQLCA_V2_PKG      = `github.com/civet148/sqlca/v2`
	SQLCA_V3_PKG      = `github.com/civet148/sqlca/v3`
	IMPORT_SQLCA_V3   = `import "github.com/civet148/sqlca/v3"`
	IMPORT_SQLCA_V2   = `import "github.com/civet148/sqlca/v2"`
)
View Source
const (
	JSON_STYLE_DEFAULT         = "default"
	JSON_STYLE_SMALL_CAMELCASE = "smallcamel"
	JSON_STYLE_BIG_CAMELCASE   = "bigcamel"
)

Variables

This section is empty.

Functions

func BigCamelCase

func BigCamelCase(strIn string) (strOut string)

func ConvertFieldStyle

func ConvertFieldStyle(strColName string, style FieldStyle) string

ConvertFieldStyle 数据库字段名风格转换

func ConvertMssqlColumnType

func ConvertMssqlColumnType(table *TableSchema) (err error)

func ConvertPostgresColumnType

func ConvertPostgresColumnType(table *TableSchema) (err error)

func CreateOutputFile

func CreateOutputFile(cmd *CmdFlags, table *TableSchema, strFileSuffix string, append bool) (file *os.File, err error)

func ExportTableSchema

func ExportTableSchema(cmd *CmdFlags, tables []*TableSchema) (err error)

func ExportToSqlFile

func ExportToSqlFile(cmd *CmdFlags, ddl *CreateDatabaseDDL, tables []*TableSchema) (err error)

func GenerateMethodDeclare

func GenerateMethodDeclare(strShortName, strStructName, strMethodName, strArgs, strReturn, strLogic string) (strFunc string)

func GetDatabaseName

func GetDatabaseName(strPath string) (strName string)

func GetGoColumnType

func GetGoColumnType(cmd *CmdFlags, strTableName string, col TableColumn, enableDecimal bool, tinyintAsBool []string) (strGoColType string, isDecimal bool)

将数据库字段类型转为go语言对应的数据类型

func GetProtoColumnType

func GetProtoColumnType(strTableName string, col TableColumn) (strColType string)

将数据库字段类型转为protobuf对应的数据类型

func HandleCommentCRLF

func HandleCommentCRLF(table *TableSchema)

func IsInSlice

func IsInSlice(in string, s []string) bool

func MakeDir

func MakeDir(strDir string) (err error)

func MakeGetter

func MakeGetter(strStructName, strColName, strColType string) (strGetter string)

func MakeProtoBody

func MakeProtoBody(cmd *CmdFlags, table *TableSchema) (strContent string)

func MakeProtoHead

func MakeProtoHead(cmd *CmdFlags) (strContent string)

func MakeSetter

func MakeSetter(strStructName, strColName, strColType string) (strSetter string)

func MakeTags

func MakeTags(cmd *CmdFlags, strColName, strColType, strTagValue, strComment string, strAppends string) string

func Register

func Register(strScheme string, inst Instance)

func ReplaceCRLF

func ReplaceCRLF(strIn string) (strOut string)

func ReplaceColumnType

func ReplaceColumnType(cmd *CmdFlags, strTableName, strColName, strColType string) string

func SmallCamelCase

func SmallCamelCase(strIn string) (strOut string)

func Split

func Split(s string) (ss []string)

func TrimSpaceSlice

func TrimSpaceSlice(s []string) (ts []string)

Types

type BaseModel

type BaseModel struct {
	Columns []string          `json:"columns"`
	Type    string            `json:"type"`
	Package map[string]string `json:"package"`
}

type CmdFlags

type CmdFlags struct {
	ConnUrl        string
	Database       string
	Tables         []string
	Without        []string
	ReadOnly       []string
	ExtraTags      []string
	Scheme         string
	Host           string
	User           string
	Password       string
	Charset        string
	OutDir         string
	Prefix         string
	Suffix         string
	PackageName    string
	Protobuf       bool
	EnableDecimal  bool
	OneFile        bool
	GogoOptions    []string
	DAO            string
	ImportModels   string
	OmitEmpty      bool
	TinyintAsBool  []string
	Engine         *sqlca.Engine
	JsonProperties string
	JsonStyle      string
	SSH            string
	SpecTypes      []*SpecType
	ImportVer      string
	SqlcaPkg       string
	Debug          bool
	ExportDDL      string
	TagTypes       []*CommTagType
	ProtoOptions   map[string]string
	FieldStyle     FieldStyle
	BaseModel      *BaseModel
}

func NewCmdFlags

func NewCmdFlags() *CmdFlags

func (*CmdFlags) GetJsonPropertiesSlice

func (c *CmdFlags) GetJsonPropertiesSlice() (jsonProps []string)

func (*CmdFlags) GoString

func (c *CmdFlags) GoString() string

func (*CmdFlags) IsBaseColumn

func (c *CmdFlags) IsBaseColumn(strColumnName string) bool

func (*CmdFlags) ParseBaseModel

func (c *CmdFlags) ParseBaseModel(strBaseModel string)

func (*CmdFlags) ParseSpecTypes

func (c *CmdFlags) ParseSpecTypes(strSpecType string)

func (*CmdFlags) String

func (c *CmdFlags) String() string

type CommTagType

type CommTagType struct {
	Table    string `json:"table"`
	Column   string `json:"column"`
	TagName  string `json:"tag_name"`
	TagValue string `json:"tag_value"`
}

type CreateDatabaseDDL

type CreateDatabaseDDL struct {
	Database  string `db:"Database"`
	CreateSQL string `db:"Create Database"`
}

type Exporter

type Exporter interface {
	ExportGo() (err error)
	ExportProto() (err error)
}

func NewExporter

func NewExporter(cmd *CmdFlags, e *sqlca.Engine) Exporter

type FieldStyle

type FieldStyle int
const (
	FieldStyle_Default    FieldStyle = iota // 默认跟数据库字段一致
	FieldStyle_SmallCamel                   // 小驼峰
	FieldStyle_BigCamel                     // 大驼峰
)

func FieldStyleFromString

func FieldStyleFromString(s string) FieldStyle

type Instance

type Instance func(cmd *CmdFlags, e *sqlca.Engine) Exporter

type SpecType

type SpecType struct {
	Table   string            `json:"table"`
	Column  string            `json:"column"`
	Type    string            `json:"type"`
	Package map[string]string `json:"package"`
}

type TableColumn

type TableColumn struct {
	Name          string `json:"column_name" db:"column_name"`
	DataType      string `json:"data_type" db:"data_type"`
	ColumnType    string `json:"column_type" db:"column_type"`
	ColumnDefault string `json:"column_default" db:"column_default"`
	ColumnKey     string `json:"column_key" db:"column_key"`
	Extra         string `json:"extra" db:"extra"`
	Comment       string `json:"column_comment" db:"column_comment"`
	IsNullable    string `json:"is_nullable" db:"is_nullable"`
	GoName        string // column name in golang
	GoType        string // column type in golang
}

func (TableColumn) IsCreateTime

func (c TableColumn) IsCreateTime() bool

func (TableColumn) IsDeleteTime

func (c TableColumn) IsDeleteTime() bool

func (TableColumn) IsPrimaryKey

func (c TableColumn) IsPrimaryKey() bool

func (TableColumn) IsUpdateTime

func (c TableColumn) IsUpdateTime() bool

type TableSchema

type TableSchema struct {
	SchemeName         string        `json:"table_schema" db:"table_schema"`   //database name
	TableName          string        `json:"table_name" db:"table_name"`       //table name
	TableEngine        string        `json:"engine" db:"engine"`               //database engine
	TableComment       string        `json:"table_comment" db:"table_comment"` //comment of table schema
	SchemeDir          string        `json:"schema_dir" db:"schema_dir"`       //output path
	PkName             string        `json:"pk_name" db:"pk_name"`             //primary key column name
	StructName         string        `json:"struct_name" db:"struct_name"`     //struct name
	StructDAO          string        `json:"struct_dao" db:"struct_dao"`       //struct DAO name
	OutDir             string        `json:"out_dir" db:"out_dir"`             //output directory
	OutFilePath        string        `json:"file_name" db:"file_name"`         //output file path
	Columns            []TableColumn `json:"table_columns" db:"table_columns"` //columns with database and golang
	TableNameCamelCase string        `json:"-"`                                //table name in camel case
	TableCreateSQL     string        `json:"-"`                                //table create SQL
}

Jump to

Keyboard shortcuts

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