-
Notifications
You must be signed in to change notification settings - Fork 2
/
numeric.go
70 lines (58 loc) · 1.18 KB
/
numeric.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
package types
type numeric struct {
BaseType
min, max int64
precision, scale int
}
var _ Type = numeric{}
func (t numeric) NotNull() numeric {
t.BaseType.NotNull()
return t
}
func (t numeric) Unique() numeric {
t.BaseType.Unique()
return t
}
func Decimal(precision, scale int) numeric {
// TODO variadic arguments, with all but the first two ignored?
datatype := Numeric(precision, scale)
datatype.BaseType.name = "DECIMAL"
return datatype
}
func Integer() numeric {
return numeric{
BaseType: Base("INTEGER"),
min: -2147483648,
max: 2147483647,
}
}
func SmallInt() numeric {
return numeric{
BaseType: Base("SMALLINT"),
min: -32768,
max: 32767,
}
}
func BigInt() numeric {
return numeric{
BaseType: Base("BIGINT"),
min: -9223372036854775808,
max: 9223372036854775807,
}
}
func Numeric(precision, scale int) numeric {
return numeric{
BaseType: Base("NUMERIC"),
precision: precision,
scale: scale,
}
}
func Float() numeric {
return numeric{BaseType: Base("FLOAT")}
}
func Real() numeric {
return numeric{BaseType: Base("REAL")}
}
func Double() numeric {
return numeric{BaseType: Base("DOUBLE PRECISION")}
}