MCPcopy Create free account
hub / github.com/Masterminds/structable / goType

Function goType

schema2struct/schema2struct.go:298–325  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

296//
297// The default type is string.
298func 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.
328func goName(sqlName string) string {

Callers 1

structFieldFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected