-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes.go
More file actions
57 lines (47 loc) · 931 Bytes
/
types.go
File metadata and controls
57 lines (47 loc) · 931 Bytes
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
package main
type Tables []Table
type Table struct {
Type string
Name string
Columns []Column
References []ForeignKey
}
type Column struct {
Name string
Type string
NotNull bool
Default interface{}
PrimaryKey bool
}
type ForeignKey struct {
Sequence int64
FromColumn string
ToTable string
ToColumn string
}
// Table performs a table lookup using the table's name
func (t Tables) Table(name string) (int, Table) {
for i := range t {
if t[i].Name == name {
return i, t[i]
}
}
return -1, Table{}
}
// Column performs a column lookup by name.
func (t Table) Column(name string) (int, Column) {
for i, c := range t.Columns {
if c.Name == name {
return i, c
}
}
return -1, Column{}
}
func (t Table) Refers(column string) (int, ForeignKey) {
for i, r := range t.References {
if r.FromColumn == column {
return i, r
}
}
return -1, ForeignKey{}
}