forked from yandex-cloud/ydb-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype.go
107 lines (92 loc) · 2.23 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package ydb
import (
"fmt"
"github.com/yandex-cloud/ydb-go-sdk/internal"
)
// Type describes YDB data type.
type Type interface {
internal.T
}
func List(T Type) Type {
return internal.ListType{T: T}
}
func Tuple(elems ...Type) Type {
es := make([]internal.T, len(elems))
for i, el := range elems {
es[i] = el
}
return internal.TupleType{
Elems: es,
}
}
type tStructType internal.StructType
type StructOption func(*tStructType)
func StructField(name string, typ Type) StructOption {
return func(s *tStructType) {
s.Fields = append(s.Fields, internal.StructField{
Name: name,
Type: typ,
})
}
}
func Struct(opts ...StructOption) Type {
var s tStructType
for _, opt := range opts {
opt(&s)
}
return internal.StructType(s)
}
func Variant(x Type) Type {
switch v := x.(type) {
case internal.TupleType:
return internal.VariantType{
T: v,
}
case internal.StructType:
return internal.VariantType{
S: v,
}
default:
panic(fmt.Sprintf("unsupported type for variant: %s", v))
}
}
func Void() Type {
return internal.VoidType{}
}
func Optional(T Type) Type {
return internal.OptionalType{T: T}
}
var DefaultDecimal = Decimal(22, 9)
func Decimal(precision, scale uint32) Type {
return internal.DecimalType{
Precision: precision,
Scale: scale,
}
}
// Primitive types known by YDB.
const (
TypeUnknown = internal.TypeUnknown
TypeBool = internal.TypeBool
TypeInt8 = internal.TypeInt8
TypeUint8 = internal.TypeUint8
TypeInt16 = internal.TypeInt16
TypeUint16 = internal.TypeUint16
TypeInt32 = internal.TypeInt32
TypeUint32 = internal.TypeUint32
TypeInt64 = internal.TypeInt64
TypeUint64 = internal.TypeUint64
TypeFloat = internal.TypeFloat
TypeDouble = internal.TypeDouble
TypeDate = internal.TypeDate
TypeDatetime = internal.TypeDatetime
TypeTimestamp = internal.TypeTimestamp
TypeInterval = internal.TypeInterval
TypeTzDate = internal.TypeTzDate
TypeTzDatetime = internal.TypeTzDatetime
TypeTzTimestamp = internal.TypeTzTimestamp
TypeString = internal.TypeString
TypeUTF8 = internal.TypeUTF8
TypeYSON = internal.TypeYSON
TypeJSON = internal.TypeJSON
TypeUUID = internal.TypeUUID
)