-
Notifications
You must be signed in to change notification settings - Fork 1
/
type.go
59 lines (50 loc) · 1.35 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
package cuckle
import (
"fmt"
"strings"
)
// Type is a type.
type Type string
// Built-in types.
const (
TypeAscii Type = "ascii"
TypeBigint Type = "bigint"
TypeBlob Type = "blob"
TypeBoolean Type = "boolean"
TypeCounter Type = "counter"
TypeDate Type = "date"
TypeDecimal Type = "decimal"
TypeDouble Type = "double"
TypeFloat Type = "float"
TypeInet Type = "inet"
TypeInt Type = "int"
TypeSmallint Type = "smallint"
TypeText Type = "text"
TypeTime Type = "time"
TypeTimestamp Type = "timestamp"
TypeTimeuuid Type = "timeuuid"
TypeTinyint Type = "tinyint"
TypeUuid Type = "uuid"
TypeVarchar Type = "varchar"
TypeVarint Type = "varint"
)
// TypeList returns a Type for a list of element.
func TypeList(element Type) Type {
return Type(fmt.Sprintf("list<%v>", element))
}
// TypeMap returns a Type for a map from key to value.
func TypeMap(key, value Type) Type {
return Type(fmt.Sprintf("map<%v, %v>", key, value))
}
// TypeSet returns a Type for a set of element.
func TypeSet(element Type) Type {
return Type(fmt.Sprintf("set<%v>", element))
}
// TypleTuple returns a Type for a tuple of elements.
func TypeTuple(elements ...Type) Type {
var ss []string
for _, e := range elements {
ss = append(ss, string(e))
}
return Type(fmt.Sprintf("tuple<%v>", strings.Join(ss, ", ")))
}