Documentation
¶
Index ¶
- func BuildDefaultTableDDL(tableName string, cols []*columnMeta) string
- func BytesToString(bs []uint8) string
- func CRLFNewlines(d []byte) []byte
- func CheckForDupeTable(tables map[string]*ModelInfo, name string) string
- func Copy(dst interface{}, src interface{}) error
- func Exists(name string) bool
- func FindInSlice(slice []string, val string) (int, bool)
- func FindInSliceRegex(slice []string, val string) (int, bool)
- func FindPrimaryKeyFromInformationSchema(db *sql.DB, tableName string) (primaryKey string, err error)
- func FmtFieldName(s string) string
- func FormatSource(s string) string
- func GenerateHardDeleteSQL(dbTable DbTableMeta, namedParams bool) (string, error)
- func GenerateInsertSQL(dbTable DbTableMeta, namedParams bool) (string, error)
- func GenerateSelectAllSQL(dbTable DbTableMeta) (string, error)
- func GenerateSelectMultiSQL(dbTable DbTableMeta, namedParams bool) (string, error)
- func GenerateSelectOneSQL(dbTable DbTableMeta, namedParams bool) (string, error)
- func GenerateSoftDeleteSQL(dbTable DbTableMeta, namedParams bool) (string, error)
- func GenerateUpdateSQL(dbTable DbTableMeta, namedParams bool) (string, error)
- func GetFieldLenFromInformationSchema(db *sql.DB, tableSchema, tableName, columnName string) (int64, error)
- func GetFunctionName(i interface{}) string
- func GetMappings() map[string]*SQLMapping
- func InitColorOutput(_au aurora.Aurora)
- func LoadMappings(mappingFileName string, verbose bool) error
- func LoadTableInfo(db *sql.DB, dbTables []string, excludeDbTables []string, conf *Config) map[string]*ModelInfo
- func LoadTableInfoFromMSSqlInformationSchema(db *sql.DB, tableName string) (primaryKey map[string]*InformationSchema, err error)
- func LoadTableInfoFromPostgresInformationSchema(db *sql.DB, tableName string) (primaryKey map[string]*PostgresInformationSchema, err error)
- func NonPrimaryKeyNames(dbTable DbTableMeta) []string
- func NormalizeNewlines(d []byte) []byte
- func ParseSQLType(dbType string) (resultType string, dbTypeLen int64)
- func PrimaryKeyCount(dbTable DbTableMeta) int
- func PrimaryKeyNames(dbTable DbTableMeta) []string
- func ProcessMappings(source string, mappingJsonstring []byte, verbose bool) error
- func Pwd() string
- func RegSplit(text string, delimeter string) []string
- func RenameReservedName(s string) string
- func Replace(nameFormat, name string) string
- func SQLTypeToGoType(sqlType string, nullable bool, gureguTypes bool) (string, error)
- func SQLTypeToProtobufType(sqlType string) (string, error)
- func Spew(val interface{}) string
- func ToJSON(val interface{}, indent int) string
- func TrimSpaceNewlineInString(s string) string
- type ColumnMeta
- type Config
- func (c *Config) CreateContextForTableFile(tableInfo *ModelInfo) map[string]interface{}
- func (c *Config) DisplayConfig() string
- func (c *Config) FileSystemCopy(src, dst string, options ...string) string
- func (c *Config) GenerateFieldsTypes(dbMeta DbTableMeta) ([]*FieldInfo, error)
- func (c *Config) GenerateFile(templateFilename, outputDirectory, outputFileName string, overwrite bool) string
- func (c *Config) GenerateTableFile(tableName, templateFilename, outputDirectory, outputFileName string) string
- func (c *Config) GetTemplate(genTemplate *GenTemplate) (*template.Template, error)
- func (c *Config) JSONFieldName(name string) string
- func (c *Config) JSONTag(name string) string
- func (c *Config) JSONTagOmitEmpty(name string) string
- func (c *Config) LoadFragments(dirname string) error
- func (c *Config) Mkdir(dst string) string
- func (c *Config) ReplaceFieldNamingTemplate(name string) string
- func (c *Config) ReplaceFileNamingTemplate(name string) string
- func (c *Config) ReplaceModelNamingTemplate(name string) string
- func (c *Config) Touch(dst string) string
- func (c *Config) WriteTemplate(genTemplate *GenTemplate, data map[string]interface{}, outputFile string) error
- type DbTableMeta
- func LoadMeta(sqlType string, db *sql.DB, sqlDatabase, tableName string) (DbTableMeta, error)
- func LoadMsSQLMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
- func LoadMysqlMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
- func LoadPostgresMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
- func LoadSqliteMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
- func LoadUnknownMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
- type FieldInfo
- type GenTemplate
- type InformationSchema
- type ModelInfo
- type PostgresInformationSchema
- type SQLMapping
- type SQLMappings
- type State
- type SwaggerInfoDetails
- type TemplateLoader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildDefaultTableDDL ¶
BuildDefaultTableDDL create a ddl mock using the ColumnMeta data
func CheckForDupeTable ¶
CheckForDupeTable check for duplicate table name, returns available name
func Copy ¶
func Copy(dst interface{}, src interface{}) error
Copy a src struct into a destination struct
func FindInSlice ¶
FindInSlice takes a slice and looks for an element in it. If found it will return it's key, otherwise it will return -1 and a bool of false.
func FindInSliceRegex ¶
FindInSliceRegex same as FindInSlice but using each value in slice as a regex pattern
func FindPrimaryKeyFromInformationSchema ¶
func FindPrimaryKeyFromInformationSchema(db *sql.DB, tableName string) (primaryKey string, err error)
FindPrimaryKeyFromInformationSchema fetch primary key info from information_schema
func FmtFieldName ¶
FmtFieldName formats a string as a struct key
Example:
fmtFieldName("foo_id")
Output: FooID
func GenerateHardDeleteSQL ¶
func GenerateHardDeleteSQL(dbTable DbTableMeta, namedParams bool) (string, error)
GenerateHardDeleteSQL generate sql for a delete
func GenerateInsertSQL ¶
func GenerateInsertSQL(dbTable DbTableMeta, namedParams bool) (string, error)
GenerateInsertSQL generate sql for a insert
func GenerateSelectAllSQL ¶
func GenerateSelectAllSQL(dbTable DbTableMeta) (string, error)
GenerateSelectAllSQL generate sql for selecting multiple records
func GenerateSelectMultiSQL ¶
func GenerateSelectMultiSQL(dbTable DbTableMeta, namedParams bool) (string, error)
GenerateSelectMultiSQL generate sql for selecting multiple records
func GenerateSelectOneSQL ¶
func GenerateSelectOneSQL(dbTable DbTableMeta, namedParams bool) (string, error)
GenerateSelectOneSQL generate sql for selecting one record
func GenerateSoftDeleteSQL ¶
func GenerateSoftDeleteSQL(dbTable DbTableMeta, namedParams bool) (string, error)
GenerateSoftDeleteSQL generate sql for a soft delete (update)
func GenerateUpdateSQL ¶
func GenerateUpdateSQL(dbTable DbTableMeta, namedParams bool) (string, error)
GenerateUpdateSQL generate sql for a update
func GetFieldLenFromInformationSchema ¶
func GetFieldLenFromInformationSchema(db *sql.DB, tableSchema, tableName, columnName string) (int64, error)
GetFieldLenFromInformationSchema fetch field length from database
func InitColorOutput ¶
func LoadMappings ¶
LoadMappings load sql mappings to load mapping json file
func LoadTableInfo ¶
func LoadTableInfo(db *sql.DB, dbTables []string, excludeDbTables []string, conf *Config) map[string]*ModelInfo
LoadTableInfo load table info from db connection, and list of tables
func LoadTableInfoFromMSSqlInformationSchema ¶
func LoadTableInfoFromMSSqlInformationSchema(db *sql.DB, tableName string) (primaryKey map[string]*InformationSchema, err error)
LoadTableInfoFromMSSqlInformationSchema fetch info from information_schema for ms sql database
func LoadTableInfoFromPostgresInformationSchema ¶
func LoadTableInfoFromPostgresInformationSchema(db *sql.DB, tableName string) (primaryKey map[string]*PostgresInformationSchema, err error)
LoadTableInfoFromPostgresInformationSchema fetch info from information_schema for postgres database
func NonPrimaryKeyNames ¶
func NonPrimaryKeyNames(dbTable DbTableMeta) []string
NonPrimaryKeyNames return the list of primary key names
func NormalizeNewlines ¶
NormalizeNewlines normalizes \r\n (windows) and \r (mac) into \n (unix)
func ParseSQLType ¶
ParseSQLType parse sql type and return raw type and length
func PrimaryKeyCount ¶
func PrimaryKeyCount(dbTable DbTableMeta) int
PrimaryKeyCount return the number of primary keys in table
func PrimaryKeyNames ¶
func PrimaryKeyNames(dbTable DbTableMeta) []string
PrimaryKeyNames return the list of primary key names
func ProcessMappings ¶
ProcessMappings process the json for mappings to load sql mappings
func RenameReservedName ¶
RenameReservedName renames a reserved word
func SQLTypeToGoType ¶
SQLTypeToGoType map a sql type to a go type
func SQLTypeToProtobufType ¶
SQLTypeToProtobufType map a sql type to a protobuf type
func Spew ¶
func Spew(val interface{}) string
Spew func to return spewed string representation of struct
func TrimSpaceNewlineInString ¶
TrimSpaceNewlineInString replace spaces in string
Types ¶
type ColumnMeta ¶
type ColumnMeta interface {
Name() string
String() string
Nullable() bool
DatabaseTypeName() string
DatabaseTypePretty() string
Index() int
IsPrimaryKey() bool
IsAutoIncrement() bool
IsArray() bool
ColumnType() string
Notes() string
Comment() string
ColumnLength() int64
DefaultValue() string
}
ColumnMeta meta data for a column
type Config ¶
type Config struct {
SQLType string
SQLConnStr string
SQLDatabase string
Module string
ModelPackageName string
ModelFQPN string
AddJSONAnnotation bool
AddGormAnnotation bool
AddProtobufAnnotation bool
AddXMLAnnotation bool
AddDBAnnotation bool
UseGureguTypes bool
JSONNameFormat string
XMLNameFormat string
ProtobufNameFormat string
DaoPackageName string
DaoFQPN string
APIPackageName string
APIFQPN string
GrpcPackageName string
GrpcFQPN string
Swagger *SwaggerInfoDetails
ServerPort int
ServerHost string
ServerScheme string
ServerListen string
Verbose bool
OutDir string
Overwrite bool
LineEndingCRLF bool
CmdLine string
CmdLineWrapped string
CmdLineArgs []string
FileNamingTemplate string
ModelNamingTemplate string
FieldNamingTemplate string
ContextMap map[string]interface{}
TemplateLoader TemplateLoader
TableInfos map[string]*ModelInfo
FragmentsDir string
// contains filtered or unexported fields
}
Config for generating code
func NewConfig ¶
func NewConfig(templateLoader TemplateLoader) *Config
NewConfig create a new code config
func (*Config) CreateContextForTableFile ¶
CreateContextForTableFile create map context for a db table
func (*Config) DisplayConfig ¶
DisplayConfig display config info
func (*Config) FileSystemCopy ¶
FileSystemCopy template command to copy files, directories and to pass --include XXX and --exclude YYY regular expressions. Files ending in .tmpl will be processed as a template. Files ending in .table.tmpl will be processed as a template iterating through all the tables
func (*Config) GenerateFieldsTypes ¶
func (c *Config) GenerateFieldsTypes(dbMeta DbTableMeta) ([]*FieldInfo, error)
GenerateFieldsTypes FieldInfo slice from DbTableMeta
func (*Config) GenerateFile ¶
func (c *Config) GenerateFile(templateFilename, outputDirectory, outputFileName string, overwrite bool) string
GenerateFile generate file from template, non table used within templates
func (*Config) GenerateTableFile ¶
func (c *Config) GenerateTableFile(tableName, templateFilename, outputDirectory, outputFileName string) string
GenerateTableFile generate file from template using specific table used within templates
func (*Config) GetTemplate ¶
func (c *Config) GetTemplate(genTemplate *GenTemplate) (*template.Template, error)
GetTemplate return a Template based on a name and template contents
func (*Config) JSONFieldName ¶
JSONFieldName convert name to appropriate case
func (*Config) JSONTagOmitEmpty ¶
JSONTagOmitEmpty converts name to JSON tag with omitempty
func (*Config) LoadFragments ¶
LoadFragments read all filed inside dirname to `fragments`
func (*Config) ReplaceFieldNamingTemplate ¶
ReplaceFieldNamingTemplate use the FieldNamingTemplate to format a table name
func (*Config) ReplaceFileNamingTemplate ¶
ReplaceFileNamingTemplate use the FileNamingTemplate to format a table name
func (*Config) ReplaceModelNamingTemplate ¶
ReplaceModelNamingTemplate use the ModelNamingTemplate to format a table name
func (*Config) WriteTemplate ¶
func (c *Config) WriteTemplate(genTemplate *GenTemplate, data map[string]interface{}, outputFile string) error
WriteTemplate write a template out
type DbTableMeta ¶
type DbTableMeta interface {
Columns() []ColumnMeta
SQLType() string
SQLDatabase() string
TableName() string
DDL() string
}
DbTableMeta table meta data
func LoadMsSQLMeta ¶
func LoadMsSQLMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
LoadMsSQLMeta fetch db meta data for MS SQL database
func LoadMysqlMeta ¶
func LoadMysqlMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
LoadMysqlMeta fetch db meta data for MySQL database
func LoadPostgresMeta ¶
func LoadPostgresMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
LoadPostgresMeta fetch db meta data for Postgres database
func LoadSqliteMeta ¶
func LoadSqliteMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
LoadSqliteMeta fetch db meta data for Sqlite3 database
func LoadUnknownMeta ¶
func LoadUnknownMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
LoadUnknownMeta fetch db meta data for unknown database type
type FieldInfo ¶
type FieldInfo struct {
Index int
GoFieldName string
GoFieldType string
GoAnnotations []string
JSONFieldName string
ProtobufFieldName string
ProtobufType string
ProtobufPos int
Comment string
Notes string
Code string
FakeData interface{}
ColumnMeta ColumnMeta
PrimaryKeyFieldParser string
PrimaryKeyArgName string
SQLMapping *SQLMapping
GormAnnotation string
JSONAnnotation string
XMLAnnotation string
DBAnnotation string
GoGoMoreTags string
}
FieldInfo codegen info for each column in sql table
type GenTemplate ¶
GenTemplate template info struct
type InformationSchema ¶
type InformationSchema struct {
TableCatalog string
TableSchema string
TableName string
OrdinalPosition int
ColumnName string
DataType string
CharacterMaximumLength interface{}
ColumnDefault interface{}
IsNullable string
}
InformationSchema results from a query of the InformationSchema db table
type ModelInfo ¶
type ModelInfo struct {
Index int
IndexPlus1 int
PackageName string
StructName string
ShortStructName string
TableName string
Fields []string
DBMeta DbTableMeta
Instance interface{}
CodeFields []*FieldInfo
}
ModelInfo info for a sql table
func GenerateModelInfo ¶
func GenerateModelInfo(tables map[string]*ModelInfo, dbMeta DbTableMeta, tableName string, conf *Config) (*ModelInfo, error)
GenerateModelInfo generates a struct for the given table.
type PostgresInformationSchema ¶
type PostgresInformationSchema struct {
TableCatalog string
TableSchema string
TableName string
OrdinalPosition int
ColumnName string
DataType string
CharacterMaximumLength interface{}
ColumnDefault interface{}
IsNullable string
IsIdentity string
PrimaryKey bool
HasDefaultNextval bool
}
PostgresInformationSchema results from a query of the postgres InformationSchema db table
type SQLMapping ¶
type SQLMapping struct {
// SQLType sql type reported from db
SQLType string `json:"sql_type"`
// GoType mapped go type
GoType string `json:"go_type"`
// JSONType mapped json type
JSONType string `json:"json_type"`
// ProtobufType mapped protobuf type
ProtobufType string `json:"protobuf_type"`
// GureguType mapped go type using Guregu
GureguType string `json:"guregu_type"`
// GoNullableType mapped go type using nullable
GoNullableType string `json:"go_nullable_type"`
// SwaggerType mapped type
SwaggerType string `json:"swagger_type"`
}
SQLMapping mapping
func SQLTypeToMapping ¶
func SQLTypeToMapping(sqlType string) (*SQLMapping, error)
SQLTypeToMapping retrieve a SQLMapping based on a sql type
func (*SQLMapping) String ¶
func (m *SQLMapping) String() interface{}
type SQLMappings ¶
type SQLMappings struct {
SQLMappings []*SQLMapping `json:"mappings"`
}
SQLMappings mappings for sql types to json, go etc
type State ¶
type State struct {
// contains filtered or unexported fields
}
State struct used for storing state in template parsing
type SwaggerInfoDetails ¶
type SwaggerInfoDetails struct {
Version string
Host string
BasePath string
Title string
Description string
TOS string
ContactName string
ContactURL string
ContactEmail string
}
SwaggerInfoDetails swagger details
type TemplateLoader ¶
type TemplateLoader func(filename string) (tpl *GenTemplate, err error)
TemplateLoader loader function to retrieve a template contents