-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathvalue.go
58 lines (56 loc) · 1.55 KB
/
value.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
package duckdb
import (
"github.com/marcboeker/go-duckdb/mapping"
)
func getValue(info TypeInfo, v mapping.Value) (any, error) {
t := info.InternalType()
switch t {
case TYPE_BOOLEAN:
return mapping.GetBool(v), nil
case TYPE_TINYINT:
return mapping.GetInt8(v), nil
case TYPE_SMALLINT:
return mapping.GetInt16(v), nil
case TYPE_INTEGER:
return mapping.GetInt32(v), nil
case TYPE_BIGINT:
return mapping.GetInt64(v), nil
case TYPE_UTINYINT:
return mapping.GetUInt8(v), nil
case TYPE_USMALLINT:
return mapping.GetUInt16(v), nil
case TYPE_UINTEGER:
return mapping.GetUInt32(v), nil
case TYPE_UBIGINT:
return mapping.GetUInt64(v), nil
case TYPE_FLOAT:
return mapping.GetFloat(v), nil
case TYPE_DOUBLE:
return mapping.GetDouble(v), nil
case TYPE_TIMESTAMP_S, TYPE_TIMESTAMP_MS, TYPE_TIMESTAMP_NS:
// DuckDB's C API does not yet support get_timestamp_s|ms|ns.
return nil, unsupportedTypeError(typeToStringMap[t])
case TYPE_TIMESTAMP, TYPE_TIMESTAMP_TZ:
ts := mapping.GetTimestamp(v)
return getTS(t, &ts), nil
case TYPE_DATE:
date := mapping.GetDate(v)
return getDate(&date), nil
case TYPE_TIME:
ti := mapping.GetTime(v)
return getTime(&ti), nil
case TYPE_TIME_TZ:
ti := mapping.GetTimeTZ(v)
return getTimeTZ(&ti), nil
case TYPE_INTERVAL:
interval := mapping.GetInterval(v)
return getInterval(&interval), nil
case TYPE_HUGEINT:
hugeInt := mapping.GetHugeInt(v)
return hugeIntToNative(&hugeInt), nil
case TYPE_VARCHAR:
return mapping.GetVarchar(v), nil
default:
return nil, unsupportedTypeError(typeToStringMap[t])
}
}