-
Notifications
You must be signed in to change notification settings - Fork 0
/
type.go
66 lines (52 loc) · 1.05 KB
/
type.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
65
66
package slicetable
import (
"fmt"
"reflect"
"time"
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/types"
)
var (
timeType = reflect.TypeFor[time.Time]()
bytesSliceType = reflect.TypeFor[[]byte]()
)
func goTypeToSQLType(t reflect.Type) sql.Type {
switch t {
case timeType:
return types.Time
case bytesSliceType:
return types.Blob
}
switch t.Kind() {
case reflect.Int:
return types.Int64
case reflect.Int8:
return types.Int8
case reflect.Int16:
return types.Int16
case reflect.Int32:
return types.Int32
case reflect.Int64:
return types.Int64
case reflect.Uint:
return types.Uint64
case reflect.Uint8:
return types.Uint8
case reflect.Uint16:
return types.Uint16
case reflect.Uint32:
return types.Uint32
case reflect.Uint64:
return types.Uint64
case reflect.Float32:
return types.Float32
case reflect.Float64:
return types.Float64
case reflect.String:
return types.Text
case reflect.Struct:
return types.JSON
default:
panic(fmt.Sprintf("unknown type: %v", t))
}
}