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 FindPrimaryKeyFromInformationSchema(db *sql.DB, tableName string) (primaryKey string, err error)
- func FmtFieldName(s string) string
- func FormatSource(s string) string
- func GenerateDeleteSQL(dbTable DbTableMeta) (string, error)
- func GenerateInsertSQL(dbTable DbTableMeta) (string, error)
- func GenerateSelectMultiSQL(dbTable DbTableMeta) (string, error)
- func GenerateSelectOneSQL(dbTable DbTableMeta) (string, error)
- func GenerateUpdateSQL(dbTable DbTableMeta) (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 CRLFNewlines ¶ added in v0.9.19
CRLFNewlines transforms \n to \r\n (windows)
func CheckForDupeTable ¶ added in v0.9.12
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 ¶ added in v0.9.7
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 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 FormatSource ¶ added in v0.9.7
FormatSource format source code contents
func GenerateDeleteSQL ¶ added in v0.9.15
func GenerateDeleteSQL(dbTable DbTableMeta) (string, error)
GenerateDeleteSQL generate sql for a delete
func GenerateInsertSQL ¶ added in v0.9.15
func GenerateInsertSQL(dbTable DbTableMeta) (string, error)
GenerateInsertSQL generate sql for a insert
func GenerateSelectMultiSQL ¶ added in v0.9.15
func GenerateSelectMultiSQL(dbTable DbTableMeta) (string, error)
GenerateSelectMultiSQL generate sql for selecting multiple records
func GenerateSelectOneSQL ¶ added in v0.9.15
func GenerateSelectOneSQL(dbTable DbTableMeta) (string, error)
GenerateSelectOneSQL generate sql for selecting one record
func GenerateUpdateSQL ¶ added in v0.9.15
func GenerateUpdateSQL(dbTable DbTableMeta) (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 GetFunctionName ¶ added in v0.9.10
func GetFunctionName(i interface{}) string
GetFunctionName get function name
func InitColorOutput ¶ added in v0.9.27
func LoadMappings ¶
LoadMappings load sql mappings to load mapping json file
func LoadTableInfo ¶ added in v0.9.7
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 ¶ added in v0.9.7
func NonPrimaryKeyNames(dbTable DbTableMeta) []string
NonPrimaryKeyNames return the list of primary key names
func NormalizeNewlines ¶ added in v0.9.19
NormalizeNewlines normalizes \r\n (windows) and \r (mac) into \n (unix)
func ParseSQLType ¶ added in v0.9.1
ParseSQLType parse sql type and return raw type and length
func PrimaryKeyCount ¶ added in v0.9.7
func PrimaryKeyCount(dbTable DbTableMeta) int
PrimaryKeyCount return the number of primary keys in table
func PrimaryKeyNames ¶ added in v0.9.7
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 Pwd ¶ added in v0.9.26
func Pwd() string
Pwd template command to return the current working directory
func RenameReservedName ¶ added in v0.9.7
RenameReservedName renames a reserved word
func Replace ¶ added in v0.9.10
Replace takes a template based name format and will render a name using it
func SQLTypeToGoType ¶ added in v0.9.1
SQLTypeToGoType map a sql type to a go type
func SQLTypeToProtobufType ¶ added in v0.9.1
SQLTypeToProtobufType map a sql type to a protobuf type
func Spew ¶ added in v0.9.7
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 ¶ added in v0.9.7
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 ¶ added in v0.9.7
func NewConfig(templateLoader TemplateLoader) *Config
NewConfig create a new code config
func (*Config) CreateContextForTableFile ¶ added in v0.9.7
CreateContextForTableFile create map context for a db table
func (*Config) DisplayConfig ¶ added in v0.9.27
DisplayConfig display config info
func (*Config) FileSystemCopy ¶ added in v0.9.27
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 ¶ added in v0.9.7
func (c *Config) GenerateFieldsTypes(dbMeta DbTableMeta) ([]*FieldInfo, error)
GenerateFieldsTypes FieldInfo slice from DbTableMeta
func (*Config) GenerateFile ¶ added in v0.9.7
func (c *Config) GenerateFile(templateFilename, outputDirectory, outputFileName string, overwrite bool) string
GenerateFile generate file from template, non table used within templates
func (*Config) GenerateTableFile ¶ added in v0.9.7
func (c *Config) GenerateTableFile(tableName, templateFilename, outputDirectory, outputFileName string) string
GenerateTableFile generate file from template using specific table used within templates
func (*Config) GetTemplate ¶ added in v0.9.7
func (c *Config) GetTemplate(genTemplate *GenTemplate) (*template.Template, error)
GetTemplate return a Template based on a name and template contents
func (*Config) JSONFieldName ¶ added in v0.9.25
JSONFieldName convert name to appropriate case
func (*Config) JSONTag ¶ added in v0.9.25
JSONTag converts name to `json:"name"` respecting json-fmt option
func (*Config) JSONTagOmitEmpty ¶ added in v0.9.25
JSONTagOmitEmpty converts name to JSON tag with omitempty
func (*Config) LoadFragments ¶ added in v0.9.28
LoadFragments read all filed inside dirname to `fragments`
func (*Config) ReplaceFieldNamingTemplate ¶ added in v0.9.11
ReplaceFieldNamingTemplate use the FieldNamingTemplate to format a table name
func (*Config) ReplaceFileNamingTemplate ¶ added in v0.9.11
ReplaceFileNamingTemplate use the FileNamingTemplate to format a table name
func (*Config) ReplaceModelNamingTemplate ¶ added in v0.9.11
ReplaceModelNamingTemplate use the ModelNamingTemplate to format a table name
func (*Config) Touch ¶ added in v0.9.27
Touch template command to touch a file under the output directory
func (*Config) WriteTemplate ¶ added in v0.9.7
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 ¶ added in v0.9.2
func LoadMsSQLMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
LoadMsSQLMeta fetch db meta data for MS SQL database
func LoadMysqlMeta ¶ added in v0.9.2
func LoadMysqlMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
LoadMysqlMeta fetch db meta data for MySQL database
func LoadPostgresMeta ¶ added in v0.9.2
func LoadPostgresMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
LoadPostgresMeta fetch db meta data for Postgres database
func LoadSqliteMeta ¶ added in v0.9.2
func LoadSqliteMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
LoadSqliteMeta fetch db meta data for Sqlite3 database
func LoadUnknownMeta ¶ added in v0.9.2
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 ¶ added in v0.9.17
GenTemplate template info struct
type InformationSchema ¶ added in v0.9.1
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 ¶ added in v0.9.7
func GenerateModelInfo(tables map[string]*ModelInfo, dbMeta DbTableMeta, tableName string, conf *Config) (*ModelInfo, error)
GenerateModelInfo generates a struct for the given table.
type PostgresInformationSchema ¶ added in v0.9.1
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 }
PostgresInformationSchema results from a query of the postgres InformationSchema db table
type SQLMapping ¶ added in v0.9.1
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 ¶ added in v0.9.1
func SQLTypeToMapping(sqlType string) (*SQLMapping, error)
SQLTypeToMapping retrieve a SQLMapping based on a sql type
func (*SQLMapping) String ¶ added in v0.9.7
func (m *SQLMapping) String() interface{}
type SQLMappings ¶ added in v0.9.1
type SQLMappings struct {
SQLMappings []*SQLMapping `json:"mappings"`
}
SQLMappings mappings for sql types to json, go etc
type State ¶ added in v0.9.7
type State struct {
// contains filtered or unexported fields
}
State struct used for storing state in template parsing
type SwaggerInfoDetails ¶ added in v0.9.7
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 ¶ added in v0.9.7
type TemplateLoader func(filename string) (tpl *GenTemplate, err error)
TemplateLoader loader function to retrieve a template contents