forked from go-reform/reform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_init_postgres.go
42 lines (33 loc) · 1.34 KB
/
cmd_init_postgres.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"fmt"
)
// goTypePostgres converts given SQL type to Go type. https://www.postgresql.org/docs/current/static/datatype.html
func goTypePostgres(sqlType string, nullable bool) (typ string, pack string, comment string) {
switch sqlType {
case "smallint", "smallserial":
return maybePointer("int16", nullable), "", ""
case "integer", "serial":
return maybePointer("int32", nullable), "", ""
case "bigint", "bigserial":
return maybePointer("int64", nullable), "", ""
case "decimal", "numeric":
return maybePointer("string", nullable), "", ""
case "real":
return maybePointer("float32", nullable), "", ""
case "double precision":
return maybePointer("float64", nullable), "", ""
case "character varying", "varchar", "character", "char", "text":
return maybePointer("string", nullable), "", ""
case "bytea":
return "[]byte", "", "" // never a pointer
case "date", "time", "time with time zone", "timestamp", "timestamp with time zone":
return maybePointer("time.Time", nullable), "time", ""
// interval can't be mapped to time.Duration: https://github.com/lib/pq/issues/78
case "boolean":
return maybePointer("bool", nullable), "", ""
default:
// logger.Fatalf("unhandled PostgreSQL type %q", sqlType)
return "[]byte", "", fmt.Sprintf("// FIXME unhandled database type %q", sqlType) // never a pointer
}
}