Documentation ¶
Overview ¶
Package parser is a library that parses to go structures based on sql and generates the code needed based on the template.
Index ¶
- Constants
- func ConvertToSQLByMgoFields(tableName string, fields []*MgoField) (string, map[string]string)
- func ConvertToSQLByPgFields(tableName string, fields []*PGField) (string, map[string]string)
- func GetMysqlTableInfo(dsn, tableName string) (string, error)
- func GetSqliteTableInfo(dbFile string, tableName string) (string, error)
- func GetTableInfo(dsn, tableName string) (string, error)
- func MgoFieldToGoStruct(name string, fs []*MgoField) string
- func ParseSQL(sql string, options ...Option) (map[string]string, error)
- func SetJSONTagCamelCase()
- func SetJSONTagSnakeCase()
- type Codes
- type MgoField
- type NullStyle
- type Option
- func WithCharset(charset string) Option
- func WithCollation(collation string) Option
- func WithColumnPrefix(p string) Option
- func WithDBDriver(driver string) Option
- func WithEmbed() Option
- func WithExtendedAPI() Option
- func WithFieldTypes(fieldTypes map[string]string) Option
- func WithForceTableName() Option
- func WithGormType() Option
- func WithJSONTag(namedType int) Option
- func WithNoNullType() Option
- func WithNullStyle(s NullStyle) Option
- func WithPackage(pkg string) Option
- func WithTablePrefix(p string) Option
- func WithWebProto() Option
- type PGField
Constants ¶
const ( // SubStructKey sub struct key SubStructKey = "_sub_struct_" // ProtoSubStructKey proto sub struct key ProtoSubStructKey = "_proto_sub_struct_" )
const ( // TableName table name TableName = "__table_name__" // CodeTypeModel model code CodeTypeModel = "model" // CodeTypeJSON json code CodeTypeJSON = "json" // CodeTypeDAO update fields code CodeTypeDAO = "dao" // CodeTypeHandler handler request and respond code CodeTypeHandler = "handler" // CodeTypeProto proto file code CodeTypeProto = "proto" // CodeTypeService grpc service code CodeTypeService = "service" // DBDriverMysql mysql driver DBDriverMysql = "mysql" // DBDriverPostgresql postgresql driver DBDriverPostgresql = "postgresql" // DBDriverTidb tidb driver DBDriverTidb = "tidb" // DBDriverSqlite sqlite driver DBDriverSqlite = "sqlite" // DBDriverMongodb mongodb driver DBDriverMongodb = "mongodb" )
Variables ¶
This section is empty.
Functions ¶
func ConvertToSQLByMgoFields ¶
ConvertToSQLByMgoFields convert to mysql table ddl
func ConvertToSQLByPgFields ¶
ConvertToSQLByPgFields convert to mysql table ddl
func GetMysqlTableInfo ¶
GetMysqlTableInfo get table info from mysql
func GetSqliteTableInfo ¶
GetSqliteTableInfo get table info from sqlite
func GetTableInfo ¶
GetTableInfo get table info from mysql Deprecated: replaced by GetMysqlTableInfo
func MgoFieldToGoStruct ¶
MgoFieldToGoStruct convert to go struct
func SetJSONTagCamelCase ¶
func SetJSONTagCamelCase()
SetJSONTagCamelCase set json tag format to camel case
func SetJSONTagSnakeCase ¶
func SetJSONTagSnakeCase()
SetJSONTagSnakeCase set json tag format to snake case
Types ¶
type Codes ¶
type Codes struct { Model []string // model code UpdateFields []string // update fields code ModelJSON []string // model json code HandlerStruct []string // handler request and respond code }
Codes content
type MgoField ¶
type MgoField struct { Name string `json:"name"` Type string `json:"type"` Comment string `json:"comment"` ObjectStr string `json:"objectStr"` ProtoObjectStr string `json:"protoObjectStr"` }
MgoField mongo field
type Option ¶
type Option func(*options)
Option function
func WithFieldTypes ¶
WithFieldTypes set field types
func WithJSONTag ¶
WithJSONTag set json tag, 0 for underscore, other values for hump
type PGField ¶
type PGField struct { Name string `gorm:"column:name;" json:"name"` Type string `gorm:"column:type;" json:"type"` Comment string `gorm:"column:comment;" json:"comment"` Length int `gorm:"column:length;" json:"length"` Lengthvar int `gorm:"column:lengthvar;" json:"lengthvar"` Notnull bool `gorm:"column:notnull;" json:"notnull"` }
PGField postgresql field