Documentation ¶
Index ¶
- func BuildDefaultTableDDL(tableName string, cols []*columnMeta) string
- func BytesToString(bs []uint8) string
- 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 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 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 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) GenerateFieldsTypes(dbMeta DbTableMeta) ([]*FieldInfo, error)
- func (c *Config) GenerateFile(templateFilename, outDir, outputDirectory, outputFileName string, ...) string
- func (c *Config) GenerateTableFile(tableInfos map[string]*ModelInfo, ...) string
- func (c *Config) GetTemplate(name, t string) (*template.Template, error)
- func (c *Config) ReplaceFieldNamingTemplate(name string) string
- func (c *Config) ReplaceFileNamingTemplate(name string) string
- func (c *Config) ReplaceModelNamingTemplate(name string) string
- func (c *Config) WriteTemplate(name, templateStr string, data map[string]interface{}, outputFile string, ...)
- 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 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 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 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 ¶
func GenerateDeleteSql ¶
func GenerateDeleteSql(dbTable DbTableMeta) (string, error)
GenerateDeleteSql generate sql for a delete
func GenerateInsertSql ¶
func GenerateInsertSql(dbTable DbTableMeta) (string, error)
GenerateInsertSql generate sql for a insert
func GenerateSelectMultiSql ¶
func GenerateSelectMultiSql(dbTable DbTableMeta) (string, error)
GenerateSelectMultiSql generate sql for selecting multiple records
func GenerateSelectOneSql ¶
func GenerateSelectOneSql(dbTable DbTableMeta) (string, error)
GenerateSelectOneSql generate sql for selecting one record
func GenerateUpdateSql ¶
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 ¶
func GetFunctionName(i interface{}) string
func LoadMappings ¶
LoadMappings load sql mappings to load mapping json file
func LoadTableInfo ¶
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 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 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 Verbose bool OutDir string Overwrite bool CmdLine string CmdLineWrapped string CmdLineArgs []string FileNamingTemplate string ModelNamingTemplate string FieldNamingTemplate string ContextMap map[string]interface{} TemplateLoader TemplateLoader // contains filtered or unexported fields }
func NewConfig ¶
func NewConfig(templateLoader TemplateLoader) *Config
func (*Config) CreateContextForTableFile ¶
func (*Config) GenerateFieldsTypes ¶
func (c *Config) GenerateFieldsTypes(dbMeta DbTableMeta) ([]*FieldInfo, error)
Generate fields string
func (*Config) GenerateFile ¶
func (c *Config) GenerateFile(templateFilename, outDir, outputDirectory, outputFileName string, formatOutput bool, overwrite bool) string
GenerateFile generate file from template, non table used within templates
func (*Config) GenerateTableFile ¶
func (c *Config) GenerateTableFile(tableInfos map[string]*ModelInfo, tableName, templateFilename, outputDirectory, outputFileName string, formatOutput bool) string
GenerateTableFile generate file from template using specific table used within templates
func (*Config) GetTemplate ¶
func (*Config) ReplaceFieldNamingTemplate ¶
func (*Config) ReplaceFileNamingTemplate ¶
func (*Config) ReplaceModelNamingTemplate ¶
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 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 }
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