goType takes a SQL type and returns a string containin the name of a Go type. The goal is not to provide an exact match for every type, but to provide a safe Go representation of a SQL type. For some floating point SQL types, for example, we store them as strings so as not to lose precision while
(sqlType string)
| 296 | // |
| 297 | // The default type is string. |
| 298 | func goType(sqlType string) string { |
| 299 | switch sqlType { |
| 300 | case "smallint", "smallserial": |
| 301 | return "int16" |
| 302 | case "integer", "serial": |
| 303 | return "int32" |
| 304 | case "bigint", "bigserial": |
| 305 | return "int" |
| 306 | case "real": |
| 307 | return "float32" |
| 308 | case "double precision": |
| 309 | return "float64" |
| 310 | // Because we need to preserve base-10 precision. |
| 311 | case "money": |
| 312 | return "string" |
| 313 | case "text", "varchar", "char", "character", "character varying", "uuid": |
| 314 | return "string" |
| 315 | case "bytea": |
| 316 | return "[]byte" |
| 317 | case "boolean": |
| 318 | return "bool" |
| 319 | case "timezone", "timezonetz", "date", "time": |
| 320 | return "time.Time" |
| 321 | case "interval": |
| 322 | return "time.Duration" |
| 323 | } |
| 324 | return "string" |
| 325 | } |
| 326 | |
| 327 | // Convert a SQL name to a Go name. |
| 328 | func goName(sqlName string) string { |