Documentation
¶
Index ¶
- Variables
- func GetValidSqlType(sqlType string) (length int, ok bool)
- func IsValidSqlType(sqlType string) bool
- func MatchType(driver string, goType string) (string, int, error)
- func NormalizeDriverName(driver string) string
- type ColumnOptions
- func (options *ColumnOptions) ReadAttr(input string, names ...string) (string, bool)
- func (options *ColumnOptions) ReadAutoIncrement(input string) bool
- func (options *ColumnOptions) ReadDefaultValue(input string) bool
- func (options *ColumnOptions) ReadName(input string) bool
- func (options *ColumnOptions) ReadTableName(input string) bool
- func (options *ColumnOptions) ReadType(input string) bool
- func (options *ColumnOptions) ReadTypeAttr(input string) bool
Constants ¶
This section is empty.
Variables ¶
View Source
var TypeDict = map[string]map[string]string{
"postgres": {
"float32": "DOUBLE PRECISION",
"float64": "DOUBLE PRECISION",
"int": "INTEGER",
"uint": "INTEGER",
"int64": "BIGINT",
"uint64": "BIGINT",
"string": "VARCHAR",
"time.Time": "TIMESTAMP",
"bool": "BOOLEAN",
"[]byte": "BYTEA",
"[]uint8": "BYTEA",
"sql.NullFloat32": "DOUBLE PRECISION",
"sql.NullFloat64": "DOUBLE PRECISION",
"sql.NullInt64": "BIGINT",
"sql.NullString": "VARCHAR",
"sql.NullBool": "BOOLEAN",
},
"mysql": {
"float32": "float",
"float64": "float",
"int": "int",
"uint": "int",
"int64": "bigint",
"uint64": "bigint",
"string": "varchar",
"time.Time": "timestamp",
"bool": "tinyint",
"[]byte": "blob",
"[]uint8": "blob",
"sql.NullFloat32": "float",
"sql.NullFloat64": "float",
"sql.NullInt64": "bigint",
"sql.NullString": "varchar",
"sql.NullBool": "tinyint",
},
}
View Source
var TypeLength = map[string]map[string]int{
"postgres": {
"VARCHAR": 255,
},
"mysql": {
"int": 11,
"uint": 11,
"int64": 20,
"uint64": 20,
"string": 255,
"bigint": 20,
"varchar": 255,
"sql.NullInt64": 20,
"sql.NullString": 255,
},
}
View Source
var ValidMySQLTypes = map[string]int{
"int": 11,
"bigint": 20,
"varchar": 255,
"text": -1,
"date": -1,
"time": -1,
"timestamp": -1,
}
View Source
var ValidPostgresTypes = map[string]int{
"integer": -1,
"bigint": -1,
"varchar": 255,
"text": -1,
"timestamp": -1,
"boolean": -1,
"bytea": -1,
"double precision": -1,
}
Functions ¶
func GetValidSqlType ¶
func IsValidSqlType ¶
IsValidSqlType checks if a SQL type is valid for either MySQL or PostgreSQL. The input is converted to lowercase before checking.
func NormalizeDriverName ¶
Types ¶
type ColumnOptions ¶
type ColumnOptions struct {
Name string
Type string
Length int
DefaultValue string
AutoIncrement int
IsAutoIncrementing bool
IsPrimaryKey bool
Serial bool
IsUnique bool
IsUnsigned bool
IsRequired bool
Ignore bool
TableName string
CurrentTimestamp bool
}
func NewColumnOptions ¶
func NewColumnOptions(input string) (*ColumnOptions, error)
func (*ColumnOptions) ReadAttr ¶
func (options *ColumnOptions) ReadAttr(input string, names ...string) (string, bool)
func (*ColumnOptions) ReadAutoIncrement ¶
func (options *ColumnOptions) ReadAutoIncrement(input string) bool
func (*ColumnOptions) ReadDefaultValue ¶
func (options *ColumnOptions) ReadDefaultValue(input string) bool
func (*ColumnOptions) ReadName ¶
func (options *ColumnOptions) ReadName(input string) bool
func (*ColumnOptions) ReadTableName ¶
func (options *ColumnOptions) ReadTableName(input string) bool
func (*ColumnOptions) ReadType ¶
func (options *ColumnOptions) ReadType(input string) bool
func (*ColumnOptions) ReadTypeAttr ¶
func (options *ColumnOptions) ReadTypeAttr(input string) bool
Click to show internal directories.
Click to hide internal directories.