forked from sdming/kdb
/
schema.go
138 lines (101 loc) · 1.98 KB
/
schema.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package ansi
import (
"fmt"
)
// DbTable is schema of table
type DbTable struct {
// Name is table name
Name string
// Catalog is catalog name
Catalog string
// Schema is schema name
Schema string
// Type is table,view,...
Type string
// Columns is columns of this table
Columns []DbColumn
}
func (t *DbTable) String() string {
if t == nil {
return "<nil>"
}
return fmt.Sprintf("%#v", t)
}
func NewTable() *DbTable {
return &DbTable{
Columns: make([]DbColumn, 0, 11),
}
}
// DbColumn is schema of column
type DbColumn struct {
// Name is column name
Name string
// Position is position in table
Position int
// DbType is data type of this column
DbType DbType
// NativeType is native data type
NativeType string
// Precision
Precision int
// Scale
Scale int
// Size
Size int
// IsNullable
IsNullable bool
// IsAutoIncrement
IsAutoIncrement bool
// IsReadOnly
IsReadOnly bool
// IsPrimaryKey
IsPrimaryKey bool
}
// DbFunction is schema of procedure / function
type DbFunction struct {
// Name is name of procedure
Name string
// Catalog
Catalog string
// Schema
Schema string
// Parameters is parameters of this procedure
Parameters []DbParameter
}
func (f *DbFunction) String() string {
if f == nil {
return "<nil>"
}
return fmt.Sprintf("%#v", f)
}
func NewFunction() *DbFunction {
return &DbFunction{
Parameters: make([]DbParameter, 0, 11),
}
}
// DbParameter is schema of procedure parameter
type DbParameter struct {
// Name
Name string
// Position is position in procedure
Position int
// DbType is data type of parameter
DbType DbType
// NativeType is native data type
NativeType string
// Dir is parameter direction
Dir Dir
// Precision
Precision int
// Scale
Scale int
// Size
Size int
}
// Schemaer is interface of database schema provider
type Schemaer interface {
// Table return schema of table
Table(name string) DbTable
// Procedure return schema of procedure
Procedure(name string) DbTable
}