forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
108 lines (88 loc) · 1.87 KB
/
types.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
108
package migrator
import (
"fmt"
"strings"
)
const (
POSTGRES = "postgres"
SQLITE = "sqlite3"
MYSQL = "mysql"
)
type Migration interface {
Sql(dialect Dialect) string
Id() string
SetId(string)
GetCondition() MigrationCondition
}
type SQLType string
type ColumnType string
const (
DB_TYPE_STRING ColumnType = "String"
)
type Table struct {
Name string
Columns []*Column
PrimaryKeys []string
Indices []*Index
}
const (
IndexType = iota + 1
UniqueIndex
)
type Index struct {
Name string
Type int
Cols []string
}
func (index *Index) XName(tableName string) string {
if index.Name == "" {
index.Name = fmt.Sprintf("%s", strings.Join(index.Cols, "_"))
}
if !strings.HasPrefix(index.Name, "UQE_") &&
!strings.HasPrefix(index.Name, "IDX_") {
if index.Type == UniqueIndex {
return fmt.Sprintf("UQE_%v_%v", tableName, index.Name)
}
return fmt.Sprintf("IDX_%v_%v", tableName, index.Name)
}
return index.Name
}
var (
DB_Bit = "BIT"
DB_TinyInt = "TINYINT"
DB_SmallInt = "SMALLINT"
DB_MediumInt = "MEDIUMINT"
DB_Int = "INT"
DB_Integer = "INTEGER"
DB_BigInt = "BIGINT"
DB_Enum = "ENUM"
DB_Set = "SET"
DB_Char = "CHAR"
DB_Varchar = "VARCHAR"
DB_NVarchar = "NVARCHAR"
DB_TinyText = "TINYTEXT"
DB_Text = "TEXT"
DB_MediumText = "MEDIUMTEXT"
DB_LongText = "LONGTEXT"
DB_Uuid = "UUID"
DB_Date = "DATE"
DB_DateTime = "DATETIME"
DB_Time = "TIME"
DB_TimeStamp = "TIMESTAMP"
DB_TimeStampz = "TIMESTAMPZ"
DB_Decimal = "DECIMAL"
DB_Numeric = "NUMERIC"
DB_Real = "REAL"
DB_Float = "FLOAT"
DB_Double = "DOUBLE"
DB_Binary = "BINARY"
DB_VarBinary = "VARBINARY"
DB_TinyBlob = "TINYBLOB"
DB_Blob = "BLOB"
DB_MediumBlob = "MEDIUMBLOB"
DB_LongBlob = "LONGBLOB"
DB_Bytea = "BYTEA"
DB_Bool = "BOOL"
DB_Serial = "SERIAL"
DB_BigSerial = "BIGSERIAL"
)