Merge pull request #66 from ZhengYang/master

#65 added interval and uuid for postgres
This commit is contained in:
astaxie 2014-09-04 11:41:44 +08:00
commit 531ce3010d
1 changed files with 17 additions and 9 deletions

View File

@ -118,6 +118,7 @@ var typeMappingPostgres = map[string]string{
"time": "time.Time", "time": "time.Time",
"timestamp": "time.Time", "timestamp": "time.Time",
"timestamp without time zone": "time.Time", "timestamp without time zone": "time.Time",
"interval": "string", // time interval, string for now
"real": "float32", // float & decimal "real": "float32", // float & decimal
"double precision": "float64", "double precision": "float64",
"decimal": "float64", "decimal": "float64",
@ -127,6 +128,7 @@ var typeMappingPostgres = map[string]string{
"tsvector": "string", // fulltext "tsvector": "string", // fulltext
"ARRAY": "string", // array "ARRAY": "string", // array
"USER-DEFINED": "string", // user defined "USER-DEFINED": "string", // user defined
"uuid": "string", // uuid
} }
// Table represent a table in a database // Table represent a table in a database
@ -668,6 +670,9 @@ func (postgresDB *PostgresDB) GetColumns(db *sql.DB, table *Table, blackList map
if isSQLBinaryType(dataType) { if isSQLBinaryType(dataType) {
tag.Size = extractColSize(columnType) tag.Size = extractColSize(columnType)
} }
if isSQLStrangeType(dataType) {
tag.Type = dataType
}
} }
} }
col.Tag = tag col.Tag = tag
@ -914,6 +919,9 @@ func isSQLBinaryType(t string) bool {
func isSQLBitType(t string) bool { func isSQLBitType(t string) bool {
return t == "bit" return t == "bit"
} }
func isSQLStrangeType(t string) bool {
return t == "interval" || t == "uuid"
}
// extractColSize extracts field size: e.g. varchar(255) => 255 // extractColSize extracts field size: e.g. varchar(255) => 255
func extractColSize(colType string) string { func extractColSize(colType string) string {