Documentation
¶
Index ¶
- func BuildDefaultTableDDL(tableName string, cols []ColumnMeta) string
- func BytesToString(bs []uint8) string
- func Copy(dst interface{}, src interface{}) error
- func FindPrimaryKeyFromInformationSchema(db *sql.DB, tableName string) (primaryKey string, err error)
- func FmtFieldName(s string) string
- func GetFieldLenFromInformationSchema(db *sql.DB, tableSchema, tableName, columnName string) (int64, error)
- func GetMappings() map[string]*SQLMapping
- func LoadMappings(mappingFileName string) error
- 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 ParseSQLType(dbType string) (resultType string, dbTypeLen int64)
- func ProcessMappings(mappingJsonstring []byte) error
- func SQLTypeToGoType(sqlType string, nullable bool, gureguTypes bool) (string, error)
- func SQLTypeToProtobufType(sqlType string) (string, error)
- func TrimSpaceNewlineInString(s string) string
- type ColumnMeta
- type DbTableMeta
- func LoadMeta(sqlType string, db *sql.DB, sqlDatabase, tableName string) (DbTableMeta, error)
- func NewMsSQLMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
- func NewMysqlMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
- func NewPostgresMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
- func NewSqliteMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
- func NewUnknownMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
- type FieldInfo
- type InformationSchema
- type ModelInfo
- type PostgresInformationSchema
- type SQLMapping
- type SQLMappings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildDefaultTableDDL ¶
func BuildDefaultTableDDL(tableName string, cols []ColumnMeta) string
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 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 GetFieldLenFromInformationSchema ¶
func GetFieldLenFromInformationSchema(db *sql.DB, tableSchema, tableName, columnName string) (int64, error)
GetFieldLenFromInformationSchema fetch field length from database
func LoadMappings ¶
LoadMappings load sql mappings to load mapping json file
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 ParseSQLType ¶ added in v0.9.1
ParseSQLType parse sql type and return raw type and length
func ProcessMappings ¶
ProcessMappings process the json for mappings to load sql mappings
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 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
ColumnType() string
ColumnLength() int64
DefaultValue() string
}
ColumnMeta meta data for a column
type DbTableMeta ¶
type DbTableMeta interface {
Columns() []ColumnMeta
SQLType() string
SQLDatabase() string
TableName() string
DDL() string
}
DbTableMeta table meta data
func NewMsSQLMeta ¶ added in v0.9.1
func NewMsSQLMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
NewMsSQLMeta fetch db meta data for MS SQL database
func NewMysqlMeta ¶
func NewMysqlMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
NewMysqlMeta fetch db meta data for MySQL database
func NewPostgresMeta ¶
func NewPostgresMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
NewPostgresMeta fetch db meta data for Postgres database
func NewSqliteMeta ¶
func NewSqliteMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
NewSqliteMeta fetch db meta data for Sqlite3 database
func NewUnknownMeta ¶
func NewUnknownMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)
NewUnknownMeta 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
Code string
FakeData interface{}
ColumnMeta ColumnMeta
}
FieldInfo info for each field in sql table
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
PrimaryKeyField int
PrimaryKeyGoType string
PrimaryKeyFieldParser string
}
ModelInfo info for a sql table
func GenerateStruct ¶
func GenerateStruct(sqlType string, db *sql.DB, sqlDatabase, tableName string, structName string, pkgName string, addJSONAnnotation bool, addGormAnnotation bool, addDBAnnotation bool, addProtobufAnnotation bool, gureguTypes bool, jsonNameFormat string, protobufNameFormat string, verbose bool) (*ModelInfo, error)
GenerateStruct 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
}
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"`
}
SQLMapping mapping
func SQLTypeToMapping ¶ added in v0.9.1
func SQLTypeToMapping(sqlType string) (*SQLMapping, error)
SQLTypeToMapping retrieve a SqlMapping based on a sql type
type SQLMappings ¶ added in v0.9.1
type SQLMappings struct {
SQLMappings []*SQLMapping `json:"mappings"`
}
SQLMappings mappings for sql types to json, go etc