schema

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	METHOD_ARGS_NULL     = ""
	METHOD_NAME_STRING   = "String"
	METHOD_NAME_GOSTRING = "GoString"
	METHOD_NAME_GET      = "Get"
	METHOD_NAME_SET      = "Set"
)
View Source
const (
	SCHEME_MYSQL             = "mysql"
	SCHEME_POSTGRES          = "postgres"
	SCHEME_MSSQL             = "mssql"
	JSON_PROPERTY_OMIT_EMTPY = "omitempty"
)
View Source
const (
	IMPORT_GOGO_PROTO = `import "github.com/gogo/protobuf/gogoproto/gogo.proto";`
	IMPORT_SQLCA      = `import "github.com/civet148/sqlca"`
)
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"
)

Variables

This section is empty.

Functions

func CamelCaseConvert

func CamelCaseConvert(strIn string) (strOut string)

func ConvertMssqlColumnType

func ConvertMssqlColumnType(table *TableSchema) (err error)

func ConvertPostgresColumnType

func ConvertPostgresColumnType(table *TableSchema) (err error)

func CreateOutputFile

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

func ExportTableColumns

func ExportTableColumns(cmd *Commander, table *TableSchema) (err error)

func ExportTableSchema

func ExportTableSchema(cmd *Commander, 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(strTableName string, col TableColumn, enableDecimal bool, tinyintAsBool []string) (strGoColType string, isDecimal bool)

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

func GetProtoColumnType

func GetProtoColumnType(strTableName, strColName, strDataType string) (strColType string)

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

func HandleCommentCRLF

func HandleCommentCRLF(table *TableSchema)

func IsInSlice

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

func MakeGetter

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

func MakeProtoBody

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

func MakeProtoHead

func MakeProtoHead(cmd *Commander) (strContent string)

func MakeSetter

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

func MakeTags

func MakeTags(cmd *Commander, 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 TrimSpaceSlice

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

Types

type Commander

type Commander struct {
	ConnUrl        string        `json:"ConnUrl,omitempty"`
	Database       string        `json:"-"`
	Tables         []string      `json:"-"`
	Without        []string      `json:"Without,omitempty"`
	ReadOnly       []string      `json:"ReadOnly,omitempty"`
	Tags           []string      `json:"Tags,omitempty"`
	Scheme         string        `json:"-"`
	Host           string        `json:"-"`
	User           string        `json:"-"`
	Password       string        `json:"-"`
	Charset        string        `json:"-"`
	OutDir         string        `json:"OutDir,omitempty"`
	Prefix         string        `json:"Prefix,omitempty"`
	Suffix         string        `json:"Suffix,omitempty"`
	PackageName    string        `json:"PackageName,omitempty"`
	Protobuf       bool          `json:"Protobuf,omitempty"`
	EnableDecimal  bool          `json:"EnableDecimal,omitempty"`
	OneFile        bool          `json:"OneFile,omitempty"`
	GogoOptions    []string      `json:"GogoOptions,omitempty"`
	Orm            bool          `json:"Orm,omitempty"`
	OmitEmpty      bool          `json:"OmitEmpty,omitempty"`
	Struct         bool          `json:"Struct"`
	TinyintAsBool  []string      `json:"TinyintAsBool,omitempty"`
	Engine         *sqlca.Engine `json:"-"`
	JsonProperties string        `json:"-"`
	SSH            string        `json:"ssh"`
}

func (*Commander) GetJsonPropertiesSlice

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

func (*Commander) GoString

func (c *Commander) GoString() string

func (*Commander) String

func (c *Commander) String() string

type Exporter

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

func NewExporter

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

type Instance

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

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"`
	Key          string `json:"column_key" db:"column_key"`
	Extra        string `json:"extra" db:"extra"`
	Comment      string `json:"column_comment" db:"column_comment"`
	IsPrimaryKey bool   // is primary key
	IsDecimal    bool   // is decimal type
	IsReadOnly   bool   // is read only
	GoName       string //column name in golang
	GoType       string //column type in golang
}

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
	OutDir             string        `json:"out_dir" db:"out_dir"`             //output directory
	FileName           string        `json:"file_name" db:"file_name"`         //output directory
	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