/
mappings.go
64 lines (60 loc) · 1.87 KB
/
mappings.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package redshift
import (
"strconv"
)
var columnTypeMappings = map[string]string{
"int": "int",
"int2": "int",
"int4": "int",
"int8": "int",
"integer": "int",
"smallint": "int",
"bigint": "int",
"real": "float",
"float": "float",
"float4": "float",
"float8": "float",
"numeric": "float",
"double precision": "float",
"boolean": "boolean",
"bool": "boolean",
"text": "string",
"varchar": "string",
"character varying": "string",
"nchar": "string",
"bpchar": "string",
"character": "string",
"nvarchar": "string",
"string": "string",
"date": "datetime",
"time": "datetime",
"time without time zone": "datetime",
"time with time zone": "datetime",
"timetz": "datetime",
"timestamptz": "datetime",
"timestamp without time zone": "datetime",
"timestamp with time zone": "datetime",
"timestamp": "datetime",
}
// jsonRowMapper maps a row's scanned column to a json object's field
func jsonRowMapper(databaseTypeName string, value any) any {
switch databaseTypeName {
case "NUMERIC":
switch v := value.(type) {
case []byte:
if n, err := strconv.ParseFloat(string(v), 64); err == nil {
return n
}
case string:
if n, err := strconv.ParseFloat(v, 64); err == nil {
return n
}
}
default:
switch v := value.(type) {
case []byte:
return string(v)
}
}
return value
}